Java help:
1.1) Create a class TA that extends class
Student.
1.2) Add a variable to the TA class to represent the course the
student is TA'ing.
1.3) Provide a constructor for the class so the code in the
PeopleFactory will work as provided.
1.4) Provide a toString() method for the TA class so
that TA's will output as shown in the sample code.
Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that creates Staff objects and so the output is like the sample shown in the Tester. You will have to do the following:
2.1) Create a class Staff that extends
class Person.
2.2) Add variables to the Staff class to represent the
department and position of the staff member.
2.3) Provide a constructor for the class so the code in the
PeopleFactory will work as provided.
2.4) Provide a toString() method for the Staff class so that Staff
objects will output as shown in the sample code.
Provided code:
public class PeopleFactory {
public static ArrayList getSomePeople() {
ArrayList people = new ArrayList();
people.add(new Person("Lou"));
people.add(new Student("Sue"));
people.add(new Student("Anne"));
people.add(new Professor("Morrison"));
people.add(new Student("Frank"));
people.add(new Person("Britney"));
people.add(new Professor("Nel"));
people.add(new TA("Terri", "COMP1405"));
people.add(new TA("Glenn", "COMP1405"));
people.add(new Staff("Linda", "Comp Sci", "Administrator"));
people.add(new Staff("John", "Comp Sci", "Tech Support"));
return people;
}
public class Student extends Person{
private static int nextStudentNumber = 12345; //initial value of transaction numbers
private int studentNumber;
public Student(String aName){
super(aName);
studentNumber = nextStudentNumber;
nextStudentNumber++;
}
/*
public boolean equals(Object anObject){
if(!(anObject instanceof Student) ) return false;
return name.equals(((Student) anObject).getName());
}
*/
public String toString(){
return super.toString() + " #" + studentNumber;
}
}
public class Professor extends Person{
private static int nextEmployeeNumber = 12345; //initial value of transaction numbers
private int employeeNumber;
public Professor(String aName){
super(aName);
employeeNumber = nextEmployeeNumber;
nextEmployeeNumber++;
}
public String toString(){
return "Prof. " + super.toString() + " emp#" + employeeNumber;
}
}
public class Person{
private static int nextSocialInsuranceNumber = 100000000; //initial value of transaction numbers
private String name = "UNNAMED";
private int sinNumber;
public Person(String aName){
sinNumber = nextSocialInsuranceNumber;
nextSocialInsuranceNumber++;
name = aName;
}
public boolean equals(Object anObject){
if(!(anObject instanceof Person) ) return false;
return name.equals(((Person) anObject).getName());
}
public String getName(){return name;
}
public String getSinNumber(){return name;
}
public String toString(){
return name;
}
}
public class TA extends Student{
public TA(String aName) {
super(aName);
}
}
import java.util.ArrayList;
public class Tester{
public static void main(String[] args){
//Create ArrayLists to hold some Persons objects and the different class names
ArrayList people = PeopleFactory.getSomePeople();
ArrayList classNames = new ArrayList();
//fill the classNames ArrayList with the different kinds of people
//This loop makes sure a class name is only added once
for(Person aPerson : people){
//Determine the real class name of the person
String nameOfPersonsClass = aPerson.getClass().getName();
//check if the class name is already in the classNames collection
boolean found = false;
for(String aClassName : classNames){
if(aClassName.equals(nameOfPersonsClass)) found = true;
}
//if the class name was not already there then add it
if(found == false)
classNames.add(nameOfPersonsClass);
}
//Print out how many different kinds of people there are and their class names
System.out.println(classNames.size() + " kinds of people: " + classNames);
System.out.println(" ");
System.out.println("The kinds of people");
System.out.println("=====================");
//Use destructive iteration to go over the classes
while(!classNames.isEmpty()){
//find and remove a class name
String className = classNames.get(0);
classNames.remove(className);
System.out.println(" ");
System.out.println(className + "s:");
System.out.println("-----------");
//Loop over the people and print them if their class name
//matches the current class being displayed
for(Person aPerson : people){
if(aPerson.getClass().getName().equals(className))
System.out.println(aPerson);
}
}
} //end main
} //end class Tester
public class PeopleFactory { public static ArrayList getSomePeople() { ArrayList people = new ArrayList(); people.add(new Person("Lou")); people.add(new Student("Sue")); people.add(new Student("Anne")); people.add(new Professor("Morrison")); people.add(new Student("Frank")); people.add(new Person("Britney")); people.add(new Professor("Nel")); people.add(new TA("Terri", "COMP1405")); people.add(new TA("Glenn", "COMP1405")); people.add(new Staff("Linda", "Comp Sci", "Administrator")); people.add(new Staff("John", "Comp Sci", "Tech Support")); return people; }
public class Student extends Person{ private static int nextStudentNumber = 12345; //initial value of transaction numbers private int studentNumber; public Student(String aName){ super(aName); studentNumber = nextStudentNumber; nextStudentNumber++; } /* public boolean equals(Object anObject){ if(!(anObject instanceof Student) ) return false; return name.equals(((Student) anObject).getName()); } */ public String toString(){ return super.toString() + " #" + studentNumber; } }
public class Professor extends Person{ private static int nextEmployeeNumber = 12345; //initial value of transaction numbers private int employeeNumber; public Professor(String aName){ super(aName); employeeNumber = nextEmployeeNumber; nextEmployeeNumber++; } public String toString(){ return "Prof. " + super.toString() + " emp#" + employeeNumber; } }
import java.util.ArrayList; public class Tester{ public static void main(String[] args){ //Create ArrayLists to hold some Persons objects and the different class names ArrayList<Person> people = PeopleFactory.getSomePeople(); ArrayList<String> classNames = new ArrayList<String>(); //fill the classNames ArrayList with the different kinds of people //This loop makes sure a class name is only added once for(Person aPerson : people){ //Determine the real class name of the person String nameOfPersonsClass = aPerson.getClass().getName(); //check if the class name is already in the classNames collection boolean found = false; for(String aClassName : classNames){ if(aClassName.equals(nameOfPersonsClass)) found = true; } //if the class name was not already there then add it if(found == false) classNames.add(nameOfPersonsClass); } //Print out how many different kinds of people there are and their class names System.out.println(classNames.size() + " kinds of people: " + classNames); System.out.println(" "); System.out.println("The kinds of people"); System.out.println("====================="); //Use destructive iteration to go over the classes while(!classNames.isEmpty()){ //find and remove a class name String className = classNames.get(0); classNames.remove(className); System.out.println(" "); System.out.println(className + "s:"); System.out.println("-----------"); //Loop over the people and print them if their class name //matches the current class being displayed for(Person aPerson : people){ if(aPerson.getClass().getName().equals(className)) System.out.println(aPerson); } } } //end main } //end class Tester public class TA extends Student {
private String course;
public Student(String aName, String aCourse){
super(aName);
course = aCourse
} // End Constructor to TA class
public String toString(){
return aCouse+" TA:" + super.toString();
} // End toString function of TA Class
} // End TA Class
public class Staff extends Person {
private String department;
private String position;
public Staff(String aName,String aDepartment,String aPosition) {
super(aName);
department = aDepartment;
position = aPosition;
}//end constructor
public String toString(){
return super.toString() + " Staff: " + department+", "+position;
} // End toString function of Staff Class
}//End of Staff class
Java help: 1.1) Create a class TA that extends class Student. 1.2) Add a variable to the...
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...
I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank; public Student() { this.name = this.major = this.status = ""; this.rank = 0; } public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; } public int...
The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams and print it to the terminal via the driver class: import java.util.*; public class Racer implements Comparable { private final String name; private final int year; private final int topSpeed; public Racer(String name, int year, int topSpeed){ this.name = name; this.year = year; this.topSpeed = topSpeed; } public String toString(){ return name + "-" + year + ", Top...
In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...
What causes an assertion error in JAVA on this? Code: public class Student extends Staff { private String s1; private String s2; public Student (String firstName, String lastName, String s1, String s2) { this.s1 = s1; this.s2 = s2; } public boolean equals(Person s){ if (s == null) return false; return ((this.s1).equals(this.s2)); } } Test Case: public void areTheyEqualTest() { Student s1 = new Student( FIRST_NAME, LAST_NAME); ...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
Solve this using Java for an Intro To Java Class.
Provided files:
Person.java
/**
* Models a person
*/
public class Person
{
private String name;
private String gender;
private int age;
/**
* Consructs a Person object
* @param name the name of the person
* @param gender the gender of the person either
* m for male or f for female
* @param age the age of the person
*/
public Person(String name, String gender, int age)
{...