Question

In: Computer Science

in java pls Write a program for spiritual lumberjacks who want to show their appreciation for...

in java pls

Write a program for spiritual lumberjacks who want to show their appreciation for each tree they 'kill' by celebrating its years of life.

  1. Ask the lumberjack how many trees he wants to cut. Verify you got the number correctly by printing it to output.

  2. Write a loop that iterates over all the trees the lumberjack wants to cut down. Print the tree number to the screen to make sure your loop is working correctly.

  3. Query the lumber jack for how many rings are in this tree and print this number to make sure you got the correct number of rings.

  4. Write an inner loop that iterates over the years of the tree. Print each year to make sure you are iterating correctly and hitting each year that it lived.

  5. Change the necessary print statements and to match the correct formatting from the output examples.

input: 2 3 4

expected output:

How many trees do you want to cut down?

2

0

How many rings are in tree 0?

3

We humbly respect tree number 0 and celebrate its 1 birthday.

We humbly respect tree number 0 and celebrate its 2 birthday.

We humbly respect tree number 0 and celebrate its 3 birthday. 1

How many rings are in tree 1?

4

We humbly respect tree number 1 and celebrate its 1 birthday.

We humbly respect tree number 1 and celebrate its 2 birthday.

We humbly respect tree number 1 and celebrate its 3 birthday.

We humbly respect tree number 1 and celebrate its 4 birthday.

Solutions

Expert Solution

Here is the code for the following pproblem with proper commenting so that you an easily understand the flow of the code. however if you feel any problem please feel free to ask.

-----------------------------------------------------------------------------------------------------------

Code:

import java.util.Scanner;

public class Main
{
//execution of program start from here
   public static void main(String[] args) {
      
       //creating Scanner class object to take user input
       Scanner scnr = new Scanner(System.in);
      
      
       //ask Number of trees user wants tot cut down
       System.out.println("How many trees you want to cut down?");
       int trees = scnr.nextInt() ;
      
      
       //loop throght all trees
       for(int i=0; i<trees; i++)
       {
       System.out.println(i);
       System.out.println("How many rings are in tree " + i + "?");
       int rings = scnr.nextInt();
      
       //celebrate all birthday of tree
       for(int j=0; j<rings; j++)
       {
       System.out.println("We humbly respect tree number " + i + " and celebrate its " + (j+1) + " birthday.");
       }
       }
   }
}

---------------------------------------------------------------------------------------------------------------------

Output:


Related Solutions

in java pls Write a Car Dealership management program. This program will allow the employees of...
in java pls Write a Car Dealership management program. This program will allow the employees of the Dealership to add cars to their database and sell them. You will be implementing two classes: Car and CarDealership. Car will store data associated with the cars and CarDealership will be the management program. Note: 5 points of your grade is based on Coding Style. You will need to update the Starter Code to follow the standards described here. Use the "Run" button...
I want to write this program in java. Write a simple airline ticket reservation program in...
I want to write this program in java. Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit...
What we want the program to do: We need to write a program, in Java, that...
What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then...
Write a Java program that implements a queue in a hospital. I want your program to...
Write a Java program that implements a queue in a hospital. I want your program to ask the user to enter the number of patients then enter the patient number starting from 110 till the end of the queue then print number of patients waiting in the queue. Suppose you have a queue D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty Stack S. Give a code fragment that uses S, to store...
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do...
Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do we appreciate!" (hint use a for loop). Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages. Write a java program that will ask the user to enter a number and print out to the screen until the number -3 is entered. Write a JAVA program that calls a method that finds...
Write a program in Java for: Starting a brand new term, you decide you want to...
Write a program in Java for: Starting a brand new term, you decide you want to make a good impression on your instructor. To do this, you want to create an application that helps process midterm exam scores, letting the instructor know which student(s) earned the lowest score so the instructor can suggest some extra help resources. To begin, initialize two parallel arrays (hardcoding the values): Names: Joey, Lisa, Karen, Mark, Christopher, etc. Scores: 78.5, 97.0, 42.5, 86.5, 42.5, etc....
I want to write java program to implement the indexing concept so as an example we...
I want to write java program to implement the indexing concept so as an example we have file named Students this file contains information like this 112233445 ahmed 222442211 saeed 112453345 john this program should search for the student name by its number so as an output example: enter the student number 112233445 name found : ahmed also i want to print the index number of where does the student name exists
Lab Assignment Write a Java program that implements a queue in a hospital. I want your...
Lab Assignment Write a Java program that implements a queue in a hospital. I want your program to ask the user to enter the number of patients then enter the patient number starting from 110 till the end of the queue then print number of patients waiting in the queue. Suppose you have a queue D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty Stack S. Give a code fragment that uses S,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT