Results 1 to 3 of 3
  1. #1
    ziongio is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Unhappy 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.

  2. #2
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    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

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What errors are you getting? You need to help us help you, I can't read your mind and see what's wrong, please give us the errors(not paraphrased), copy them exactly.

    Also, wrap your code in code tage
    [code ]
    your code here
    [/code]

Similar Threads

  1. Field definition for extending classes Question.
    By MadJack in forum New To Java
    Replies: 11
    Last Post: 11-12-2010, 07:52 PM
  2. Extending Classes and What is Necessary
    By GavinCash in forum New To Java
    Replies: 10
    Last Post: 10-11-2010, 08:07 AM
  3. Got confused with extending classes.
    By nethz13 in forum New To Java
    Replies: 7
    Last Post: 04-19-2010, 01:19 AM
  4. OOP Question re. private variables and extending classes
    By ImplicitCharm in forum New To Java
    Replies: 7
    Last Post: 07-28-2009, 04:46 PM
  5. [SOLVED] Problem with extending classes...
    By Bizmark in forum New To Java
    Replies: 4
    Last Post: 04-08-2008, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •