Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

You have the templates of 2 classes, StarbucksAccount.java and StarbucksDemo.java --- This only tests your StarbucksAccount.java class - use StarbucksDemo.java to test your code! The

image text in transcribedimage text in transcribedimage text in transcribedYou have the templates of 2 classes, StarbucksAccount.java and StarbucksDemo.java --- This only tests your StarbucksAccount.java class - use StarbucksDemo.java to test your code! The StarbucksAccount class has attributes: firstName, lastName, membershipID, funds, and hasReward. There is a constructor for the class that is used to make StarbucksAccount objects - look at it to see how it works. The StarbucksDemo class has a main method that creates and initializes a sample StarbucksAccount object. Your tasks are described below. Each task is a separate test case, listed in the order you should complete the tasks. Note - task 1 is required as it is used in several of the subsequent test cases. Your task is as follows: Within StarbucksAccount.java: Read through the description and existing code to become familiar with the class setup and your tasks. Write an accessor method for the funds attribute. You must use proper naming convention for the method to receive credit Write an accessor method for the hasReward attribute: * This method should be named hasReward() Write a method called printAccountInfo that prints out the information in the format below: * Pay close attention to the last line of output. * The example below is the output for the joesAccount object created for you in StarbucksDemo.java Name: Joe King Membership ID: 98765432 Available funds: $10.0 Does not have a reward. * If joesAccount had a reward (hasReward evaluated to true), the following should be printed: Name: Joe King Membership ID: 98765432 Available funds: $10.0 Has a reward. Write a method called addFunds that accepts a double parameter to increase the funds by. Starbucks only allows users to increase their funds by 10.00, 20.00, or 50.00 dollars. * Note - this method stub is provided for you, complete the code so that it works as follows: Increase the current funds by the requested amount only when the deposit amount is one of the allowed values specified above. otherwise - print the following error: "Invalid deposit amount." Write a method called makePurchase that accepts a double purchaseAmount * Note - this method stub is provided for you, complete the code so that it works as follows: * Ensure that purchaseAmount is a positive number, otherwise print the error: "Purchase amount must be greater than 0." If purchase amount is valid, deduct that amount from your funds only when there are enough funds to cover the purchaseAmount - funds should never be negative (but could be 0). Otherwise - print the following error message: "Purchase amount exceeds funds." Write a method called generateUsername that accepts no parameters and returns a username (String) in the following format: * first letter of the first name (lowercase) * first three letters of the last name (lowercase) * and last three digits of the membershipID Example1: firstName is Joe, lastName is King, membershipID is 98765432. This method would return: jkin432 Example2: firstName is Bill, lastName is Bob, membershipID is 58991 This method would return: bbob991 You can assume firstName, lastName, and membershipID will have lengths of at least 3. (Hint: charAt returns a char - you can't store it directly in a String (but you can concat it to one!) (Hint2: There is a toLowerCase method in both the String and Character class) Work in StarbucksDemo.java Create a new StarbucksAccount object named jbond with the following attributes: Name - James Bond (Bond is last name) membershipID - 007 Initial funds - 7.00 Comment out all of your previous code in StarbucksDemo.java. Uncomment the code that prints a menu of options to the user. Read in the user's selection (1-4). (hint - don't forget to import Scanner) Based on the user's input, do one of the following: 1 - call your printAccountInfo method for the jbond object 2 - call the generateUsername method for your jbond object and print the result. 3 - Prompt the user to enter how much they want to deposit, read their input and call the addFunds method with this amount. hint: you can pass any any double value - but only some will be valid in your method definition. Then print the funds by calling the getFunds method. 4 - Prompt the user to enter how much the purchase costs, read their input and call the makePurchase method with this amount. (hint: 10.25 and 7.99 should both be accepted values). Then print the funds by calling the getFunds method. If the user enters anything other than 1-4, print: "Please enter an option between 1-5."

/x * 6. Write a method called generateUsername that accepts no parameters and returns a username in the following format: * first letter of the first name (lowercase) * first three letters of the last name (lowercase), * and last three digits of the membershipID * Example1: firstName is Joe, lastName is King, membershipID is 98765432. This method would return: jkin 432 * Example2: firstName is Bill, lastlame is Bob, membershipID is 58991 This method would return: bbob991 * You can assume firstName, lastName, and membershipID will have lengths of at least 3. * (Hint: charAt returns a char - you can't store it directly in a String!) * (Hint2: The String class has a toLowerCase method!) / \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions