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

  Technical community blog

Write a blog article for a coding and technical community blog.

  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.

  How to access to elements of document object model

To limit creation of malicious code, do you believe that access to elements of document object model and some Javascript functionality be limited?

  Implement the lexical and syntactic analysis

Implement the lexical and syntactic analysis of Minifun programming language.

  Simulate a simple multiuser computer system

Prepare a java program to simulate a simple multiuser computer system

  Write various bindings to determine semantics

Write the various bindings that are required to determine the semantics when statement is executed. For each binding, indicate binding time used for language. Describe your answer.

  Function using javascript syntax to compute gross pay

Write a function using JavaScript syntax to compute a person's gross pay for a week. The function must receive the number of hours worked and the rate of pay per hour.

  Tracer for java

Implementation of a tracer of Java objects and the tracer can be invoked from any point of a Java program, accepting an object as argument.

  Determine the visual resolution of resulting image

Drawing in 8.5 by 11 inch sheet is digitized by means of 300 dpi (dots per inch) scanner. Determine the visual resolution of resulting image (number of dots in each dimension)?

  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.

  Java application to permit user to enter ten numbers

Write down Java application which permits a user to enter 10 numbers (double precision) into the array and then sorts and displays numbers from lowest to highest.

  Create the working applet to compute tax

Write down a java applet. Your applet assits to find out how much federal tax we require to pay suppose the tax rate is 12%. Create and implement the working applet to compute tax.

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