Subclass toString should call include super.toString();

re-submit these codes.

 

public class Vehicle {

 

   private String registrationNumber;

 

   private String ownerName;

 

   private double price;

 

   private int yearManufactured;

 

   Vehicle [] myVehicles = new Vehicle[100];

 

 

 

   public Vehicle() {

 

       registrationNumber="";

 

       ownerName="";

 

       price=0.0;

 

       yearManufactured=0;

 

   }

 

   public Vehicle(String registrationNumber, String ownerName, double price, int yearManufactured) {

 

       this.registrationNumber=registrationNumber;

 

       this.ownerName=ownerName;

 

       this.price=price;

 

       this.yearManufactured=yearManufactured;

 

   }

 

   public String getRegistrationNumber() {

 

       return registrationNumber;

 

   }

 

   public String getOwnerName() {

 

       return ownerName;

 

   }

 

   public double getPrice() {

 

       return price;

 

   }

 

   public int getYearManufactured() {

 

       return yearManufactured;

 

   }

 

   public void setRegistrationNumber(String registrationNumber) {

 

       this.registrationNumber=registrationNumber;

 

   }

 

   public void setOwnerName(String ownerName) {

 

       this.ownerName=ownerName;

 

   }

 

   public void setPrice(double price) {

 

       this.price=price;

 

   }

 

   public void setYearManufactured(int yearManufactured) {

 

       this.yearManufactured=yearManufactured;

 

   }

 

 

 

   public String toString() {

 

       return " Registration number:"+ registrationNumber +"\n Owner Name:"+ownerName+"\n Price:"+

 

   price+"\n year manufactured"+yearManufactured;

 

   }

 

public static double findMin(Vehicle[] theVehicles)

 

{

 

   double lowestPrice = Vehicles[0];

 

   for(int i=1; i<price.length;i++){

 

   if(Vehicles[i] < lowestPrice){

 

       lowestPrice = Vehicles[i];

 

       } 

 

   }

 

   return lowestPrice;

 

}

 

 

public class Car extends Vehicle{

    private int numberOfDoors;

 

    public Car(String registrationNumber, String ownerName, double price, int yearManufactured, int numberOfDoors) {

        super(registrationNumber, ownerName, price, yearManufactured);

        this.numberOfDoors = numberOfDoors;

    }

 

    public int getNumberOfDoors() {

        return numberOfDoors;

    }

 

    @Override

    public String toString() {

        return "Car{" +

                "numberOfDoors=" + numberOfDoors +

                '}';

    }

 

    public void setNumberOfDoors(int numberOfDoors) {

        this.numberOfDoors = numberOfDoors;

    }

}

public class Truck extends Vehicle{

    private int numberOfAxles;

 

    public Truck(String registrationNumber, String ownerName, double price, int yearManufactured, int numberOfAxles) {

        super(registrationNumber, ownerName, price, yearManufactured);

        this.numberOfAxles = numberOfAxles;

    }

 

    public int getNumberOfAxles() {

        return numberOfAxles;

    }

 

    public void setNumberOfAxles(int numberOfAxles) {

        this.numberOfAxles = numberOfAxles;

    }

 

    @Override

    public String toString() {

        return "Truck{" +

                "numberOfAxles=" + numberOfAxles +

                '}';

    }

}

 

Expert Solution
Students who’ve seen this question also like:
Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Not helpful? See similar books
Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
Computer Networks And The Internet. R1RQ
marketing sidebar icon
Want to see this answer and more?
Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*
*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

Related Computer Engineering Q&A

Find answers to questions asked by students like you.

Q: Pet Whisperer Define a public class Whisperer that provides a single class method named…

A: Java  Code for Above :   //class in which method is defined class Whisperer{     //method…

Q: Create the a Person class with the following: Class Variables String firstname String lastname int…

A: Actually, Java is a high level  programming language. And also object oriented . It. Is a platform…

Q: Book class: • private data members: o bookName: as String o bookAuthor: as object of class Author o…

A: package bookauthor;                 //Same package where class Author is therepublic class Book {…

Q: 2)Start by completing the constructor. The Sedan constructor takes only one argument (MPG) since the…

A: ALGORITHM:- 1. Use super to call the parent class constructor in Sedan class. 2. In efficient()…

Q: True or False, the below method is a good example of a toString() method for the below class: public…

A: In second step all the explain the all data member and method to the override.

Q: Nutritional information (classes/constructors) PYTHON ONLY Complete the FoodItem class by adding a…

A: Given: Complete the FoodItem class by adding a constructor to initialize a food item. The…

Q: Subject(String subjectStr) { subjectName = subjectStr; } %3D public String returnSubjectstr() {…

A: Find the answer given as below : As this is pseudo code there is no output:

Q: Create a Dog and a Cat class, each of which inherit from Animal. Each class should have a…

A: Programs are a set of lines of code that give the machine instructions. To complete those tasks,…

Q: Defining Classes Write and document the definition for the Money class. The Money class represents…

A: Purpose of the program: This program would create the Money.java class with two pre-defined…

Q: Assume the Book class is defined as follows:   public class Book{  enum Type type…

A: The Book class is defined as follows:   public class Book{  enum Type type {FICTION,NON_FICTION};…

Q: Write the Bicyle class which extends Vehicle. The UML diagram is shown below. Follow it exactly.…

A: public class Vehicle { private String owner; private int wheels;  public Vehicle(String owner, int…

Q: The class "Student" has the following attributes: studentId (int), name (String), surname (String),…

A: Given: The class "Student" has the following attributes: studentId (int), name (String), surname…

Q: 2. Student (extend the class Person) that has the following: Data Fields: private int ID pnvate…

A: Accessors:  Accessors are member functions.  These allow to access data memebers.  They must have…

Q: Class : HumanBeing Main Class: Index private public setHeight() 1. call the Human height being…

A: Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that…

Q: 1. Complete the partial declaration of Class Car public class Car { declare three private instamce…

A: NOTE: Since programming, langauge is not mentioned. Therefore the answering question in Java…

Q: super can be used to invoke superclass method> Write a code snippet

A: super is a keyword used to access Parent class methods as well as parent class constructors and it…

Q: Exercises abstract class • Design a new Triangle class that extends the abstract GeometricObject…

A: Program Approach: Defining the necessary packages Defining the Base class Declaring the method…

Q: Programming Language = Python 1. Employee and ProductionWorker Classes Write an Employee class…

A: Programming Approach: Defining a class Employee. Defining the _init_ method. Defining method…

Q: Java User-Defined Class Create a class named: Student with the following class members: Constructor…

A: Here I have created the class Student. Next, I have created the variables as per the question. Next,…

Q: Find the error in each of the following code segments: // Superclasspublic class Vehicle{private…

A: Given : Find the error in each of the following code segments: // Superclasspublic class…

Q: reference is used to refer to a child class object. class Main ( public static void main(String(]…

A: class Animal{    void displayInfo(){        System.out.println("Its A Animal");    }}class Dog…

Q: reate a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and…

A: First, create class BeautyProduct as mentioned.   Next, create class Lipstick which inherits base…

Q: . Exercise # 2: Implement a class Portfolio. This class has two objects, checking and saving, of the…

A: Here is the detailed and simplified python code for the above listed problem statement:

Q: (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw…

A: Given:

Q: public class Rational private int numerator; private int denominator; public Rational (int…

A: GIVEN: Fix the typo in the given java program. The output should be a single line.   TYPO ERROR: In…

Q: Vehicle is an abstract class. Create the Airplane class as a subclass of Vehicle. Extend and…

A: We have to write a Java program for  Vehicle is an abstract class. Create the Airplane class as a…

Q: JAVA USER-DEFINED CLASS: Create a class named: Student with the following class members: Constructor…

A: Student.java   public class Student{ int studentNo; String fname; String lname; String course;…

Q: Given the following class   public class student {      private String name; private String email;…

A: public class Student {   private String name;     private String email;    private int id;…

Q: Loan Account Class: Create class LoanAccount. Use a static variable annuallnterestRate to store the…

A: Source code LoanAccount class public class LoanAccount { //declare static double variable…

Q: A class which is called Employee consists of: • Instance Variable Name of employee (String) - Job…

A: public class Employee  {     private String firstName;     private String lastName;     private…

Q: class Person(name:String, age:Int) class Student(name:String,major:String, age:Int) :…

A: When we run the code we get the following error: this type is final, so it cannot be inherited…

Q: 1 using static System.Console; 2 class ShapesDemo 3 { static void Main() { abstract class…

A: Netezza is the appliance of IBM, whereas it is not used in big data to provide high storage; it is…

Q: JAVA class:  Main.java, Quadratic.java, TestQuadratic.java Create a class called Quadratic for…

A: The roots of the quadratic equation in the form of ax2+bx+c=0 can be calculated using the below…

Q: public abstract class DebugBoat {    String boatType = new String();    int passengers;    String…

A: public abstract class DebugBoat{   String boatType = new String();   int passengers;   String power…

Q: Write a Point class with two properties: 1, y. Write required constructor, get & set, and toString…

A: I have given an answer in step 2.

Q: • Write a Point class with two properties: 1, y. Write required constructor, get & set, and toString…

A: Point class :-  properties - x,y methods - get, set and toString  Note :- as only class definitions…

Q: Java programming lanaguage A. Design and implement the class Circle that contains the double…

A: Here I have created a class named Circle. Here I have created a variable named radius. Next, I have…

Q: Apex code: - public with sharing class MyFirstClass {     public static Integer…

A: Below is the detailed solution to the given problem statement:

Q: amountofcontainers int amountofholds: int Gload (containes: int) load (type: String ) 1) Create a…

A: public class Ship {  public int length; public double grosstonnage; public String flag; public…

Q: Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and…

A: The question asks about constructing a super class of BeautyProduct and then two child classes for…

Q: Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and…

A: The question asks about constructing a super class of BeautyProduct and then two child classes for…

Q: Write a class Runner having three private data members (distance, minutes, seconds) The class has A…

A: Programming instructions:   Create a class. Declare private variables. Create a constructor with no…

Q: Q1. In the following class, how many instance variables are there? public class Car { int numDoors;…

A: - The question is to find the number of instance variable in the given code.  - The second question…

Q: Write a Dice class. The class should have: • A private field for the number of sides of the die • A…

A: Java used to answer this question

Q: 1.1. Write a front-end class called Debug and save it in a file called Debug.cpp. This class must…

A: Objective: A CPP file should be created naming "Debug.cpp" that has two static public members, i.e.…

Q: Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a…

A: public class LandTract { double length; double width;  public LandTract(double length, double width)…

Q: Class Attributes Attributes type Methods Ojon Dharon Khomota String Float LoadKora() UnLoadKora()…

A: We will solve this problem in Java Language.

Q: Using JAVA language complete the following tasks inside the Employee class: Consider a base class…

A: Program: import java.awt.*;import java.awt.event.*;import javax.swing.*;import…

Q: Using JAVA language complete the following tasks inside the Employee class: Consider a base class…

A: public class Employee{    private String name;    private int empID;    private double hourlyIncome;…

Q: Every class has a constructor and if we do not explicitly write a constructor for a class, the java…

A: In Java, if we do not implement any constructor in our class, then Java compiler inserts a default…

Knowledge Booster
Recommended textbooks for you
  • Computer Networking: A Top-Down Approach (7th Edi...
    Computer Engineering
    ISBN:9780133594140
    Author:James Kurose, Keith Ross
    Publisher:PEARSON
    Computer Organization and Design MIPS Edition, Fi...
    Computer Engineering
    ISBN:9780124077263
    Author:David A. Patterson, John L. Hennessy
    Publisher:Elsevier Science
    Network+ Guide to Networks (MindTap Course List)
    Computer Engineering
    ISBN:9781337569330
    Author:Jill West, Tamara Dean, Jean Andrews
    Publisher:Cengage Learning
  • Concepts of Database Management
    Computer Engineering
    ISBN:9781337093422
    Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
    Publisher:Cengage Learning
    Prelude to Programming
    Computer Engineering
    ISBN:9780133750423
    Author:VENIT, Stewart
    Publisher:Pearson Education
    Sc Business Data Communications and Networking, T...
    Computer Engineering
    ISBN:9781119368830
    Author:FITZGERALD
    Publisher:WILEY
  • Computer Networking: A Top-Down Approach (7th Edi...
    Computer Engineering
    ISBN:9780133594140
    Author:James Kurose, Keith Ross
    Publisher:PEARSON
    Computer Organization and Design MIPS Edition, Fi...
    Computer Engineering
    ISBN:9780124077263
    Author:David A. Patterson, John L. Hennessy
    Publisher:Elsevier Science
    Network+ Guide to Networks (MindTap Course List)
    Computer Engineering
    ISBN:9781337569330
    Author:Jill West, Tamara Dean, Jean Andrews
    Publisher:Cengage Learning
    Concepts of Database Management
    Computer Engineering
    ISBN:9781337093422
    Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
    Publisher:Cengage Learning
    Prelude to Programming
    Computer Engineering
    ISBN:9780133750423
    Author:VENIT, Stewart
    Publisher:Pearson Education
    Sc Business Data Communications and Networking, T...
    Computer Engineering
    ISBN:9781119368830
    Author:FITZGERALD
    Publisher:WILEY