Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Inheritance Issue!

Posted on 2006-05-02
3
Medium Priority
?
354 Views
Last Modified: 2010-03-31
Can anyone help me out with an Inheritence issue. I need to provide a simple solution for a Car hire company, It doesnt have to be a fully functioning system but the code must show how the design would be implemented.

For each vehicle I need to keep a note of make, colour, registration and MOT date and print these out in a near and clear fashion. In addtional to this the system must be capable of being modified to incorporate minibuses and trucks (15 & 17 seat capacity) and truck payload of(3,5 & 7 Tonnes)
(Minus bus and truck will use same make, colour & reg details etc)

I have had the code working for the Cars but after trying to use inheritence to reuse code I can't get the program to compile. Any ideas why It won't compile and are there any other problems you can see?

import javax.swing.JOptionPane;
public class Car{

//instance variables
private String make, colour, registration, motDue;


public Car(String make, String colour, String registration, String motDue){
      setMake(make);
      setColour(colour);
      setRegistration(registration);
      setMot(motDue);
}

// Create Text for Output
public String toString() {
String output;
output = "Make:                " + make + "\n";
output = output + "Colour:               " + colour + "\n";
output = output + "Registration:    " + registration + "\n";
output = output + "MOT Due:          " + motDue + "\n";

return output;
}


public void printDetails(){
String output;

output = toString();
JOptionPane.showMessageDialog(null,output,"Vehicle Hire - Car Details",JOptionPane.INFORMATION_MESSAGE);
}

//Set methods for properties

  public void setMake(String aMake){
    make = aMake;
  }

  public void setColour(String aColour){
    colour = aColour;
  }

  public void setRegistration(String aRegistration){
    registration = aRegistration;
  }

  public void setMot(String aMot){
    motDue = aMot;
  }

  //Get methods for properties
  public String getMake(){
    return make;
  }

  public String getColour(){
    return colour;
  }

  public String getRegistration(){
    return registration;
  }

  public String getMot(){
       return motDue;
  }

} //end class

import javax.swing.JOptionPane;

public class Minibus extends Car{

//instance variables
private int seats;


public Car(int seats){

      setSeats(seats);
}


// Create Text for Output
public String toString() {
String output;

output = output + "No. of Seats:    " + seats + "\n";

return output;
}


public void printDetails(){
String output;

output = toString();
JOptionPane.showMessageDialog(null,output," Vehicle Hire - Minibus Details",JOptionPane.INFORMATION_MESSAGE);
}

  //Set methods for properties

  public void setSeats(int aSeats){
    seats = aSeats;
  }

   //Get methods for properties

  public int getSeats(){
       return seats;
  }
} //end class


public class DemoVehicle {
 public static void main (String args[]){

 Car c1 = new Car("Vauxhall", "Red", "MD06 PUV", "12th March 2009");
 Car c2 = new Car("Subaru", "Silver", "ST05 HNX", "14th January 2007");
 Minibus m1 = new Minibus("Ford", "White", "MB03 YHT", "15th February 2007",15);

 c1.printDetails();
 c2.printDetails();


 System.exit(0);
 }
 }


0
Comment
Question by:helpmeoot
3 Comments
 
LVL 4

Expert Comment

by:paulgrunner
ID: 16591050
What is the error message you get?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16591063
>public Car(int seats){
>
>     setSeats(seats);
>}


you ctor is wrong, should be:

public Minibus(String make, String colour, String registration, String motDue, int seats){
     super(make, colour, registration, motDue);
     setSeats(seats);
}
0
 

Author Comment

by:helpmeoot
ID: 16591338
Thanks Objects! Much Appreciated.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question