iam new finding an error in java
package ooptutorial;
public class ShoppingTest {
//name of file must be same as name of method
public static void main(String[] args) {
Shopping firstClient = new Shopping();
int[] pricelist = {299,399,499};
for (int i = 0; i < pricelist.length; i++){
firstClient.Basket(pric开发者_开发技巧elist[i]);
}
System.out.println("The Total Price of your Item is : "
+ firstClient.r);
System.out.println("The Total Price with VAT : "
+ firstClient.TotalPrice());
firstClient.DailyIncome(firstClient.TotalPrice());
Shopping secondClient = new Shopping();
int[] pricelist2 = {599,159,459};
for(int i = 0; pricelist2.length; i++){
secondClient.Basket(pricelist2[i]);
}
System.out.println("The Total Price of your Item is : "
+ secondClient.r);
System.out.println("The Total Price with VAT : "
+ secondClient.TotalPrice());
secondClent.DailyIncome(secondClient.TotalPrice());
System.out.println("The Daily Income : "
+ secondClient._dailyIncome);
}
}
[ed: artificial break added]
class Shopping{
int r = 0;
final int VAT_VALUE = 17;
static int DailyIncome = 0;
int Basket(int ItemPrice){
r = ItemPrice;
return r;
}
int TotalPrice(){
return ((r * VAT_VALUE) / 100) + r;
}
public static int DailyIncome(int income){
_dailyIncome += income;
return _dailyIncome;
}
}
You have an error on this line:
for(int i = 0; pricelist2.length; i++){
Because pricelist2.length
is an int
, not a boolean
as required by Java syntax. Perhaps you meant:
for(int i = 0; i < pricelist2.length; i++){
精彩评论