Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Student.Java : public class Student { private String name; private int studentNumber; public Student(String name, int studentNumber) { this.name = name; this.studentNumber = studentNumber; }

image text in transcribed

Student.Java :

public class Student

{

private String name;

private int studentNumber;

public Student(String name, int studentNumber)

{

this.name = name;

this.studentNumber = studentNumber;

}

public String getName()

{

return name;

}

public int getNumber()

{

return studentNumber;

}

public void setName(String name)

{

this.name = name;

}

public void setNumber(int number)

{

this.studentNumber = number;

}

public String toString()

{

return "This is a student named "+name;

}

public boolean equals(Object o)

{

if (this == o) return true; // they are the same object

if (o == null) return false; // o is null

if (getClass() != o.getClass()) return false; // o is not a Student

Student oStudent = (Student) o;

return (oStudent.getName().equals(this.getName()) && oStudent.getNumber() == this.getNumber());

}

}

Overview: In this lab, you are provided with a class called Student and asked to create a subclass of student called ExchangeStudent. A. The Student class Download Student java and look through the code. Most of this should be straightforward. A student has a name and a student number. Look through the equals method and make sure you understand what it is doing. Two students are considered equal if they have the same name and same student number. B. The ExchangeStudent class Create a subclass of Student called ExchangeStudent (it extends Student). ExchangeStudent should have the following elements: 1. A String instance field representing the country they are visiting from. 2. A constructor that takes a name, number and country. This constructor should call the superclass constructor with name and number, and then set the country instance field directly. 3. A getter method for the country instance field 4. An overriden toString() method. This method should return a concatenation of the student name followed by a space followed by their country C. The StudentTester class In the main) method of a separate tester class, create 3 objects: 1. A Student object with Student variable type (eg. Student s1 = new Student( 2. An ExchangeStudent object with Student variable type 3. An ExchangeStudent object with ExchangeStudent variable type )) Then call System.out.printin() directly on each object you created, e.g System.out.println(student1); Examine the output and make sure you understand the differences Also in the main() method, create two separate objects with identical names and student numbers and confirm that they are equal according to the equals) method Deliverables: Zip up ExchangeStudent.java and StudentTester.java and submit the zip file via Blackboard

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+a) Show that mixing implies ergodicity.

Answered: 1 week ago