고객 및 거래라는 두 가지 클래스가 있습니다. 고객을 거래로 확장하려고 할 때 오류가 발생합니다. 누구든지 도와 줄 수 있습니까? 이 당신은 Customer
생성자의 동일한 매개 변수 Transactions
클래스의 생성자를 정의해야 하나, 또는 Customer
클래스에 매개 변수가없는 생성자를 추가해야 내 코드클래스의 생성자를 지정된 유형에 적용 할 수 없습니다.
public class Customer{
public String name;
public String surname;
public int id;
public int ban;
public double balance;
public Customer(String pName, String pSurname, int pId, int pBan, double pBalance)
{
name = pName;
surname = pSurname;
id = pId;
ban = pBan;
balance = pBalance;
}
}
public class Transactions extends Customer{
public double Deposit(){
double deposit = Double.parseDouble(JOptionPane.showInputDialog("How much would you like to deposit?"));
balance = balance + deposit;
JOptionPane.showMessageDialog(null,"Transaction complete. Your new balance is " + balance,"Transaction Complete", JOptionPane.PLAIN_MESSAGE);
return balance;
}
public double Withdraw(){
double withdraw = Double.parseDouble(JOptionPane.showInputDialog("How much would you like to withdraw?"));
if(balance >= withdraw){
balance = balance - withdraw;
JOptionPane.showMessageDialog(null,"Transaction complete. Your new balance is " + balance,"Transaction Complete", JOptionPane.PLAIN_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"Error. You were trying to withdraw more than you have in your account.","ERROR", JOptionPane.ERROR_MESSAGE);
}
return balance;
}
public void checkBalance(){
JOptionPane.showMessageDialog(null, "Name: " + name + " " + surname + "\nID: " + id + "\nBAN: " + ban + "\nBalance: " + balance);
}
코드 제대로 포맷. 어떤 오류가 발생하고 있습니까? 너 뭐 해봤 니? – Taylor
고객 클래스의 생성자 고객은 주어진 유형에 적용 할 수 없습니다. –
Transactions에는 생성자가없고 일부 인수가있는 생성자가있는 Customer 클래스를 확장하는 것처럼 보입니다. 따라서 Transactions에 대한 생성자를 추가하고 Customer 생성자를 호출하십시오. – Bharath