Reference no: EM13159634
1. Create a New Project named InheritanceDemo . 2. Create a new class called Person and cut and paste the Person.java file from Blackboard into the class. Create a new class called Student and cut and paste the Student.java file from Blackboard into the class. Cut and paste the InheritanceDemo.java file from Blackboard into the InheritanceDemo class. 3. Create a new class called GraduateStudent that inherits from class Student. Add two instance variables, a String called major and a double called gpa. Add two constructors, one with no parameters and one with four. Make sure you call the super constructors for each of them. Write the accessor methods and the mutator methods for major and gpa. Write a reset() method that resets the name, studentNumber, major, and gpa. Finally, write a writeOutput() method that prints out all four values for the GraduateStudent class. 4. Uncomment the commented lines in InheritanceDemo.java. Compile the project and then execute it. What does it output?
public class Person
{
private String name;
public Person ()
{
name = "No name yet";
}
public Person (String initialName)
{
name = initialName;
}
public void setName (String newName)
{
name = newName;
}
public String getName ()
{
return name;
}
public void writeOutput ()
{
System.out.println ("Name: " + name);
}
public boolean hasSameName (Person otherPerson)
{
return this.name.equalsIgnoreCase (otherPerson.name);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class InheritanceDemo
{
public static void main (String [] args)
{
Student s = new Student ();
s.setName ("Warren Peace");
s.setStudentNumber (1234);
s.writeOutput ();
/* GraduateStudent g = new GraduateStudent("Ariel Bender", 5678,
"Computer Science", 4.0);
g.writeOutput ();
g.reset ("Thin White Duke", 2468, "Music", 3.7);
g.writeOutput ();
g.setName ("Holden Caulfield");
g.setStudentNumber (1357);
g.setMajor ("Philosophy");
g.setGpa (3.0);
g.writeOutput ();
*/
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class Student extends Person
{
private int studentNumber;
public Student ()
{
super ();
studentNumber = 0; //Indicating no number yet
}
public Student (String initialName, int initialStudentNumber)
{
super (initialName);
studentNumber = initialStudentNumber;
}
public void reset (String newName, int newStudentNumber)
{
setName (newName);
studentNumber = newStudentNumber;
}
public int getStudentNumber ()
{
return studentNumber;
}
public void setStudentNumber (int newStudentNumber)
{
studentNumber = newStudentNumber;
}
public void writeOutput ()
{
System.out.println ("Name: " + getName ());
System.out.println ("Student Number: " + studentNumber);
}
public boolean equals (Student otherStudent)
{
return this.hasSameName (otherStudent) &&
(this.studentNumber == otherStudent.studentNumber);
}
}
Major influencers upon israel in ancient near east
: What were the major influencers upon Israel in the Ancient Near East (cultures) and how did they impact the Hebrew people/writings of the Hebrew Bible?
|
Explain the effect of increase size of random sample
: The Gallup Poll has decided to increase the size of its random sample of Canadian voters from about 1500 people to 4000 people. The effect of this increase is: increase the standard error of the estimate.
|
State the relative concentrations of hmr
: Suppose that a student collects the following spectrophotometric data to determine the relative concentrations of HMR and MR in solution:
|
Amount of goodwill impairment
: The fair value of net identifiable assets exclusive of goodwill of a reporting unit of X Company is $300,000. On X Company's books, the carrying value of this reporting unit's net assets is $350,000, including $60,000 goodwill. If the fair value o..
|
Inheritancedemo
: Create a New Project named InheritanceDemo . 2. Create a new class called Person and cut and paste the Person.java file from Blackboard into the class. Create a new class called Student and cut and paste the Student.java file from Blackboard into the..
|
To what structure should he apply the pollen
: Darren operates a nusery and he wants to apply some pollon to fertilize som flowers. To what structure should he apply the pollen?
|
Explain a child has a dangerous blood lead level
: A child has a dangerous blood lead level of 120ug/100mL. If the child is administered 100 mL of 0.10M Na2 Ca(EDTA), assuming the exchange reaction
|
Introduction to consolidated financial statements
: Paige, Inc. owns 80% of Sigler, Inc. During 2011, Paige sold goods with a 40% gross profit to Sigler. Sigler sold all of these goods in 2011. For 2011 consolidated financial statements, how should the summation of Paige and Sigler income statement..
|
Confidence for the true variance of the product lengths
: Lengths had a calculated sample standard deviation of 8 and mean of 9.4. Select the 95% confidence for the true variance of the product lengths. Use the appropriate table in the book.
|