I am a little stuck with my coursework in JAVA. Could you help me?
let's say you want to write a program that repetitively asks the names of people and their age and stops when the string FINISH is entered, then prints out the name and the age of the youngest person of all the people entered. And if 2 or more people have the same age, jsut write the name of the last person of that age entered. How can you ask JAVA to select that person, without the use of arrays, but only while loops, if statements and for loops.
Here is the example, starting from the method.
String name = "";
int age = 0;
while (!name.equals ("finish))
{
name = JOptionPane.showInputDialog ("Give name: ");
String ageText = JOptionPane.showInputDialog ("Give age: ");
int age = Integer.parseInt (ageText);
}
JOptionPane.showMessageDialog ("the yougest person is " + age + ". It's " + name + ".");
An example run of the program:
Give name: Lucy Give age: 52
Give name: Paul Give age: 29
Give name:John Give age: 28
Give name: Mary Give age: 31
Give name: finish
The youngest person is 28. It's John.
Please note how string "finish" is not printed out at the end.
I have been thinking trying to find a way of doing that for 8 hours. I beg you help please.
Kind regards,