【问题标题】:Java Credit Account errorJava 信用帐户错误
【发布时间】:2017-08-23 17:00:50
【问题描述】:

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

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;

}



}

【问题讨论】:

  • 变量名不要以大写开头...
  • CreditCardAcct 类中的 CreditCardAcct.purchase() 方法在哪里?但是,我确实看到了 CreditCardAcct.setPurchase() 方法和 CreditCardAcct.getPurchase() 方法。

标签: java jcreator


【解决方案1】:

据我所知,您似乎没有启动 randNum 类...

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

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

希望这会有所帮助!

【讨论】:

  • 非常有帮助。谢谢
猜你喜欢
  • 2016-08-15
  • 2013-10-21
  • 1970-01-01
  • 2016-02-01
  • 2022-01-15
  • 1970-01-01
  • 2016-09-22
  • 2011-11-06
  • 1970-01-01
相关资源
最近更新 更多