Reply
Old February 20th, 2006 Top | #1
 
Scott Young's Avatar
Real picture of me
Joined: September 2004
Posts: 97
Reputation: 40
Power: 123

Default Simple Java for statement problem

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);


}
}



Scott Young is offline   Reply With Quote
Old February 20th, 2006 Top | #2
 
apu95's Avatar
Caffeine-->Code Converter
Joined: April 2002
Location: Montreal, Canada
Posts: 502
Reputation: 60
Power: 156

Default Re: Simple Java for statement problem

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


Telepathic: Q6600, 4 GB, HD3650, Audigy, Win7 64

Phantom: P4 3.0 800 FSB, D865GBFL, 512 DDR400, Radeon 9200 128, SB Live 5.1, WD 80gb, 16x DVD, Samsung SW-204B 40x24x40 CD-RW

Psychic: ASUS M50SV: Core 2 Duo T8100, 3GB DDR2, nVidia 9500GS, 250GB (Win7), BluRay, 802.11b/g/n
apu95 is offline   Reply With Quote
Old February 20th, 2006 Top | #3
 
Scott Young's Avatar
Real picture of me
Joined: September 2004
Posts: 97
Reputation: 40
Power: 123

Default Re: Simple Java for statement problem

thanks very much, compiles fine now!



Scott Young is offline   Reply With Quote
Old February 21st, 2006 Top | #4

OSNN Folding Team  
Geffy's Avatar
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 245

Default Re: Simple Java for statement problem

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()



blog tumblog lastfm flickr #rubyonrails @twitter
"I could be replaced with a very small shell script"
Geffy is offline   Reply With Quote

Reply

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
java problem perris Windows Desktop Systems 4 November 5th, 2007 7:16pm
MySQL Arbitarary string prefix in select statement LordOfLA Web Design & Coding 4 May 1st, 2006 1:01pm
Privacy Statement Electronic Punk News & Information 0 March 20th, 2004 3:27am
Java Problem Shooter1973 Web Design & Coding 8 March 13th, 2003 5:25pm
simple problem...just need a solution ryan3dfan Windows Desktop Systems 12 June 12th, 2002 3:51am