Question: You will need to complete the constructor and write three methods: getUserBalance, addToUserBalance, and purchaseTShirts. The details for each of these methods are listed extensively
You will need to complete the constructor and write three methods: getUserBalance, addToUserBalance, and purchaseTShirts. The details for each of these methods are listed extensively in the starter code.
1 public class ShoppingCenter{ 2 3 /**This is the instance variable we will use to store the user's balance. It is 4 the only instance variable we will need. 5 **/ 6 private double userBalance; 7 8 /**This is the constructor. We will need to give the initial balance to the user. 9 We're running a special promotion where new users start with $100 of store credit. 10 **/ 11 public ShoppingCenter(){ 12 } 13 14 /**In this method we will return the balance of the user. This method takes no parameters 15 and returns a double representing the balance of the user. 16 **/ 17 public double getUserBalance(){ 18 return -1; 19 } 20 21 /**In this method we handle the case where the user wants to deposit money into their account. 22 We take in the value they want to add as the double amountToAdd and return a boolean value 23 signifying if the deposit was successful or not. We want to make sure that amountToAdd is 24 greater than zero. If it is, we want to add the value to the account and return true. However 25 if it is not, we don't want to do anything and instead return false. 26 **/ 27 public boolean addToUserBalance(double amountToAdd){ 28 return false; 29 } 30 31 /**This method allows the user to purchase T-Shirts. It takes two parameters: amount, which represents 32 the number of T-shirts being purchased; and size, which represents the size of the shirts being purchased. 33 The prices for T-Shirts are as follows: 34 smalls (represented by the character 's' or 'S'): $10 each 35 medium (represented by the character 'm' or 'M'): $20 each 36 larges (represented by the character 'l' or 'L'): $24 each 37 Before allowing the purchase to go through, make sure it is a valid purchase first. Purchases can be invalid 38 for a number of reasons. If the user does not have enough money, it is invalid. If the size character is invalid, 39 the purchase is invalid. If they try to buy zero or a negative number of shirts, it is invalid. 40 41 If a purchase is invalid, we will return false so that the error message can be shown by the main method. Otherwise 42 we will subtract the cost from the user's balance and return true to signify that it is a valid purchase. 43 **/ 44 public boolean purchaseTShirts(int numTShirts, char size){ 45 return false;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
