Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EmployeeData
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner scanner=new Scanner(System.in);
  9.  
  10. String custInp;
  11. String fName = "";
  12. String lName = "";
  13. int empID;
  14. double wage;
  15. //initation loop
  16. int newInput=1;
  17. while(newInput==1)
  18. {
  19. //input in single string
  20. System.out.println("Please enter First name, last name, emp ID
  21. and wage. (include space inbetween each)");
  22. custInp = scanner.nextLine();
  23. //cut string into variables
  24. fName = splitNext(custInp, ' ');
  25. custInp = custInp.substring(fName.length() + 1,
  26. custInp.length());
  27. lName = splitNext(custInp, ' ');
  28. custInp = custInp.substring(lName.length() + 1,
  29. custInp.length());
  30. String temp = splitNext(custInp, ' ');
  31. empID = Integer.parseInt(temp);
  32. custInp = custInp.substring(custInp.indexOf(' ') + 1,
  33. custInp.length());
  34. wage = Double.parseDouble(custInp);
  35. //set data
  36. Employee emp = new Employee(fName, lName, empID, wage);
  37. //get data
  38. System.out.println(fName + " " + lName + " " + empID + " " +
  39. wage);
  40. System.out.println("Employee Name: " + emp.getFirstName() + "
  41. " + emp.getLastName());
  42. System.out.println("Employee ID: " + emp.getEmpID());
  43. System.out.println("Employee Wage: " + emp.getWage());
  44. System.out.println("");
  45. //decide to continue or not
  46. System.out.println("Do you want to add more? 1=Yes or 2=no");
  47. newInput = scanner.nextInt();
  48. //THIS IS WHERE the issue happens
  49. }
  50. }
  51.  
  52.  
  53. public static String splitNext(String s, char delim)
  54. {
  55. //location of first space character in s
  56. int delimIndex = s.indexOf(delim);
  57.  
  58. //require that next is at least 1 char long
  59. if(delimIndex > 0)
  60. {
  61. //set next to all chars in s preceding first space found
  62. String next = s.substring(0, delimIndex);
  63.  
  64. //truncate beginning of s so that s.find(' ') can reach second
  65. s = s.substring(delimIndex + 1, s.length());
  66.  
  67. return next;
  68. }
  69.  
  70. return "";
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement