-3
我必須將-1替換爲將評估爲新購物者ID號的適當整數值的值。如何在方法內創建一個自動遞增的ID
import java.util.Scanner;
public class MethodHolder {
private static int nextShopperID = 100;
private static int nextProductID = 100;
protected static Shopper generateShopper(){
Scanner scan = new Scanner(System.in);
String name = null;
double balance = 0.0;
int productLimit = 0;
System.out.println("Please enter the shoppers name: ");
name = scan.next();
System.out.println("Please enter the shoppers balance: ");
balance = scan.nextDouble();
System.out.println("Please enter the shoppers product limit: ");
productLimit = scan.nextInt();
// replace -1 with the appropriate increment expression
return new Shopper(-1, name, balance, productLimit);
}
這是什麼問題? – ergonaut
你知道'if'語句是什麼嗎?順便說一句:[爲我的Java類生成唯一的int ID](http://stackoverflow.com/q/32639692) – Tom
這是什麼'nextShopperID'打算是什麼?這可能與你的問題有關嗎? – zapl