(Java code) Download the complete student information program and add the following feature to it: 1. There...
Question:
(Java code)
Download the complete student information program and add the following feature to it:
1. There is still duplicate code in the deansHonourList() method in the two subclasses. This code can be moved into the superclass, but the two types of students have different criteria for being on the list. You can make it work without using instanceof or getClass(), and without adding any more if-else statements or instance variables. Make this change; there should be no deansHonourList() method in either GraduateStudent or UndergraduateStudent, and the getGPA() method can be removed. Hint: add another instance method to the superclass and override it in the subclasses as necessary; call that method in your deansHonourList() method.
2. After making the change above, create another subclass of Student called VisitingStudent. A visiting student has all of the Student instance variables, plus a string that indicates which university the student is visiting from. A visiting student cannot be on the Dean's honour list; make sure the deansHonourList() method always returns false for them. Also make sure the toString() method includes the additional information.
Submit your four classes (Student, GraduateStudent, UndergraduateStudent, and VisitingStudent) by the due date specified in the course schedule.
import java.io.*;
public class Activity6A {
public static void main(String[] args) {
UndergradStudent undergrad1, undergrad2;
GraduateStudent grad1, grad2;
undergrad1 = new UndergradStudent(8032, "Casper", 2.78, 2);
grad1 = new GraduateStudent(3044, "Sheena", 3.92, "Natural Language Processing");
undergrad2 = new UndergradStudent(6170, "Yolanda", 4.26, 3);
grad2 = new GraduateStudent(1755, "Geordi", 3.58, "Human-Computer Interaction");
System.out.println(undergrad1);
System.out.println(grad1);
System.out.println(undergrad2);
System.out.println(grad2);
System.out.println("End of processing.");
}
}
class UndergradStudent {
private int number;
private String name;
private double gpa;
private int year;
public UndergradStudent(int number, String name, double gpa, int year) {
this.number = number;
this.name = name;
this.gpa = gpa;
this.year = year;
}
public double getGPA() {
return gpa;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.5)
result = true;
return result;
}
public String toString() {
return "Undergraduate: " + number + " " + name + " (" + gpa + ") year: " + year;
}
}
class GraduateStudent {
private int number;
private String name;
private double gpa;
private String thesis;
public GraduateStudent(int number, String name, double gpa, String thesis) {
this.number = number;
this.name = name;
this.gpa = gpa;
this.thesis = thesis;
}
public double getGPA() {
return gpa;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.75)
result = true;
return result;
}
public String toString() {
return "Graduate: " + number + " " + name + " (" + gpa + ") thesis: " + thesis;
}
}
import java.io.*;
public class Activity6B {
public static void main(String[] args) {
Student[] students = new Student[4];
students[0] = new UndergradStudent(8032, "Casper", 2.78, 2);
students[1] = new GraduateStudent(3044, "Sheena", 3.92, "Natural Language Processing");
students[2] = new UndergradStudent(6170, "Yolanda", 4.26, 3);
students[3] = new GraduateStudent(1755, "Geordi", 3.58, "Human-Computer Interaction");
printStudents(students);
System.out.println("End of processing.");
}
public static void printStudents(Student[] students) {
System.out.println("List of all students:");
for (int i = 0; i < students.length; i++) {
System.out.println(i + 1 + ": " + students[i]);
}
}
}
class Student {
private int number;
private String name;
private double gpa;
public Student(int number, String name, double gpa) {
this.number = number;
this.name = name;
this.gpa = gpa;
}
public double getGPA() {
return gpa;
}
public String toString() {
return number + " " + name + " (" + gpa + ")";
}
}
class UndergradStudent extends Student {
private int year;
public UndergradStudent(int number, String name, double gpa, int year) {
super(number, name, gpa);
this.year = year;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.5)
result = true;
return result;
}
public String toString() {
return "Undergraduate: " + super.toString() + " year: " + year;
}
}
class GraduateStudent extends Student {
private String thesis;
public GraduateStudent(int number, String name, double gpa, String thesis) {
super(number, name, gpa);
this.thesis = thesis;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.75)
result = true;
return result;
}
public String toString() {
return "Graduate: " + super.toString() + " thesis: " + thesis;
}
}
import java.io.*;
public class Activity6C {
public static void main(String[] args) {
Student[] students = new Student[4];
students[0] = new UndergradStudent(8032, "Casper", 2.78, 2);
students[1] = new GraduateStudent(3044, "Sheena", 3.92, "Natural Language Processing");
students[2] = new UndergradStudent(6170, "Yolanda", 4.26, 3);
students[3] = new GraduateStudent(1755, "Geordi", 3.58, "Human-Computer Interaction");
printStudents(students);
printDeansList(students);
System.out.println("End of processing.");
}
public static void printStudents(Student[] students) {
System.out.println("List of all students:");
for (int i = 0; i < students.length; i++) {
System.out.println(i + 1 + ": " + students[i]);
}
}
public static void printDeansList(Student[] students) {
System.out.println("Dean's honour list:");
for (int i = 0; i < students.length; i++) {
if (students[i].deansHonourList()) {
System.out.println(students[i]);
}
}
}
}
class Student {
private int number;
private String name;
private double gpa;
public Student(int number, String name, double gpa) {
this.number = number;
this.name = name;
this.gpa = gpa;
}
public double getGPA() {
return gpa;
}
public boolean deansHonourList() {
return false;
}
public String toString() {
return number + " " + name + " (" + gpa + ")";
}
}
class UndergradStudent extends Student {
private int year;
public UndergradStudent(int number, String name, double gpa, int year) {
super(number, name, gpa);
this.year = year;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.5)
result = true;
return result;
}
public String toString() {
return "Undergraduate: " + super.toString() + " year: " + year;
}
}
class GraduateStudent extends Student {
private String thesis;
public GraduateStudent(int number, String name, double gpa, String thesis) {
super(number, name, gpa);
this.thesis = thesis;
}
public boolean deansHonourList() {
boolean result = false;
if (getGPA() >= 3.75)
result = true;
return result;
}
public String toString() {
return "Graduate: " + super.toString() + " thesis: " + thesis;
}
}
Managerial Accounting A Focus on Ethical Decision Making
ISBN: 978-0324663853
5th edition
Authors: Steve Jackson, Roby Sawyers, Greg Jenkins