I think i am doing it right but the program skips line 30 where it asks user to insert first name. i dont know why this happens and would like help.
code is unfinish btw i just needed to fix this before i want to move forward
import java.util.Scanner; public class EmployeeTest { public static void main(String[] args){ String yourName; String yourLastName; double yourSalary; Scanner input = new Scanner(System.in); Employee applicant1 = new Employee("Trung","Lam",2729.00); Employee applicant2 = new Employee("Vanessajoie","Castillo",4055.00); System.out.printf("Initial employee1 is %s %s and makes $%.2f monthly\n", applicant1.getName(), applicant1.getSurName(), applicant1.getSalary()); System.out.printf("Initial employee2 is %s %s and makes $%.2f monthly\n", applicant2.getName(), applicant2.getSurName(), applicant2.getSalary()); //set up new employee1 System.out.print("New employee1 first name: "); yourName = input.nextLine(); System.out.print("New employee1 last name: "); yourLastName = input.nextLine(); System.out.print("New employee1 salary: $"); yourSalary = input.nextDouble(); applicant1.setName(yourName); applicant1.setSurName(yourLastName); applicant1.setSalary(yourSalary); //set up new employee2 System.out.print("New employee2 first name: "); yourName = input.nextLine(); System.out.print("New employee2 last name: "); yourLastName = input.nextLine(); System.out.print("New employee2 salary: $"); yourSalary = input.nextDouble(); applicant2.setName(yourName); applicant2.setSurName(yourLastName); applicant2.setSalary(yourSalary); //list current employees System.out.printf("Current employee1 is %s %s and makes $%.2f monthly\n", applicant1.getName(), applicant1.getSurName(), applicant1.getSalary()); System.out.printf("Current employee2 is %s %s and makes $%.2f monthly\n", applicant2.getName(), applicant2.getSurName(), applicant2.getSalary()); } }
public class Employee { private String name; private String surName; private double salary; public Employee(String eName, String eSurName, double eSalary){ name = eName; surName = eSurName; salary = eSalary; } //setting values public void setName(String eName){ name = eName; } public void setSurName(String eSurName){ surName = eSurName; } public void setSalary(double eSalary){ if (eSalary >= 0) salary = eSalary; else salary = 0.0; } //get values public String getName(){ return name; } public String getSurName(){ return surName; } public double getSalary(){ return salary; } }