View Single Post
  #1 (permalink)  
Old 04-09-2008, 01:07 AM
Minime Minime is offline
Member
 
Join Date: Apr 2008
Posts: 1
Minime is on a distinguished road
Help with constructors
I can't get the Car constructor to work it says I need a ; after the car() in the code here it is:
import java.text.DecimalFormat;
import java.io.*;

public class Car {
public static void main(String args[]) {
String Color = "",
Make = "",
Model = "";
int year = 0;
double invoice;
double price;
double getProfit;
double X;

//void showCar()

Car carA = new Car();
Car(){
Make = "Ford";
Model = "Escort";
year = 1997;
invoice = 10500;
price = 14500;
Color = "blue";
}



BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(System.in));
String inputValue;

DecimalFormat number2Digits = new DecimalFormat ("0");


try
{

//Input
System.out.print("Please enter Car Color: ");
Color = reader.readLine();

System.out.print("Please enter Car Make: ");
Make = reader.readLine();

System.out.print("Please enter Car Model: ");
Model = reader.readLine();

System.out.print("Please enter year of Car: ");
inputValue = reader.readLine();
year = Integer.parseInt(inputValue);

System.out.print("Please enter Invoice Price: ");
inputValue = reader.readLine();
invoice = Double.parseDouble(inputValue);

System.out.print("Please enter Actuall Price: ");
inputValue = reader.readLine();
price = Double.parseDouble(inputValue);



//Processing
{
X = invoice - price;
}

//Output
System.out.println("\t CarA");
System.out.println("Car Color: " + Color); //Print Color
System.out.println("Car Make: " + Make); //Print Make
System.out.println("Car Model: " + Model);//Print Model
System.out.println("Year: " + number2Digits.format(year));//Print year
System.out.println("Invoice Price: " + number2Digits.format(invoice));//Print invoice
System.out.println("Actuall Price: " + number2Digits.format(price));//Print price
System.out.println("Profit =" + number2Digits.format(X));//Print difference


}
catch (Exception e)
{
System.out.println("Exception occurred");
}

}


}
Reply With Quote
Sponsored Links