Extend the summer camp program from a previous exercise so that the program also prints the oldest camper's name and age

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Extend the summer camp program from a previous exercise so that the program also prints the oldest camper's name and age

Post by answerhappygod »

Extend the summer camp program from a previous exercise so thatthe program also prints the oldest camper's name and age.
The following is a sample run (bold fonts represent userinputs):
Enter # of campers:3Enter the 3 campers' names one by one:Amy Bob CharlieEnter Amy's age:18Enter Bob's age:19Enter Charlie's age:17The campers:Amy (age 18)Bob (age 19)Charlie (age 17)The oldest camper is Bob (19 years old).
Extend The Summer Camp Program From A Previous Exercise So That The Program Also Prints The Oldest Camper S Name And Age 1
Extend The Summer Camp Program From A Previous Exercise So That The Program Also Prints The Oldest Camper S Name And Age 1 (43.83 KiB) Viewed 43 times
Main.Java New 1- import java.util.Scanner; 2 3 public class Main 4 - { 5 6 - 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter # of campers:"); int numCampers = input.nextInt(); } String[] names = new String[numCampers]; System.out.println("Enter the " + numCampers + campers' names one by one: "); //TODO 1: Use a loop to get the campers' names one by one int[] ages = new int[numCampers]; //TODO 2: Use a loop to get each camper's age. When prompting, Please mention each camper's name, such as "Enter Amy's age:" System.out.println("The campers:"); //TODO 3: Use a loop to print each camper's name and age //TODO4: Use a loop to find which camper is oldest //Display the oldest camper's name and age. PLEASE DO NOT CHANGE the code beloew. System.out.printf("The oldest camper is %s (%d years old).\n", names[indexOfMax], ages [indexOfMax]);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply