Java Credit Account错误

时间:2017-03-30 00:36:19

标签: java jcreator

我在编写这段短代码时遇到错误,如果你帮我解决它会很有帮助。

import java.util.*;

class DriverProgram {

public static void main(String[] args) {

      //Create objects of the class

    CreditCardAcct fatherCredit = new CreditCardAcct("Father","121215");

    CreditCardAcct SonCredit = new CreditCardAcct("Son","656565");

      //loop to perform 10 purchases

    for(int vi=0; vi<=10; vi++){

        double valueRandom =(Math.random()*1100);

        System.out.println("Father purchase"+valueRandom);

        fatherCredit.purchase(valueRandom);

        valueRandom = (Math.random()*1000);

        System.out.println("Son Purchase: "+valueRandom);

        SonCredit.purchase(valueRandom);

    }

}

}

这两行发生错误

             fatherCredit.purchase(valueRandom);
             SonCredit.purchase(valueRandom);

这两个错误都找不到符号。

我知道这个错误并不是很难解决,但我不知道我有这个错误的原因。

谢谢大家,祝你有个美好的一天!

这是我的CreditCardAcct类代码:

 import java.util.*;

 //class CreditcardAcct definition

 class CreditCardAcct {

 //instance variables

String cardHolderName;

String cardNumber;

 //arraylist to store the Listpurchase

ArrayList<Double> Listpurchase;

 //static instance variables of the class

static final double overallAccountLimit = 10000;

static double overallAccountBalance = 10000;

 //Class constructor to initialize the variables

public CreditCardAcct(String ParametercardHolderName, String ParametercardNumber) {

    this.cardHolderName = ParametercardHolderName;

    this.cardNumber = ParametercardNumber;

    this.Listpurchase = new ArrayList<Double>();

}

public void Updatecredit(Double Inputamount){

      //if condition to update the account balance

    if(Inputamount <= overallAccountBalance) {

        overallAccountBalance = overallAccountBalance - Inputamount;

        Listpurchase.add(Inputamount);

        System.out.println("Updated the Purchase!");

        System.out.println("Credit balance: "+(overallAccountBalance));

    }else {

        System.out.println("Insufficient Credit amount, Purchase failed");

    }

}

 //Accessors and mutators of the class

 //To get the Name

public String getCardHolderName() {

    return cardHolderName;

}

 //To get the card number

public void setCardNumber(String ParametercardNumber) {

    this.cardNumber = ParametercardNumber;

}



 //To set the name

public void setCardHolderName(String ParametercardHolderName) {

    this.cardHolderName = ParametercardHolderName;

}

 //To get the purchASE LIST

public ArrayList<Double> getPurchase() {

    return Listpurchase;

}



 //to set the purchase

 public void setPurchase(ArrayList<Double> Listpurchase) {

    this.Listpurchase = Listpurchase;

}



 //To get the card number

public String getCardNumber() {

    return cardNumber;

}



}

1 个答案:

答案 0 :(得分:0)

从我看到的情况来看,你似乎没有启动randNum类......

随机randNum = new Random(); num = randNum.nextInt(x); 试试这种随机的风格...

这是我一直使用的,我没有任何问题。

希望这有帮助!