Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to display the results + repeat to the number entered by user?

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    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);
     
     
    	}
     
        }


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    6
    My Mood
    Amused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display the results + repeat to the number entered by user?

    I'm currently working on a program like this also
    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

Similar Threads

  1. Replies: 1
    Last Post: September 17th, 2011, 10:28 AM
  2. Wanting to repeat my program...
    By Shaybay92 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 8th, 2011, 08:29 AM
  3. Replies: 2
    Last Post: February 17th, 2011, 05:37 AM
  4. Replies: 1
    Last Post: December 4th, 2010, 04:26 PM
  5. Need this to end when a negative number is entered
    By ponyexpress in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2010, 09:02 AM