HW 10 Create the classes described below. Use meaningful class variables and fun
ID: 3872621 • Letter: H
Question
HW 10 Create the classes described below. Use meaningful class variables and function names. All class variables are private, while functions are public. Each class need to have at least two constructors. Add an instance counter to Student, use the constructors to update this variable. Add a Driver class, instantiate at least 3 objects of each class using constructors, and print each object to the console. BONUS: Automate the generation of new ID values for Student and Employee types. So, first ID=1, 2nd ID= 2, and so on. Ensure programmatically that once created, an ID value cannot be accidentally changed. (up to +5 points) Team (name, city) > NBATeam (arenaName, coachName) Person (name, dateOfBirth) -> student (ID, SchoolName, GPA) .Person (name, dateOfBirth)->Employee(ID, title, hireDate, deptName, salary) .Employee>SoftwareDeveloper (languages, technologies)Explanation / Answer
import java.util.*;
class Team
{
private String name,city;
//constructors
public Team()
{
name = " ";
city = " ";
}
public Team(String name,String city)
{
this.name = name;
this.city = city;
}
public String toString()
{
return " Team : name "+name + " city "+city;
}
}
class NBATeam extends Team
{
private String arenaName,coachName;
public NBATeam()
{
arenaName = " ";
coachName = " ";
}
public NBATeam(String arenaName,String coachName)
{
this.arenaName = arenaName;
this.coachName = coachName;
}
public String toString()
{
return " NBA Team : Arenaname : "+arenaName + " Coachname : "+coachName;
}
}
class Person
{
private String name,dateOfBirth;
public Person()
{
name = " ";
dateOfBirth = " ";
}
public Person(String name,String dateOfBirth)
{
this.name = name;
this.dateOfBirth = dateOfBirth;
}
public String toString()
{
return " Name : "+ name + " Date of Birth : "+dateOfBirth;
}
}
class Student extends Person
{
private static int ID = 1;
private String schoolName;
private double GPA;
public Student()
{
ID++;
schoolName = " ";
GPA = 0.0;
}
public Student(String schoolName,double GPA)
{
ID++;
this.schoolName = schoolName;
this.GPA = GPA;
}
public String toString()
{
return " Student ID : "+ID +" School Name : "+schoolName +" GPA : "+GPA;
}
}
class Employee extends Person
{
private static int ID = 100;
private String title,hireDate,deptName;
private double salary;
public Employee()
{
ID++;
title = " ";
hireDate = " ";
salary = 0.0;
}
public Employee(String title,String hireDate,String deptName,double salary)
{
this.title = title;
this.hireDate = hireDate;
this.deptName = deptName;
this.salary = salary;
}
public String toString()
{
return " Employee ID : "+ID + " title : "+title + " hireDate : "+hireDate +" deptName : "+deptName;
}
}
class SoftwareDeveloper extends Employee
{
private String languages,technologies;
public SoftwareDeveloper()
{
languages = " ";
technologies = " ";
}
public SoftwareDeveloper(String languages,String technologies)
{
this.languages = languages;
this.technologies = technologies;
}
public String toString()
{
return " Software Developer : Languages : "+ languages +" technologies "+technologies;
}
}
class Test
{
public static void main (String[] args)
{
//objects of different classes
NBATeam nt = new NBATeam(" AB Grounds"," Trevor Bayliss");
//calling toString() method
System.out.println(nt);
Student s1 = new Student("New Jersey School",6.7);
System.out.println(s1);
Employee e1 = new Employee("Accountant","09/02/2008","Accounts",5667.78);
System.out.println(e1);
SoftwareDeveloper sd1 = new SoftwareDeveloper("C,C++,Java","OOP,Testing");
System.out.println(sd1);
}
}
Output:
NBA Team : Arenaname : AB Grounds Coachname : Trevor Bayliss
Student ID : 2 School Name : New Jersey School GPA : 6.7
Employee ID : 100 title : Accountant hireDate : 09/02/2008 deptName : Accounts
Software Developer : Languages : C,C++,Java technologies OOP,Testing
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.