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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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