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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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