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 a java program to compute salary

Write a Java program which computes the Salary for a given number of employees. The program prompts user to enter n the number of employees.

  Write a program that reads a set of floating-point

Write a program that reads a set of floating-point data values from the input.

  Understand actual communication with an smtp server

Understand actual communication with an SMTP server can be achieved using TCP Sockets and understand the development of a graphical user interface (GUI) and use of event handling.

  Write java program to compute how much federal need to pay

Write a java application to calculate how much federal and state tax you need to pay. The program should accomplish the following task.

  Uml exercise

UML Exercise: Automated Teller Machine (ATM),   1. To allow authorized card holders to make transactions,   Brief Summary of Requirements:

  Write java program to find calories-conditional operator

Write down the answer for this program? Write down Java program (use Conditional (? Operator) which suggests number of calories a person must eat each day.

  Create a world class that contains a 2d array

You have to create a world class that contains a 2d array then create an abstract class called organism that contains move() method the organism should move randomly one step at the time.

  Develop a gui based java program

Designing and developing a College Registration program

  Determine the decision of java

Determine the decision of Java as the platform to develop this program. Identify the Java-based technologies utilized in this project and analyze each of them. Then, provide discussion on the purpose of each of the Java-based technologies utiliz..

  Implement a class quiz

Implement a class Quiz that implements the Measurable interface.

  Write java program prints strings given at command line

Write down the program Average.java which just prints strings which it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Utilizes a good design process

Analyze, design, and document a simple program that utilizes a good design process and incorporates sequential, selection and repetitive programming statements as well as at least one function call and the use of at least one array.

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