Question

Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and day. • Three getter methods for the data fields, year, month, and day, respectively. • A method named setDate(long elapsedTime) that sets a enw date for the object using the elapsed time. • Write a test program that creates two MyDate objects (using new MyDate() and new MyDate(34355555133101L) and displays their year, month, and day. (Hint: The first two constructors will extract the year, month, and day from the elapsed time. For example, if the elapsed time is 561555550000 milliseconds, the year is 1987, the month is 9, and day is 18. You may use the GregorianCalandear class. Java API has the GregorianCalendar class in the java.tuil package, which you can use to obtain the year, month, and day of date. The no-arg constructor constructs an instance for the current date, and the mentod get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), and get(GregorianCalendar.DAY_OF_MONTH) return the year, month, and day.)

Part II: (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate class defined in Part I to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString metod in each class to display the class name and the person’s name. Part III: Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part - 1 : :

import java.util.*;

class Date {
public static void main(String[] args) {
MyDate d1 = new MyDate();
       d1.display();
       MyDate d2 = new MyDate(34355555133101L);
       d2.display();
       MyDate d3 = new MyDate(561555550000L);
       d3.display();
}
  
  
}

class MyDate{
   Calendar c = Calendar.getInstance();
   private int year, month, day;
  
   public MyDate(){
       this(System.currentTimeMillis());
   }
  
   public MyDate(long millis){
       setDate(millis);
   }
  
   public MyDate(int year, int month, int day){
       this.year = year;
       this.month = month;
       this.day = day;
   }
  
   public int getYear(){
       return year;
   }
  
   public int getMonth(){
       return month;
   }
  
   public int getDay(){
       return day;
   }
  
   public void setDate(long millis){
       c.setTimeInMillis(millis);
       year = c.get(Calendar.YEAR);
       month = c.get(Calendar.MONTH);
       day = c.get(Calendar.DAY_OF_MONTH);
   }
  
   public void display(){
   System.out.printf("%d/%d/%d (mm/dd/yyyy)\n", month, day, year);
}
}

Part - 2 ::

Person.java

public class Person {

protected String name;
protected String address;
protected String phoneNumber;
protected String email;

public Person(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
return "Name: " + getName() + " Class: " + this.getClass().getName();
}
}

Student.java

public class Student extends Person {

public static final String FRESHMAN = "Freshman";
public static final String SOPHOMORE = "Sophomore";
public static final String JUNIOR = "Junior";
public static final String SENIOR = "Senior";

protected String status;

public Student(String name) {
super(name);
}

public Student(String name, String status) {
super(name);
this.status = status;
}

@Override
public String toString() {
return "Name: " + getName() + " Class: " + this.getClass().getName();
}
}

Employee.java



public class Employee extends Person {

protected double salary;
protected String office;
protected MyDate dateHired;

public Employee(String name) {
this(name, 0, "none", new MyDate());
}

public Employee(String name, double salary, String office, MyDate dateHired) {
super(name);
this.salary = salary;
this.office = office;
this.dateHired = dateHired;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public String getOffice() {
return office;
}

public void setOffice(String office) {
this.office = office;
}

public MyDate getDateHired() {
return dateHired;
}

public void setDateHired(MyDate dateHired) {
this.dateHired = dateHired;
}

@Override
public String toString() {
return "Name: " + getName() + " Class: " + this.getClass().getName();
}
}

Faculty.java

public class Faculty extends Employee {

public static String LECTURER = "Lecturer";
public static String ASSISTANT_PROFESSOR = "Assistant Professor";
public static String ASSOCIATE_PROFESSOR = "Associate Professor";
public static String PROFESSOR = "Professor";

protected String officeHours;
protected String rank;

public Faculty(String name) {
this(name, "9-5PM", "Employee");
}

public Faculty(String name, String officeHours, String rank) {
super(name);
this.officeHours = officeHours;
this.rank = rank;
}

public String getOfficeHours() {
return officeHours;
}

public void setOfficeHours(String officeHours) {
this.officeHours = officeHours;
}

public String getRank() {
return rank;
}

public void setRank(String rank) {
this.rank = rank;
}

@Override
public String toString() {
return "Name: " + getName() + " Class: " + this.getClass().getName();
}
}

Staff.java

public class Staff extends Employee {

protected String title;

public Staff(String name) {
this(name, "none");

}

public Staff(String name, String title) {
super(name);
this.title = title;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

@Override
public String toString() {
return "Name: " + getName() + " Class: " + this.getClass().getName();
}
}

Main.java

public class Main {

public static void main(String[] args) {

Person person = new Person("Test1");
Student student = new Student("StuTest1");
Employee employee = new Employee("TestEmp1");
Faculty faculty = new Faculty("TestFac");
Staff staff = new Staff("TestStaff");

System.out.println(person.toString());
System.out.println(student.toString());
System.out.println(employee.toString());
System.out.println(faculty.toString());
System.out.println(staff.toString());

}


}

Output ::

Please do comment if you have any doubts ...

Add a comment
Know the answer?
Add Answer to:
Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use "Eclipse IDE for Java EE Developers" Design a class named MyDate. The class contains: The...

    Use "Eclipse IDE for Java EE Developers" Design a class named MyDate. The class contains: The Date fields year, month, and day that represent a date. month is 0-based, i.e., 0 is for January. A no argument constructor that creates a MyDate object for the current date. A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. A constructor that constructs a MyDate object with the specified year, month, and day....

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • In Python - Design a class named Time. The class contains: -Data fields hour, minute, and...

    In Python - Design a class named Time. The class contains: -Data fields hour, minute, and second that represent a time. -A no-arg constructor that creates a Time object for the current time.(the values of the data fields will respresent the current time.) -A constructor that constructs a Time object with a specified hour, minute, and second, respectively. -A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds. (The values of...

  • Java Programming Design a class named Person and its two subclasses named Student and Employee. A...

    Java Programming Design a class named Person and its two subclasses named Student and Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, date hired. Define a class named MyDate that contains the fields year, month, and day. Override the toString method in each class to display the class name and the person's name....

  • Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee

    In Java(The Person, Student, Employee, Faculty, and Staff classes)Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and date hired. Define a class namedMyDate that contains the fields year, month, and day. A faculty member has office hours and a rank....

  • Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define...

    Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...

  • Design a class named StopWatch. The class contains: - Private data fields startTime and endTime with...

    Design a class named StopWatch. The class contains: - Private data fields startTime and endTime with getter methods. - A no-arg constructor that initializes startTime with the current time. - A method named start() that resets the startTime to the cur- rent time. - A method named stop() that sets the endTime to the current time. A method named getElapsedTime() that returns the elapsed time for the stopwatch in milliseconds. - The System.currentTimeMillis() method returns the current number of milliseconds....

  • Please provide the code for the last part(client side program). yes i have all the class...

    Please provide the code for the last part(client side program). yes i have all the class implementations. ``` person.h #ifndef PERSON_H #define PERSON_H #include <string> using namespace std; class person { public: person(); string getname() const; string getadd() const; string getemail() const; string getphno() const; string toString() const; private: string name; string add; string email; string phno; }; ```person.cpp #include "person.h" person::person() { name = "XYZ"; add="IIT "; email="%%%%"; phno="!!!!!"; } string person::getname() const { return name; } string person::getadd()...

  • Design a class named MyPoint to represent a point with x and y-coordinates. The class contains:...

    Design a class named MyPoint to represent a point with x and y-coordinates. The class contains: Two data fields x and y that represent the coordinates. . A no-arg constructor that creates a point (0, 0) .A constructor that constructs a point with specified coordinates. Two get functions for data fields x and y, respectively. A function named distance that returns the distance from this point to another point of the MyPoint type Write a test program that creates two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT