Results 1 to 3 of 3
- 03-15-2011, 06:32 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 6
- Rep Power
- 0
I'm having trouble with extending classes
Here is my code. I can't get it to run.
import java.io.*;
class gcamposAuto {
private String make;
private Integer cylinders;
private String transmission;
private String color;
gcamposAuto(String autoMake, int autoCylinders, String autoTransmission, String autoColor)
{
make = autoMake;
cylinders = autoCylinders;
transmission = autoTransmission;
color = autoColor;
}
public String getMake()
{
return make;
}
public int getCylinders()
{
return cylinders;
}
public String getTransmission()
{
return transmission;
}
public String getColor()
{
return color;
}
String printAuto()
{
return("A "+ getColor()+", "+ getTransmission()+ ", "+" v"+getCylinders()+ getMake()+" automobile" );
}
}
class Truck extends gcamposAuto
{
private int towCapacity;
private int groundClearance;
public Truck(String autoMake, int autoCylinders, String autoTransmission, String autoColor, int truckTowC,int truckGroundC )
{
super(autoMake, autoCylinders, autoTransmission, autoColor);
towCapacity = truckTowC;
groundClearance = truckGroundC;
}
public int getTcapacity()
{
return towCapacity;
}
public int getGclearance()
{
return groundClearance;
}
{
super.getMake();
super.getCylinders();
super.getTransmission();
super.getColor();
}
String printTruck()
{
return("A "+ getColor()+", "+ getTransmission()+ ", "+" v"+getCylinders()+ getMake()+" truck with"+ getTcapacity()+ " lbs \n of towing capacity and "+ getGclearance()+ " inches of ground clearance");
}
}
class Car extends gcamposAuto
{
private int doors;
private int mpg;
public Car(String autoMake, int autoCylinders, String autoTransmission, String autoColor, int carDoors,int carMPG )
{
super(autoMake, autoCylinders, autoTransmission, autoColor);
doors = carDoors;
mpg = carMPG;
}
public int getDoors()
{
return doors;
}
public int getMPG()
{
return mpg;
}
{
super.getMake();
super.getCylinders();
super.getTransmission();
super.getColor();
}
String printCar()
{
return("A "+ getColor()+", "+ getTransmission()+ ", "+" v"+getCylinders()+ getMake()+" car with"+ getDoors()+ " doors getting \n"+ getMPG()+" MPG");
}
}
class autotest
{
public static void main(String s[])throws java.io.IOException {
InputStreamReader istream = new InputStreamReader(System.in);
BufferedReader read = new BufferedReader(istream);
{
System.out.println(" Welcome to Greasy Gus’ Auto Inventory");
System.out.println("Let’s start by entering an automobile: \n What’s the make?");
String m1 = read.readLine();
System.out.println("How many cylinders?");
String Cy1 = read.readLine();
int cy1 = Integer.parseInt(Cy1);
System.out.println("What transmission?");
String t1 = read.readLine();
System.out.println("What color");
String co1 = read.readLine();
gcamposAuto a = new gcamposAuto(m1, cy1,t1,co1);
System.out.println("Okay, now enter a truck: \n What’s the make?");
String m2 = read.readLine();
System.out.println("How many cylinders?");
String Cy2 = read.readLine();
int cy2 = Integer.parseInt(Cy2);
System.out.println("What transmission?");
String t2 = read.readLine();
System.out.println("What color?");
String co2 = read.readLine();
System.out.println("How many pounds of towing capacity?");
String Tc = read.readLine();
int tc = Integer.parseInt(Tc);
System.out.println("How many inches of ground clearance?");
String Gc = read.readLine();
int gc = Integer.parseInt(Gc);
Truck t = new Truck(m2, cy2, t2, co2, tc, gc);
System.out.println("Finally, enter a car: \n What’s the make?");
String m3 = read.readLine();
System.out.println("How many cylinders?");
String Cy3 = read.readLine();
int cy3 = Integer.parseInt(Cy3);
System.out.println("What transmission?");
String t3 = read.readLine();
System.out.println("What color?");
String co3 = read.readLine();
System.out.println("How many doors?");
String D = read.readLine();
int d = Integer.parseInt(D);
System.out.println("How many MPG?");
String Mpg3 = read.readLine();
int mpg3 = Integer.parseInt(Mpg3);
Car c = new Car(m3, cy3, t3, co3, d, mpg3);
System.out.println("Alright, Greasy Gus is selling the following vehicles you’ve entered:");
System.out.println(a.printAuto());
System.out.println(t.printTruck());
System.out.println(c.printCar());
}
}
}
Thanks for the help.
- 03-15-2011, 06:53 AM #2
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
HI
your code seems to be fine and is running so where is the problem.
instead of using{
super.getMake();
super.getCylinders();
super.getTransmission();
super.getColor();
}
this why dont you use syntax
String printCar()
{
return("A "+ super.getColor()+", "+ super.getTransmission()+ ", "+" v"+super.getCylinders()+ super.getMake()+" car with"+ getDoors()+ " doors getting \n"+ getMPG()+"
MPG");
}
if there is any specific reason please tell me what is its purpose
- 03-15-2011, 07:33 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
Field definition for extending classes Question.
By MadJack in forum New To JavaReplies: 11Last Post: 11-12-2010, 06:52 PM -
Extending Classes and What is Necessary
By GavinCash in forum New To JavaReplies: 10Last Post: 10-11-2010, 07:07 AM -
Got confused with extending classes.
By nethz13 in forum New To JavaReplies: 7Last Post: 04-19-2010, 12:19 AM -
OOP Question re. private variables and extending classes
By ImplicitCharm in forum New To JavaReplies: 7Last Post: 07-28-2009, 03:46 PM -
[SOLVED] Problem with extending classes...
By Bizmark in forum New To JavaReplies: 4Last Post: 04-07-2008, 11:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks