Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2008, 07:05 PM
Member
 
Join Date: Dec 2008
Posts: 2
Rep Power: 0
jackhammer is on a distinguished road
Exclamation Help With Project!!!
Hi everyone,

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

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!!!!!!
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-03-2008, 07:17 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 486
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
And what is your question or problem in it?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 07:20 PM
Member
 
Join Date: Dec 2008
Posts: 2
Rep Power: 0
jackhammer is on a distinguished road
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!!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2008, 07:46 PM
Senior Member
 
Join Date: Aug 2008
Posts: 374
Rep Power: 2
Supamagier is on a distinguished road
Default
Use this after the prices are given...

Code:
totalPrice = carValue + gasPrice + transmissionPrice + enginePrice;
Instead of before.
__________________
I die a little on the inside...
Every time I get shot.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-04-2008, 05:45 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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!!
Can you post your error message and ask your question more clearly?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-04-2008, 06:10 AM
Member
 
Join Date: Dec 2008
Posts: 41
Rep Power: 0
timkd127 is on a distinguished road
Smile
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Project Help XxHEXSORxX AWT / Swing 4 01-28-2009 11:01 AM
Need Help With Project maggie_2 New To Java 1 12-02-2008 09:24 AM
jsp project help rajibmp New To Java 4 10-10-2008 01:50 AM
Converting an existing project to an EclipseME project JavaForums Java Blogs 0 06-23-2008 10:41 AM
First Project Need Big Help earl New To Java 1 01-18-2008 07:12 PM


All times are GMT +2. The time now is 03:13 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org