Java 如何在方法中创建自动递增的id

Java 如何在方法中创建自动递增的id,java,Java,我必须将-1替换为新购物者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 Scanne

我必须将-1替换为新购物者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); 
    }

尝试传入nextShopperID并递增它

return new Shopper(nextShopperID++, name, balance, productLimit);

问题是什么?你知道什么是
if
语句吗?顺便问一下:下一个shopperid的目标是什么?这可能与你的问题有关吗?