Reputation: 3
So I'm working on this program and I've created two classes, one class called CreditCard, the other called CreditCardTester.I'm using Eclipse IDE and I keep getting compiling errors such as "The method getBalance(double) in the type CreditCard is not applicable for the arguments ()". I'm not really sure on what I have to fix.
This is the first class called CreditCard:
public class CreditCard
{
private String accountNumber;
private double creditLimit;
private double balance;
public void CreditCard(String number, double limit)
{
accountNumber = number;
limit = creditLimit;
balance = 0;
}
public String getAccountNumber()
{
return accountNumber;
}
public double getCreditLimit()
{
return creditLimit;
}
public double getBalance(double theBalance)
{
return balance;
}
public double charge(double amount)
{
balance = balance + amount;
return balance;
}
This is the second class CreditCardTester:
public class CreditCardTester
{
public static void main(String[] args)
{
CreditCard card = CreditCard("1234-5678-9012-3456", 1000.00);
String formatString = "Credit Card [number = %s, bal = %.2f, limit = %.2f]\n";
System.out.printf(formatString, card.getAccountNumber(), card.getBalance(), card.getCreditLimit());
System.out.println("\nCharging $50.00 to credit card...\n");
card.charge(50.00);
System.out.printf(formatString, card.getAccountNumber(), card.getBalance(), card.getCreditLimit());
}
Upvotes: 0
Views: 164
Reputation: 21367
I think getBalance
should not accept an argument in your class definition.
Use this in your CreditCard
class:
public double getBalance()
{
return balance;
}
Upvotes: 0
Reputation: 178243
This is not a constructor, because you added void
, making it a normal method:
public void CreditCard(String number, double limit)
Remove void
:
public CreditCard(String number, double limit)
Also, one of the assignments in the method/constructor is backwards. You assigned the instance variable to the parameter.
limit = creditLimit;
Change it around:
creditLimit = limit;
You're missing "new" when creating a CreditCard
:
CreditCard card = CreditCard("1234-5678-9012-3456", 1000.00);
Try
CreditCard card = new CreditCard("1234-5678-9012-3456", 1000.00);
You have an unused parameter on the getBalance
method, and you call it without a parameter.
public double getBalance(double theBalance)
Remove it:
public double getBalance()
Upvotes: 1