How to display the results + repeat to the number entered by user?
Hi, so I'm writing a program in which the user inputs the number of employees to store data. This is followed by questions such as "Employee Name" "Date", etc.
How do I make the program loop for the number of employees entered. For example. If the user enters 3 for the number of employees, the questions should appear 3 times,looping. Also, how do I make the answers all display at the end, depending on the original number of employees entered by the user?
Thanks :)
Here's what I have:
Code :
package Unit10;
import java.util.ArrayList;
import java.util.Scanner;
public class Unit10 {
private static ArrayList list;
public static void main(String[] args) {
int choice;
Scanner input = new Scanner(System.in);
do
{
choice = -1;
System.out.println("Enter the Number of Employees");
System.out.println("Employee Data:");
System.out.println("1. - Employee Name:");
System.out.println("2. - Employee Hire Date:");
System.out.println("3. - Employee Address:");
System.out.println("4. - Employee Number:");
System.out.println("5. - Display All Information");
System.out.println("6. - Exit");
choice = input.nextInt();
input.nextLine();
switch (choice)
{
case 1:
Name NameObject = new Name ();
System.out.println("Enter the name of the employee:");
String name = input.nextLine();
NameObject.name(name);
case 2:
Date DateObject = new Date ();
System.out.println("Enter the hire date of the employee:");
String date = input.nextLine();
DateObject.date(date);
case 3:
Address AddressObject = new Address ();
System.out.println("Enter the address of the employee:");
String address = input.nextLine();
AddressObject.address(address);
case 4:
Employee EmployeeObject = new Employee ();
System.out.println("Enter the Employee number:");
int Employee = input.nextInt();
EmployeeObject.employee(Employee);
case 5:
System.out.println("The employee data: ");
default:
continue;
}
}
while (choice != 6);
}
}
Re: How to display the results + repeat to the number entered by user?
I'm currently working on a program like this also :D
Quote:
System.out.println("How many weeks per paycheck?");
Scanner week = new Scanner (System.in);
int weekv = week.nextInt();
int count = 0;
while (count != weekv)
{
// check System.out.println ("count: " + count + "weekv: " + weekv);
System.out.println ("How many hours did you work Sunday of week " + count + " ?");
Scanner scan = new Scanner (System.in);
sunday = scan.nextDouble();
System.out.println ("How many hours did you work Monday of week " + count + " ?");
Scanner scan1 = new Scanner (System.in);
monday = scan1.nextDouble();
System.out.println ("How many hours did you work Tuesday of week " + count + " ?");
Scanner scan2 = new Scanner (System.in);
tuesday = scan2.nextDouble();
System.out.println ("How many hours did you work Wednesday of week " + count + " ?");
Scanner scan3 = new Scanner (System.in);
wednesday = scan3.nextDouble();
System.out.println ("How many hours did you work Thursday of week " + count + " ?");
Scanner scan4 = new Scanner (System.in);
thursday = scan4.nextDouble();
System.out.println ("How many hours did you work Friday of week " + count + " ?");
Scanner scan5 = new Scanner (System.in);
friday = scan5.nextDouble();
System.out.println ("How many hours did you work Saturday of week " + count + " ?");
Scanner scan6 = new Scanner (System.in);
saturday = scan6.nextDouble();
count ++;
Try something like this with a while loop