Results 1 to 6 of 6
  1. #1
    jackhammer is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Exclamation Help With Project!!!

    Hi everyone,

    im screwed for java project for college and im wondering could anyone help me?
    its due for tomorrow!!:eek:

    can anyone correct this code for me and get it to do something please? Thanks

    class car_sales
    {

    String carName;
    String gas;
    String transmission;
    int engineSize;




    public car_sales (String carName, String gas, String transmission, int engineSize)
    {
    this.carName = carName;
    this.gas = gas;
    this.transmission = transmission;
    this.engineSize = engineSize;
    }

    String carName()
    {
    return carName;

    }

    String gas()
    {
    return gas;
    }

    String transmisson()
    {
    return transmission;
    }


    int engineSize()
    {
    return engineSize;
    }
    }

    AND

    import java.util.Scanner;

    class car_tax//name of class
    {
    int carName = 0;
    String gas = "";
    int transmission =0;
    int engineSize = 0;
    int carValue = 0;
    int gasPrice = 0;
    int transmissionPrice = 0;
    int enginePrice = 0;
    int totalPrice = carValue + gasPrice + transmissionPrice + enginePrice;



    public static void main(String args[])
    {


    System.out.println(" Welcome to Siobhán's Toyota Car Sales!!");
    System.out.println(" Please fill out the information about the car you would like, and it will give you the price.");
    Scanner scan = new Scanner(System.in);
    System.out.println("Please enter the type of car:");
    int carName = scan.nextInt();

    switch (carName) { //switch statement for the name of the car and to assign the values to each car
    case 1: System.out.println("Aygo");
    carValue = 11000;
    break;
    case 2: System.out.println("Yaris");
    carValue = 12000;
    break;
    case 3: System.out.println("Auris");
    carValue = 13000;
    break;
    case 4: System.out.println("Avensis");
    carValue = 14000;
    break;
    case 5: System.out.println("Verso");
    carValue = 15000;
    break;
    case 6: System.out.println("RAV4");
    carValue = 16000;
    break;
    default: System.out.println("Invalid Car.");break;
    }


    System.out.println("Please choose from either Petrol or Diesel:");
    String gas = scan.nextLine();
    if (gas = "Petrol" || "Diesel")// an if statement to assign values to the gas
    {
    gasPrice = 200;
    }
    else
    {
    gasPrice = 100;
    }


    System.out.println("Please inticate what transmission you want: Manual, Automatic, Semi-Automatic");
    int transmission = scan.nextInt();
    switch (transmisson) {
    case 1: System.out.println("Manual");
    transmissonPrice = 200;
    break;
    case 2: System.out.println("Automatic");
    transmissonPrice = 400;
    break;
    case 3: System.out.println("Semi-Automatic");
    transmissonPrice = 500;
    break;
    default: System.out.println("Invalid Transmission");
    break;
    }


    System.out.println("What size of an engine do you want? 1, 1.2, 1.4, or 2 litre");

    int engineSize = scan.nextInt();



    switch (engineSize) {
    case 1: System.out.println(1);
    enginePrice = 50;
    break;
    case 2: System.out.println(1.2);
    enginePrice = 100;
    break;
    case 3: System.out.println(1.4);
    enginePrice = 150;
    break;
    case 4: System.out.println(2);
    enginePrice = 200;
    break;
    default: System.out.println("Invalid Engine Size");
    break;
    }

    System.out.println("Your car is " + totalPrice);
    }
    }



    Any help appreciated!!!!!!

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    And what is your question or problem in it?

  3. #3
    jackhammer is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Exclamation

    its for a car sales business scenario where people can pick the model type, engine size etc...

    and then i want all the prices to add up at the end!! we're not suppose to use GUI!!

    the code i posted has errors but i cant figure them out!!:rolleyes:

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    Use this after the prices are given...

    Java Code:
    totalPrice = carValue + gasPrice + transmissionPrice + enginePrice;
    Instead of before.
    I die a little on the inside...
    Every time I get shot.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by jackhammer View Post
    its for a car sales business scenario where people can pick the model type, engine size etc...

    and then i want all the prices to add up at the end!! we're not suppose to use GUI!!

    the code i posted has errors but i cant figure them out!!:rolleyes:
    Can you post your error message and ask your question more clearly?

  6. #6
    timkd127 is offline Member
    Join Date
    Dec 2008
    Posts
    41
    Rep Power
    0

    Smile

    Java Code:
    System.out.println("What size of an engine do you want? 1, 1.2, 1.4, or 2 litre");
    
    int engineSize = scan.nextInt();
    
    
    
    switch (engineSize) {
    case 1: System.out.println(1);
    enginePrice = 50;
    break;
    case 2: System.out.println(1.2);
    enginePrice = 100;
    break;
    case 3: System.out.println(1.4);
    enginePrice = 150;
    break;
    case 4: System.out.println(2);
    enginePrice = 200;
    break;
    default: System.out.println("Invalid Engine Size");
    break;
    }
    
    System.out.println("Your car is " + totalPrice);
    }
    }
    in this set of statements you declared the engineSize variable as an int. but gave the user non whole number choices (1.2, 1.4) if u enter this the code is only going to read 1 and the first case statement will execute. changing the data type to float will fix that.

Similar Threads

  1. Project Help
    By XxHEXSORxX in forum AWT / Swing
    Replies: 4
    Last Post: 01-28-2009, 10:01 AM
  2. Need Help With Project
    By maggie_2 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 08:24 AM
  3. jsp project help
    By rajibmp in forum New To Java
    Replies: 4
    Last Post: 10-10-2008, 12:50 AM
  4. First Project Need Big Help
    By earl in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 06:12 PM

Posting Permissions

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