please tell me what mistakes I made here for writing methods, it fails when I te
ID: 3757232 • Letter: P
Question
please tell me what mistakes I made here for writing methods, it fails when I tested it
elp /* This class models a user's account The class keeps track of the user 's current balance, number of items purchased, and the total monetary amount purchased. TODO: implement all of the methods in this class definition. public class UserAccount String userName; double balance,; int numPurchases; double totalPurchaseAmt / Constructor that initializes this account with a user name and an initial balance that is passed in. It also initializes the number of purchases made to e, and the total monetary amount of all purchases to e.e. public UserAccount (String userName, double initBal) f /* Returns the user's name. public String getUserName() return userName; 9Returns the user's balance. 1 public double getBalance) ( return balance; 4 5 6 /* Returns the number of purchases made. 7 public int getNumPurchases() f 38 39 40 41 return numPurchases; /* Returns the total monetary amount of all purchases. AccountManagerjavavl UserAccountTestjava Compile MessagesjGRASP Messages Run I/O Interactions UserAccount.java UserAccountTest.java Stop Clear CopyExplanation / Answer
The mistake is in the constructor of your class
The constructor of your class takes in two parameters (String userName,double initBal)
both there are no statements inside the constructor body to make use of the parameters that were passed.
So make sure when you create the object do pass a String as name and a double as initial balance.
The correction would be:
Change the constructor as follows:
public UserAccount(String userName,double initBal)
{
this.userName=userName;
this.balance=initBal;
}
Create the object as follows:
UserAccount ua=new UserAccount("Your_name",200.00);
ua-is the name given for the object by me you can use any name of your choice.
balance-is given as 200.00 you can give any amount
and any name in the place of Your_name.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.