Hello, I need some help with a question. I not a very good programmer myself so plese go easy on me. I'm a year 1 student in diploma in Information Technology.
The question goes like this
Write an application that will read in people names and their ages. Store them in two arrays. Then do a search of names to find the corresponding age. Follow these steps to write the programme:
a) Create a class BasicsApp4.java with a main() method
b) Add a readAge() method
c) Add a readAges() method
d) Add a readName() method
e) Add a readNames() method that will call readName method to store 5 names into an array called nameArray
f) In the main method, do the followings:
-Declare ageArray and nameArray with size of 5
-Call/Invoke readNames() and readAges() methods to read in 5 names and ages
-Ask the user to enter a name and search for the age
-Display name and age if found, else display name not found
-Ask user to enter an age and display all the names with the same age
Here is what i done so far, I'm not very sure if where i had gone wrong and i did not know how to continue.
public class BasicApp4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[]ageArray = new int[5];
String[]nameArray = new String[5];
readName(nameArray);
}
private static void readName(String[] nameArray) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
name = sc.nextLine();
}
private static int readAge(int[] ageArray) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int age;
do {
System.out.print("Enter age: ");
age = sc.nextInt();
}
while ((age<0)||(age>100));
return age;
}
private static void readAges(int[] ageArray) {
// TODO Auto-generated method stub
for (int i=0; i<ageArray.length; i++){
}
ageArray[0]=readAge(null);
}
}