Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EmployeeData
- {
- public static void main(String[] args)
- {
- Scanner scanner=new Scanner(System.in);
- String custInp;
- String fName = "";
- String lName = "";
- int empID;
- double wage;
- //initation loop
- int newInput=1;
- while(newInput==1)
- {
- //input in single string
- System.out.println("Please enter First name, last name, emp ID
- and wage. (include space inbetween each)");
- custInp = scanner.nextLine();
- //cut string into variables
- fName = splitNext(custInp, ' ');
- custInp = custInp.substring(fName.length() + 1,
- custInp.length());
- lName = splitNext(custInp, ' ');
- custInp = custInp.substring(lName.length() + 1,
- custInp.length());
- String temp = splitNext(custInp, ' ');
- empID = Integer.parseInt(temp);
- custInp = custInp.substring(custInp.indexOf(' ') + 1,
- custInp.length());
- wage = Double.parseDouble(custInp);
- //set data
- Employee emp = new Employee(fName, lName, empID, wage);
- //get data
- System.out.println(fName + " " + lName + " " + empID + " " +
- wage);
- System.out.println("Employee Name: " + emp.getFirstName() + "
- " + emp.getLastName());
- System.out.println("Employee ID: " + emp.getEmpID());
- System.out.println("Employee Wage: " + emp.getWage());
- System.out.println("");
- //decide to continue or not
- System.out.println("Do you want to add more? 1=Yes or 2=no");
- newInput = scanner.nextInt();
- //THIS IS WHERE the issue happens
- }
- }
- public static String splitNext(String s, char delim)
- {
- //location of first space character in s
- int delimIndex = s.indexOf(delim);
- //require that next is at least 1 char long
- if(delimIndex > 0)
- {
- //set next to all chars in s preceding first space found
- String next = s.substring(0, delimIndex);
- //truncate beginning of s so that s.find(' ') can reach second
- s = s.substring(delimIndex + 1, s.length());
- return next;
- }
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement