Inheritancedemo

Assignment Help JAVA Programming
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);
    }
}

Reference no: EM13159634

Questions Cloud

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.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write java program which simulates flipping of coin

Write a Java program which simulates flipping of coin 1000 times and prints total number of heads and tails. You should create a class.

  The objective is to implement a menu-based system

The objective is to implement a menu-based system for Bank Accounts in order to simulate a very simple banking system. Many structures have to be declared to manage bank accounts.

  Java-s ability to derive new fonts from existing ones

Find out where on your system these font libraries are located. When you do, please specify the operating system and the location (folder/directory) where you found them. Discuss Java's ability to derive new fonts from existing ones.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

  Determine the type of moped

Write a driver class called MopedRental. This class should perform the following: asks the user to enter the size of the moped, the day of the week and the number of hours rented, creates the Moped object, based on the size, and displays the input..

  These test scores into an array and computes:

Write a program that reads these test scores into an array and computes:Sum of the test scores after dropping the minimum test scoreAverage of the test scores

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

  Print the contents of the array

Prepare a second loop that prints the contents of the array

  Dijikstra for undirected graph using simple scheme

Dijikstra for undirected graph using simple scheme with array and fibonacci heap and compare the performance/results, preferably in java.

  Write java program which will permit user to input data

Write the Java Program which will permit the user to input data. The data will be validated using a loop that requires the user to input the data until it is correct or in the correct range. T

  Write java application to show successive element of array

Write down java application named GoTooFar which declares the array of 5 integers and stored five values in array. write try block in which you loop to show each successive element of array.

  Sequence of method in vector class

Construct a Vector class implementing a number of vector operations as methods along with a testing program to verify the class is working.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd