dimanche 23 mars 2014

how do i add or delete something from an array?


Vote count:

0




I am writing this program that will take in the names, ages and salaries for 5 different people from the user and will put them in an array.


I then want to write a method that will ask the user for another name, age and salary and add that into the array. Also a method that will as for the name of someone who's already in the array and will delete the information of the person with that age from the array.


The first method will increase the array size by 1 and the second will decrease the array size by 1. so far this is what I have:



ArrayList<details> details = new ArrayList<details>();

for(int x = 0; x < 4; x++) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the first name: ");
String firstName = scan.nextLine();

System.out.println("Enter the last name: ");
String lastName = scan.nextLine();

System.out.println("Enter the age: ");
int age = scan.nextInt();

System.out.println("Enter the salary: ");
double salary = scan.nextDouble();

details.add (new details(firstName, lastName, age, salary));

}


I don't know how to go about doing this. I need some help! thanks!



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire