Determine the number of tribble for any hour

Assignment Help JAVA Programming
Reference no: EM132075891

You need help figuring out how to match my inputed hour value with an array of set values. I can make everything work from there. Here is the problem You are looking at, and below that is code thus far. Any pointers or suggestions would be greatly appreciated.

Problem

You think rabbits breed quickly? Tribbles are worse by far! Dr. McCoy of the Enterprise is trying to determine how many tribbles are there going to be every hour.

Now, he suspects that they are born pregnant with one baby-tribble (which saves a lot of time when you think about it) that is born within the first hour. His empirical research has identified these amount of tribbles alive at each hour:

2          2          2          6          10        18        34        62        114      210

Using this sequence, write a JAVA program that uses recursion to determine the number of tribble for any hour. It should prompt the user for the hour and then display the total tribbles.

For example, the user enters 1 and the program displays 2; the user enters 10 and the program displays 210; and so on.

Code

import java.util.Scanner;

public class DBtest {

//private static int[] anArray;

public static void main(String[] args){

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter the number of hours: ");

int hours = keyboard.nextInt();

System.out.println(num(hours));

}

public static int num(int hours){

int[] anArray = new int[hours];

//anArray[1] = 2;

//anArray[2] = 2;

//anArray[3] = 2;

if (hours <= 3)

return 2;

else

return num(hours - 1) + num(hours - 2);

}

}

Reference no: EM132075891

Questions Cloud

What is the price per share of equity under plan : Destin Corp. is comparing two different capital structures. Plan I would result in 10,000 shares of stock and $90,000 in debt.
What is the present value of a annuity payment : What's the present value of a $900 annuity payment over five years if interest rates are 8 percent? (Do not round intermediate calculations).
What are the tax consequences, : She is not currently able to make payments on the loan. What are the tax consequences, if any, to Andrea in this situation
How much can miley except to receive for sale of these bonds : The discount rate for such securities is 10%. How much can Miley except to receive for the sale of these bonds? This is from financial accounting
Determine the number of tribble for any hour : Write a JAVA program that uses recursion to determine the number of tribble for any hour. It should prompt the user for the hour and then display the total.
What would the future value be : What's the future value of a 5%, 5-year ordinary annuity that pays $800 each year? If this was an annuity due, what would its future value be?
What is the effect on the income statement : Hoover Company mined 400,000 tons of coal. What is the effect on the income statement and the statement of cash flows for 2017
What is a current financial trend : What's a current financial trend that is going on at the moment or one that was recently trending? Must be recent.
How many critical paths should there be in your pert chart : List the nodes [in the order of traversal] in the critical path[s] that you have identified in question 6 [above] and documented in your PERT chart.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Containing integers sorted in ascending order

You are given a list, L , and a another list, P, containing integers sorted in ascending order.

  Write an application that reads determines the surface area

Write a program that uses the top five countries' National Wealth to calculate the average of those five countries.

  Create constructor methods-methods to manipulate the data

Add a private static double field called MINIMUM_PAYMENT_PERCENTAGEand make it equal to .02. This will help calculate the minimum payment due.

  Consider an algorithm for computing cubes using addition

You have a computer where multiplication is an enormously expensive operation compared to addition. Consider an algorithm for computing cubes using only addition (FYI: the first 5 cubes are 13 = 1, 23 = 8, 33 = 27, 43 = 64 and 53 = 125). This comp..

  Redesign the grading program as an object-oriented design

Redesign the grading program as an object-oriented design. We will start with a simple Student class. The student will have a name, an id (as a String) and a set of grades (as doubles).

  Elements in a two-dimensional array

Write a value-returning method that returns the number of columns with n elements in a two-dimensional array of chars, where n is a parameter of the method. Include code to test your method.

  Design a class named mydate

Design a class named MyDate. The class contains: The data fields year, month, and day that represesents a date. month is 0-based, i.e., 0 is January. A no-arg constructor that creates a MyDate object for the current date

  Write a program to print all of the permutations

Write a program to print all of the permutations of the values 1, 2, 3, ..., n - Your program takes one argument from the command line, which as an integer n  that is the number of elements.

  Explain how a typical ide is used explain the purpose of

explain how a typical ide is used. explain the purpose of the various panes of the ide. justify the importance of this.

  Design a class named square which implementscolorable

Design an interface namedColorable with a public void method namedhowToColor(). Every class of acolorable object must implement theColorable interface.

  Implement a class person with two fields name and age

Implement a class Person with two fields name and age, and a class Car with three fields

  Solving programming problems

Write a computer program that will figure out the total of an order when given the amount of the order ($1000) and a sales tax rate of eight percent.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd