Question
public class Person { // person name protected String name; // defualt constructor public Person() { name =No Name Yet; } // 1st argument constructors
public class Person
{
// person name
protected String name;
// defualt constructor
public Person()
{
name ="No Name Yet";
}
// 1st argument constructors
public Person(String initialName)
{
name = initialName;
}
//Sets new name
public void setName (String newName)
{
name = newName;
}
//Returns person name
public String getName()
{
return name;
}
// inputs name to console
public void writeOutput()
{
System.out.println("Name : " + name);
}
//returns true in names are the same if not false
public boolean hasSameName(Person otherPerson)
{
return
this.name.equalsIgnoreCase(otherPerson.name);
}
}
// employee
public class Employee extends Person
{
//data members
private double annualSalary;
private int hiredYear;
private String ID;
// constructor with parameters
public Employee(String initialName, double initialSalary, int joinedYear, String id)
{
super(initialName);
annualSalary = initialSalary;
hiredYear = joinedYear;
ID = id;
}
//sets annual salary
public void setAnnualSalary(double newSalary)
{
annualSalary = newSalary;
}
//sets hired year
public void sethiredYear(int year)
{
hiredYear = year;
}
//sets employee id
public void setID(String newID)
{
ID =newID;
}
//returns annual salary
public double getAnnualSalary()
{
return annualSalary;
}
//returns hired year
public int getHiredYear()
{
return hiredYear;
}
// returns employee id
public String getID()
{
return ID;
}
public boolean equals(Employee otherEmployee)
{
if (name.equals(otherEmployee.name))
if (annualSalary == otherEmployee.annualSalary)
if(hiredYear == otherEmployee.hiredYear)
if(ID == otherEmployee.ID)
return true;
return false;
}
//prints the employee name salary hired yr and id
public void display()
{
System.out.println("Employee Name: " + name);
System.out.println("Employee Annual Salary: " + annualSalary);
System.out.println("Employee Hired Year: " + hiredYear);
System.out.println("Employee ID: " + ID);
System.out.println();
}
}
--------------------------------------------------------------------------------------------------------------------------------
public class TestEmployee
{
public static void main (String[] args)
{
// employee objects
Employee e1 = new Employee("John", 50000, 2004, "A101");
e1.display();
}
}
______________________________________________________________________
instead of inputing the data i want to beable to have the user input it all would like someone to help me with the coding to allow the
user to do so
Step by Step Solution
3.50 Rating (163 Votes )
There are 3 Steps involved in it
Step: 1
One of the way to take input from user in JAVA from keyboard is to use import javautilScanner Modifi...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started