CODE public class ExpenseManager { public static void main(String args[]) { Stri
ID: 3604806 • Letter: C
Question
CODE
public class ExpenseManager {
public static void main(String args[]) {
String itemNames[] = { "Coffee", "Grocery", "Phone", "Tution", "Books",
"Rent" };
double grandTotal = 0;
double amount_frequency[][] = { { 0.0, 365 }, { 50.0, 52 },
{ 80.0, 12 }, { 6500.0, 2 }, { 400, 2 }, { 950, 12 } };
System.out.format("%-10s%10s%10s%10s%15s","Item","Frequency","Times","Amount","Annual Total");
System.out.println();
for (int i = 0; i < itemNames.length; i++) {
grandTotal = grandTotal + amount_frequency[i][0]
* amount_frequency[i][1];
outputInfo(itemNames[i],(int) amount_frequency[i][1],amount_frequency[i][0]);
}
System.out.format("Total %50s",grandTotal);
}
static String getLabel(int times) {
if (times == 365)
return "Daily";
else if (times == 52)
return "Weekly";
else if (times == 12)
return "Monthly";
else if (times == 2)
return "Semi-anually";
return "";
}
static void outputInfo(String item, int times, double amount) {
System.out.format("%-10s%10s%8s%10s%15s",item,getLabel(times),times,amount,times*amount);
System.out.println();
}
}
QUESTION
Describe the design choices and structure of the program: class, methods, variables, and other notable functions used (e.g., printf). Include a flowchart of the for–loop part of the main method. Also include a UML class diagram of the class using the notation adopted in this course.
Explanation / Answer
The program structures used are
class : EcpenseManager
Methods : main, outputinfo, System.out.format
Data:
2 dimensional array - amount frequency
1- D array - itemnames
Flowchart for the for loop is as follows:
start
|
V
-------> i < itemNames.length ---->No---->Display output(grandTotal)--->stop
| |
| |(Yes)
| |
| V
------ display info
UML class for ExpenseManager
ExpenseManager
main:void
getLabel():String
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.