Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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);
    }
}

Java, Programming

  • Category:- Java
  • Reference No.:- M9449760

Have any Question?


Related Questions in Java

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As