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: Help the code seems fine and all but it doesn't identify the names even it's right

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Help the code seems fine and all but it doesn't identify the names even it's right

    import java.util.Scanner;

    public class Employee {

    public static void main(String[] args) {

    Scanner a = new Scanner(System.in);

    //1
    String employeeNames[] = {"Caleb Enrix", "Xiolou", "Maria"};
    String employeeCodes[] = {"291215", "171117", "071119"};

    System.out.println("—————EMPLOYEE NAMES—————");

    for(int i = 0;i < 3;i++) {
    System.out.println(employeeNames[i]);
    }
    System.out.println();
    System.out.println();


    //2
    System.out.println("—————EMPLOYEE CODES—————");
    System.out.println("Caleb Enrix 's Code: " + employeeCodes[0]);
    System.out.println("Xiolou's Code: " + employeeCodes[1]);
    System.out.println("Maria's Code : " + employeeCodes[2]);
    System.out.println();
    System.out.println();


    //3
    System.out.println("—————EMPLOYEE TYPES——————");
    String employeeTypes[] = {"Regular Staff", "Team Leader", "Manager"};

    System.out.println("Caleb Enrix : " + employeeTypes[0]);
    System.out.println("Xiolou: " + employeeTypes[1]);
    System.out.println("Maria : " + employeeTypes[2]);
    System.out.println();
    System.out.println();

    //4
    System.out.println("—————EMPLOYEE DETAILS—————");

    System.out.print("Employee Name: ");
    String employeename = a.nextLine();

    System.out.print("Employee Code: ");
    String employeecode = a.nextLine();

    boolean doMatch = false;

    for(int c = 0;c < employeeNames.length;c++) {
    if(employeename.equals(employeeNames[c]) && employeecode.equals(employeeCodes[c])){
    doMatch = true;
    break;
    }
    }

    if(doMatch) System.out.println("Hello, " + employeename + " ");
    else System.out.println("Unknown Employee Account!");
    System.out.println();
    System.out.println();

    //6
    System.out.println("—————WORK HOURS PER DAY——————");
    int mon;
    int tue;
    int wed;
    int thu;
    int fri;
    int sum;

    System.out.print("Monday |Enter of Worked Hours: ");
    mon = a.nextInt();

    System.out.print("Tuesday |Enter of Worked Hours: ");
    tue = a.nextInt();

    System.out.print("Wednesday |Enter of Worked Hours: ");
    wed = a.nextInt();

    System.out.print("Thursday |Enter of Worked Hours: ");
    thu = a.nextInt();

    System.out.print("Friday |Enter of Worked Hours: ");
    fri = a.nextInt();

    sum = (mon + tue + wed + thu + fri);
    System.out.println("The total of 5 working days: " + sum);
    System.out.println();

    System.out.println("—————WORKING HOURS—————");
    String types[] = {"Undertime", "Regular", "Overtime"};

    System.out.println("Less Than 8 Hours: " + types[0]);
    System.out.println("Greater than or Equal To 8 Hours : " + types[1]);
    System.out.println("Greater than or Equal To 9 Hours : " + types[2]);
    System.out.println();
    System.out.println();

    int overtimepay;
    int workinghours;
    int subtrahend;
    int multiplier = 75;

    System.out.print("Enter Working Hours: ");
    workinghours = a.nextInt();

    System.out.print("Enter Subtrahend: ");
    subtrahend = a.nextInt();

    System.out.print("Enter Multiplier: ");
    multiplier = a.nextInt();

    overtimepay = (workinghours - subtrahend) * multiplier;
    System.out.println();
    System.out.println("Overtime Pay: " + overtimepay);
    System.out.println();
    System.out.println();

    //7
    System.out.println("—————WORKING HOURS FORMAT——————");
    String days[] = {"Day1", "Day2", "Day3", "Day4", "Day5"};

    System.out.println("Day 1 |No. of Worked Hours: " + mon );
    System.out.println("Day 2 |No. of Worked Hours: " + tue );
    System.out.println("Day 3 |No. of Worked Hours: " + wed );
    System.out.println("Day 4 |No. of Worked Hours: " + thu );
    System.out.println("Day 5 |No. of Worked Hours: " + fri );
    System.out.println();
    System.out.println();



    }
    }

  2. #2
    Member
    Join Date
    Apr 2022
    Posts
    36
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: Help the code seems fine and all but it doesn't identify the names even it's right

    import java.util.Scanner;
     
    public class Employee {
     
        public static void main(String[] args) {
     
            /*-----------------------------------------------------------*/
            Scanner scanner = new Scanner(System.in);
            String employeeNames[] = {"Caleb Enrix", "Xiolou", "Maria"},
                   employeeCodes[] = {"291215", "171117", "071119"},
                   employeeTypes[] = {"Regular Staff", "Team Leader", "Manager"},
                   days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"},
                   types[] = {"Undertime", "Regular", "Overtime"};
            int pay[] = new int[5], sum = 0;
            boolean doMatch = false;
            /*-----------------------------------------------------------*/
     
     
            //names
            System.out.println("—————EMPLOYEE NAMES—————");
            for(int i = 0; i < 3; i++) {
                System.out.println(employeeNames[i]);
            }
     
     
            //codes
            System.out.println("\n\n—————EMPLOYEE CODES—————");
            for(int i = 0; i < 3; i++) {
                System.out.println(employeeNames[i] + "'s Code: " + employeeCodes[i]);
            }
     
     
            //types
            System.out.println("\n\n—————EMPLOYEE TYPES——————");
            for(int i = 0; i < 3; i++) {
                System.out.println(employeeNames[i] + ": " + employeeTypes[i]);
            }
     
     
            //details
            System.out.println("\n\n—————EMPLOYEE DETAILS—————");
            System.out.print("Employee Name: ");
            String employeename = scanner.nextLine();
            System.out.print("Employee Code: ");
            String employeecode = scanner.nextLine();
            for(int i = 0; i < employeeNames.length; i++) {
                if(employeename.equals(employeeNames[i]) && employeecode.equals(employeeCodes[i])) {
                    doMatch = true;
                    break;
                }
            }
            System.out.println(doMatch ? "Hello, " + employeename : "Unknown Employee Account!");
     
     
            //hours per day
            System.out.println("\n\n—————WORK HOURS PER DAY——————");
            for(int i = 0; i < 5; i++) {
                System.out.println(days[i] + "|Enter of Worked Hours: ");
                pay[i] = scanner.nextInt();
                sum += pay[i];
            }
            System.out.println("The total of 5 working days: " + sum);
     
     
            //hours
            System.out.println("\n\n—————WORKING HOURS—————" + "\nLess Than 8 Hours: " + types[0] +
            "\nEqual To 8 Hours : " + types[1] + "\nGreater than or Equal To 8 Hours : " + types[2] + "\n");
     
            System.out.print("Enter Working Hours: ");
            int workinghours = scanner.nextInt();
            System.out.print("Enter Subtrahend: ");
            int subtrahend = scanner.nextInt();
            System.out.print("Enter Multiplier: ");
            int multiplier = scanner.nextInt();
            System.out.println("\nOvertime Pay: " + (workinghours - subtrahend) * multiplier + "\n");
     
     
            //format
            System.out.println("—————WORKING HOURS FORMAT——————");
            for(int i = 0; i < 5; i++) {
                System.out.println("Day " + (i+1) + " |No. of Worked Hours: " + pay[i]);
            }
            System.out.println("\n");
        }
    }

Similar Threads

  1. Program works fine but with friend it doesn't work
    By Rizza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 1st, 2011, 01:20 PM
  2. Code compiles fine but doesn't run Properly
    By nadirkhan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 12:46 PM
  3. Replies: 3
    Last Post: October 4th, 2011, 09:03 PM
  4. The program working fine but the "NO" button doesn't work
    By ahcenpg in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 1st, 2011, 07:32 PM
  5. HELP! Gui is running fine, don't know exactly how to code.
    By cc11rocks in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 12th, 2011, 02:12 PM