for (int i = 0; i < 2; i++) {
System.out.println("Please enter your name: ");
name = scan.nextLine();
peoples.setName(name);
System.out.println("Please enter your IC: ");
icNo = scan.nextLine();
peoples.setIcNo(icNo);
System.out.println("Please enter your marital status: ");
status = scan.nextLine();
taxes.setStatus(status);
System.out.println("Please enter your taxable income: ");
taxableIncome = scan.nextDouble();
taxes.setTaxableIncome(taxableIncome);
peoples.addPeople(name, icNo, taxableIncome, taxAmount);
}
System.out.printf("NAME " + "IC NO " + "TAXABLE INCOME " + "TAX AMOUNT");
System.out.println("");
System.out.println(peoples.toString());
This is a section of the code for the problem. I'm supposed to ask a person's name, ID, marital status and taxable income. I have three classes, one for the person's details, one to calculate the tax imposed and the main class here.
The information obtained from the people was supposed to be placed into an array but they're all in different data types. Well, name and ID are string types while both taxable income and tax amount are in double data types.
I tried to make an array in the people class but it didn't work out. I tried casting the array into string but it didn't work either. I'm supposed to obtain data from two or more people and print them out below a header. I just can't think of how it's supposed to store the data from user inputs and print them outside of the for loop. The user input should be stored as an array but I'm open to any other solutions.