Simple Java for statement problem

Scott Young

Real picture of me
Joined
7 Sep 2004
Messages
97
Im having a problem with some java code, wondering what is wrong with this for statemnt to stop it compiling?

class car{

String Model;
int enginecapacity, yearofmanufacture;
double PriceWhenNew;

public void readDetails(){

System.out.println("Please Enter the model:");
uuInOut.ReadString();
System.out.println("Please Enter the engine capacity:");
uuInOut.ReadInt();
System.out.println("Please Enter the year of manufacture:");
uuInOut.ReadInt();

System.out.println("Please Enter the price of the car when new:");
uuInOut.ReadInt();


}

private double roadTax(int enginecapacity){

if (enginecapacity<= 1200)
return 100;
else if ((enginecapacity > 1200) && (enginecapacity<= 2000))
return 150;
else
return 200;
}
private double currentValue(){

for (intYearofManufacture; Yearofmanufacture<=2006; Yearofmanufacture++){

PriceWhenNew - (PriceWhenNew*10/100);


}
}
 
I can help you I think :)
I need the whole source code though, so post (or attach) both the car source and the main source.
So I can know in advance, what's the compile error you're getting?

Edit: Nevermind what I posted, I found it I think.

for (intYearofManufacture; Yearofmanufacture<=2006; Yearofmanufacture++){

PriceWhenNew - (PriceWhenNew*10/100);
}


You forgot to declare the first int in the for. You typed in intYearofManufacture, but that doesn't mean anything. You have to initialize it: int yearofManufacture = SomeYear
 
you dont need to have an assignment in the first piece of the for, any statement will do

you might have needed something like

for (int yearmade = yearofmanufacture; yearmade <= 2006; yearmade++)

making a copy of yearofmanufacture and working with that in your function so that you dont start incrementing your class variable yearofmanufacture and thereby screwing up any future calls to currentValue()
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back