Bird Watcher

/* This program is used for Garden Bird watchers to enter their data until the user runs out of data Author---------Tsotne Gvadzabia Date-----------07/11/16 */ import java.util.Scanner; class birds { public static void main(String[]p) { //Methods are shown below Welcomemsg(); loop(); System.exit(0); } public static void Welcomemsg() //This method dislpays a welcome messege and Instructions for the user { System.out.println("Welcome noble garden watcher!"); System.out.println("Answer the questions corretly"); System.out.println("Remember when you are finished and want your reuslts just type in: END"); } public static void loop() //This is the main method for the program where the while loop takes place { Scanner scanner = new Scanner(System.in); final String quit = "END"; String bird = " "; //Initialises variable int number = 0; int common; String realb = " "; common = number; System.out.println("Which bird have you seen?"); bird = scanner.next(); while(!(bird.equals(quit))) //If user enters "END" into the program, the loop will stop" { System.out.println("How many were in your garden at once?"); number = scanner.nextInt(); if(number>common) //Keeps track of the most birds seen and bird type { common = number; realb = bird; } System.out.println("Which bird have you seen?"); bird = scanner.next(); } //While loop END System.out.println("You saw "+common+" "+realb+"s"); System.out.println("It was the most common bird seen at one time in your garden."); } } // Program END
A Program for Bird Watchers.

The user inputs the species of bird they have spotted and then how many.
The user keeps doing this until they have finished bird watching in which case they enter "END" into the program.

The Program then displays which was the most spotted bird, along with how many.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.