Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public static void create() { in = new Scanner(System.in); dateAndTime = getDateAndTime(); shopLocation = getShopLocationFromUser(); staffName = getFromUser(your first name); staffName = capitalise(staffName); //end of

public static void create() { in = new Scanner(System.in); dateAndTime = getDateAndTime(); shopLocation = getShopLocationFromUser(); staffName = getFromUser("your first name"); staffName = capitalise(staffName);

//end of code

Note that in the create() method the class invokes a method written to make sure that the name entered by the user is capitalised appropriately: staffName = capitalise(staffName);. The capitalise(String) method takes a String parameter and returns a String. The method makes sure that the name entered by the user starts with a capital letter, with the rest of the name in lower case. Note that the capitalise(String) method uses String methods, such as substring() and toUpperCase() that you will find documented in the String API.

There is a TODO comment in the create() method that reads: //TODO client wants the item description in title case Different authorities have slightly different rules for title case, but title case means, in general, that every word is capitalised (meaning the word starts with a capital letter, but the rest of the word is in lower case), except for articles (a, an, the), prepositions (e.g. in, on) and conjunctions (e.g. and, or). In this case the client wants every word capitalised except for the words: a; an; and; the; of; with. This means that if the user were to type: REPLACE BATTTERY WITH A NEW BATTERY for the item description, what would be printed on the receipt would be: Replace Battery with a New Battery

itemisedCosts = ""; numberOfItemsPurchased = 0; subtotal = 0; boolean keepGoing = true; //loop so that the user can enter as many items as they need to while (keepGoing) { //ask user to enter information about item and charges String itemDescription = getFromUser("Item or service user is being charged for"); //TODO client wants the item description in title case double unitPrice = getDoubleFromUser("the unit price (without VAT) of " + itemDescription); int numberOfUnits = getIntFromUser("the number of " + itemDescription); //TODO make above statements a method

//update receipt information with item and charges for item itemisedCosts += addItemisedCostToReceipt(itemDescription, unitPrice, numberOfUnits); subtotal += (unitPrice * numberOfUnits); numberOfItemsPurchased += numberOfUnits; //TODO make above three statements a method

//add more items to the receipt? String more = getFromUser("another item or service? Yes/No"); if (more.trim().toLowerCase().startsWith("n")) { keepGoing = false; } //TODO make asking the user if they wish to add more items into a method }//end of while loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is one major advantage of having a blood-brain barrier?

Answered: 1 week ago