Code the following ADTs (classes), making sure to follow the instructions in the
ID: 3800322 • Letter: C
Question
Code the following ADTs (classes), making sure to follow the instructions in the bulleted lists:
1.Write a class name Employee
A. that has the following fields:
name
idNumber
department
position (job title)
b. and the following methods:
A no-argument constructor
A constructor that sets the data to passed values
Getters and setters for each piece of data
A toString( ) method to display the object data
c. Include Javadoc comments for the class and every method
d. Create a separate Java application to “unit test” this class (zyBook section 6.6) by creating 3 objects.
e. Generate the Javadoc/API document for this ADT
2.Write a class name Car
a. that has the following fields:
yearModel (integer holding the car’s year model)
make (String holding the make of the car)
speed (integer holding the car’s current speed)
b.and the following methods:
A no-argument constructor
A constructor that sets the data to passed values
Getters and setters for each piece of data
accelerate: adds 5 to the speed field each time it is called
brake: subtracts 5 from the speed field each time it is called
A toString( ) method to display the object data
c.Include Javadoc comments for the class and every method
d.Create a separate Java application to “unit test” this class (zyBook section 6.6) by creating 2 objects.
e.Generate the Javadoc/API document for this ADT
Explanation / Answer
Hi Friend, I have answered Q1.
Please repost other question in separate post.
Please let me know in case of any issue.
############## Employee.java #############
public class Employee {
// instance variables
private String name;
private int idNumber;
private String department;
private String position;
// constructor
public Employee() {
this.name = "";
this.idNumber = 0;
this.department = "";
this.position = "";
}
/**
* @param name
* @param idNumber
* @param department
* @param position
*/
public Employee(String name, int idNumber, String department, String position) {
this.name = name;
this.idNumber = idNumber;
this.department = department;
this.position = position;
}
//getters and setters
/**
* @return name
*/
public String getName() {
return name;
}
/**
* @return idNumber
*/
public int getIdNumber() {
return idNumber;
}
/**
* @return department
*/
public String getDepartment() {
return department;
}
/**
* @return position
*/
public String getPosition() {
return position;
}
/**
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* @param idNumber
*/
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
/**
* @param department
*/
public void setDepartment(String department) {
this.department = department;
}
/**
* @param position
*/
public void setPosition(String position) {
this.position = position;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Name: "+name+", ID: "+idNumber+", Department: "+department+", and Job Title: "+position;
}
}
########### test ########
public class EmployeeTest {
public static void main(String[] args) {
// creating two object of Employee
Employee emp1 = new Employee();
emp1.setName("Pravesh Kumar");
emp1.setIdNumber(12);
emp1.setDepartment("CSE");
emp1.setPosition("SSE");
Employee emp2 = new Employee("Alex", 13, "EEE", "Maneger");
System.out.println(emp1);
System.out.println(emp2);
}
}
/*
Sample run:
Name: Pravesh Kumar, ID: 12, Department: CSE, and Job Title: SSE
Name: Alex, ID: 13, Department: EEE, and Job Title: Maneger
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.