Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me to write the code for those problems. My code is here, but I don't know how to do for rounding public int
Please help me to write the code for those problems.
My code is here, but I don't know how to do for rounding
public int roundDollars(String amountStr)
{
int result = 0;
amountStr = amountStr.replace(".","").replace("$","").replace(",","").trim();
//maybe round should be here?
result = Integer.parseInt(amountStr);
return result;
}
Also, please help me with other problems,15 and 16.
14THE ROUNDEDDoLLArs PROBLEM Write the method named roundDollars(). The method has one input, a String named amountStr which consists of a dollar-formatted amount, such as "$ 1,256.86". The returned value is an int representing the number of rounded "dollars" in the amount (1257) in the sample shown here. You will need to scrub, format and parse the input, then use arithmetic to determine how many quarters the amount contains. 15THE LINENUMBER PROBLEM Write the method named lineNumber(). The method has two parameters, an int named number and a String named text. Return a formatted string where number is right-justified in a field 5 characters wide, followed by a colon and space, followed by the text. For example: lineNumber (5, "Orange Coast College")* "5: Orange Coast College" 16THE LINEITEM PROBLEM Write the method named lineItem() that formats an item on a receipt. The method has two parameters, a String description and a double price. Return a formatted string where description is left-aligned in a column 15 wide and price is right-aligned in a column 10 wide with two decimals. Thousands should be separated by commas but there should be no dollar sign. For example: lineItem("Toaster", 24)"Toaster 24.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started