Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.*; import java.text.DecimalFormat; import java.util.Calendar; p

ID: 3529701 • Letter: I

Question

import java.util.*; import java.text.DecimalFormat; import java.util.Calendar; public class CashForMetalsClient { static Scanner scan = new Scanner(System.in); static Customer generalC = new Customer(); static Customer genPC = new PersonalCustomer(); static PersonalCustomer p1 = (PersonalCustomer) genPC; static Customer genCC = new CommercialCustomer(); static CommercialCustomer cc1 = (CommercialCustomer) genCC; static Transaction generalT = new Transaction(); static Account acct = new Account(); public static int displayMenuAndGetInput() { int inputInt = -1; Scanner input = new Scanner(System.in); // Menu Display System.out.println("*** ***"); System.out.println("*** Welcome to Cash for Metals Calculator!!! ***"); System.out.println("*** ***"); System.out.println(" 1. Create Personal Customer"); System.out.println(" 2. Create Commercial Customer"); System.out.println(" 3. Record Transaction"); System.out.println(" 4. Make Withdrawal"); System.out.println(" 5. Display Customer"); System.out.println(" 6. Display Customer Summary"); System.out.println(" 7. Display Grand Summary"); System.out.println(" 8. Exit"); System.out.println(""); // Get the input from the user System.out.print("Please input your choice (1-8): "); // Check for valid user input inputInt = input.nextInt(); return inputInt; } // Create a new PersonalCustomer public static Customer createPersonalCustomer() { System.out.println(" Enter the customer name > "); generalC.customerName = scan.nextLine(); System.out.println(" Enter the customer address > "); generalC.address = scan.nextLine(); System.out.println(" Enter the customer home phone > "); p1.hPhone = scan.nextLine(); System.out.println(" Enter the customer work phone > "); p1.wPhone = scan.nextLine(); return generalC [[ I want to be able to return generalC, p1, and acct]], how do I do that??? } // Create a new CommercialCustomer public static Customer createCommercialCustomer() { System.out.println(" Enter the customer name > "); generalC.customerName = scan.nextLine(); System.out.println(" Enter the customer address > "); generalC.address = scan.nextLine(); System.out.println(" Enter the customer contact person > "); cc1.contactPerson = scan.nextLine(); System.out.println(" Enter the customer contact person Phone > "); cc1.contactPhone = scan.nextLine(); return createCommercialCustomer(); } // Create a new Transaction public static Transaction recordTransaction() { System.out.println(" Enter the customer ID to create the transaction > "); generalC.customerID = scan.nextLong(); System.out.println(" Enter the weight of gold > "); generalT.goldWt = scan.nextDouble(); System.out.println(" Enter the weight of platinum > "); generalT.platWt = scan.nextDouble(); System.out.println(" Enter the weight of silver > "); generalT.silvWt = scan.nextDouble(); System.out.println(" Transaction ID: " + acct.getUniqueID()); System.out.println(" Gold Weight: " + (twoDecimalFormat.format(generalT.getGoldWt()))); System.out.println(" Platinum Weight: " + (twoDecimalFormat.format(generalT.getPlatWt()))); System.out.println(" Silver Weight: " + (twoDecimalFormat.format(generalT.getSilvWt()))); System.out.printf(" Total Value: " + (moneyFormat.format(generalT.getTotal()))); System.out.println(); return null; } // Make a withdrawal public static double makeWithdrawal() { System.out.println(" Enter the customer ID to make a withdrawl > "); generalC.customerID = scan.nextLong(); System.out.println(" Enter the customer ID to make a withdrawl > "); acct.withdrawAmount = scan.nextDouble(); System.out.println(" Amount withdrawn from this account: "); return makeWithdrawal(); } // Display customer summary public static void displayCustomer() { System.out.println(" Enter the customer ID ot view a summary >"); generalC.customerID = scan.nextLong(); System.out.println(" Customer Name: " + generalC.getCustomerName()); System.out.println(" Customer ID: " + generalC.getCustomerID()); System.out.println(" Customer Address: " + generalC.getAddress()); System.out.println(" Account Number: " + acct.getUniqueID()); System.out.printf(" Balance: " + acct.getBalance()); System.out.println(" Interest Rate: "); System.out.println(" Date Opened: " + acct.getDate()); System.out.println(" Transaction ID: "); return; } // Display total customer summary public static void displayCustomerSummary() { System.out.println(" Total number of customers: " + generalC.getnumberOfClients()); System.out.println(" Total value of all accounts: " + (moneyFormat.format(generalT.getGrandTotal()))); System.out.println(); return; } // Display all customers, accounts and transactions public static void displayGrandSummary() { System.out.println(" Customer Name: " + generalC.getCustomerName()); System.out.println(" Customer ID: " + generalC.getCustomerID()); System.out.println(" Customer Address: " + generalC.getAddress()); System.out.println(" Account Number: " + acct.getUniqueID()); System.out.println(" Balance: " + acct.getBalance()); System.out.println(" Interest Rate: " ); System.out.println(" Date Opened: " + acct.getDate()); System.out.println(" Transaction ID: " ); System.out.printf(" Gold Weight: " + (twoDecimalFormat.format(generalT.getTGoldWt()))); System.out.printf(" Platinum Weight: " + (twoDecimalFormat.format(generalT.getTPlatWt()))); System.out.printf(" Silver Weight: " + (twoDecimalFormat.format(generalT.getTSilvWt()))); System.out.println(" Platinum Weight: " + (moneyFormat.format(generalT.getTotal()))); System.out.println(" Home Phone: " + p1.getHPhone()); System.out.println(" Work Phone: " + p1.getWPhone()); return; } // Helper method to determine if a customer exists public static Customer findCustomer(long customerID) { return null; } // Data structure to store customers private static ArrayList customers = new ArrayList(); static DecimalFormat moneyFormat = new DecimalFormat("$0.00"); static DecimalFormat percentFormat = new DecimalFormat("0.00"); static DecimalFormat twoDecimalFormat = new DecimalFormat("0.00"); //Returns a money-formatted String from a double public static String formatMoney(double money) { return moneyFormat.format(money); } //Returns a decimal formatted String from a double public static String formatTwoDecimals(double weight) { return twoDecimalFormat.format(weight); } public static void main(String[] args) { Customer customer; Transaction transaction; double withdrawalAmount = 0; boolean finished = false; while (finished == false) { // Menu Display and Get user input int inputInt = 0; while (inputInt == 0) { inputInt = displayMenuAndGetInput(); // if the input is out of range if ((inputInt < 1) || (inputInt > 8)) { System.out.println(" The input is out of range!"); System.out.println(); inputInt = 0; } } // end while // switch to correspondence function switch (inputInt) { case 1: customer = createPersonalCustomer(); System.out.println(" The Personal customer has been created: " + customer.toString()); customers.add(customer); System.out.println(); break; case 2: customer = createCommercialCustomer(); System.out.println(" The Commercial customer has been created: " + customer.toString()); customers.add(customer); break; case 3: transaction = recordTransaction(); if (transaction != null) System.out.println(" The Transaction has been created: " + transaction.toString()); else System.out.println(" The ID could not be found. "); break; case 4: withdrawalAmount = makeWithdrawal(); if (withdrawalAmount > 0) System.out.println(" Amount withdrawn from this account: " + moneyFormat.format(withdrawalAmount) + " "); else System.out.println(" The ID could not be found. "); break; case 5: displayCustomer(); break; case 6: displayCustomerSummary(); break; case 7: displayGrandSummary(); break; case 8: // exit finished = true; break; default: System.out.println("Invalid Input!"); System.out.println(""); break; } // end switch } // end while } }

Explanation / Answer

Since you already know how to turn Objects intot Strings, you should be aware that you can use parameters to do 'multiple returns' by passing in variables by Reference, or just make a method to call each specific parameter's toString and return the concant. String

e.g.

public String toString(classA a, classB b ){

String str=a.toString() + b.toString();

return str;

}