Assignment Report (1)
Assignment Report (1)
import java.util.InputMismatchException;
import java.util.Scanner;
{"Main Dishes", "Pad Thai", "Stir-fried rice noodles with shrimp, tofu,
peanuts, and bean sprouts.", "12.00"},
{"Fried Rice", "Thai Fried Rice", "Fried rice with chicken, shrimp, or
vegetables, seasoned with Thai spices.", "11.00"},
};
while (ordering) {
if (option == 2) {
} else if (option == 1) {
// Display categories
while (continueOrdering) {
System.out.println("Categories:");
System.out.println("1. Appetisers");
switch (categoryChoice) {
default:
System.out.println("Invalid category.");
continue;
System.out.println("..........................................................................................
.........................................");
int dishNumber = 1;
if (menu[i][0].equals(selectedCategory)) {
dishNumber = 1;
if (menu[i][0].equals(selectedCategory)) {
if (dishNumber == dishChoice) {
selectedDishIndex = i;
break;
dishNumber++;
if (selectedDishIndex == -1) {
System.out.println("Invalid dish selection.");
double dishPrice =
Double.parseDouble(menu[selectedDishIndex][3]);
totalBill += subtotal;
if (continueResponse.equalsIgnoreCase("no")) {
continueOrdering = false;
if (totalBill > 0) {
System.out.println("\nINVOICE:");
System.out.println(".....................................................");
System.out.println(invoice.toString());
System.out.printf("%-20s %-10s $%-10.2f\n", "Total Bill", "", totalBill);
} else {
scanner.close();
while (!valid) {
System.out.print(prompt);
if (scanner.hasNextInt()) {
input = scanner.nextInt();
valid = true;
} else {
return input;
}
2. Screenshots
a) Giving two options to user when system is open which is Show Menu and Exit.
b) If user choose option 2 which is exit then output will be shown as below
c) If user choose option 1 which is Show Menu
d) If user choose one of the category suppose user choose appetisers then output shows like
below
3. Step-by-Step Explanation
User Prompt:
Initially, the program will display the option of either showing the menu or exiting the program.
Menu Categories:
When the user selects "Show Menu," the program displays the available categories: Appetisers,
Main dishes and Fried rice.
Dish Selection:
Within the selected category, the dishes are numbered. There are meal options for the user to
choose from, and the user selects a dish by choosing the number of the dish.
Order Processing:
If the user chooses a particular dish, they are asked to input the number of portions they want for
that specific dish. The program checks such an input to guarantee that it is positive.
Invoice Generation:
This means that after the user is through with ordering, the program provides an invoice for all
the ordered items, the quantity of each item, and the subtotal. The net amount of the bill is also
shown.
Task 2: Calculator
1. Java Code
//Calculator.java
Import java.util.Scanner;
// Input for annual interest rate, starting balance, and number of months
account.deposit(depositAmount);
account.withdraw(withdrawalAmount);
account.addMonthlyInterest();
scanner.close();
}
// File: SavingsAccount.java
this.balance = startingBalance;
this.annualInterestRate = annualInterestRate;
this.totalDeposits = 0;
this.totalWithdrawals = 0;
this.totalInterestEarned = 0;
balance += amount;
totalDeposits += amount;
}
// Method to withdraw amount from the account
balance -= amount;
totalWithdrawals += amount;
balance += monthlyInterest;
totalInterestEarned += monthlyInterest;
// Getter methods
return balance;
return totalDeposits;
}
public double getTotalWithdrawals() {
return totalWithdrawals;
return totalInterestEarned;
}
2. ScreenShots
Sample output
3. Step-by-step Explanation
User Input:
This involves the user inputting the annual interest rate, the starting balance, and the number of
months.
Monthly Transactions:
For each month, the user enters the deposit/withdrawal amount. With the present program, the
account balance may be updated, and the monthly interest may be applied.
Interest Calculation:
Monthly interest is calculated using the formula: Monthly interest is calculated using the
formula:
4.
Task 2: Calculator
1. User Input:
o The program collects the annual interest rate, starting balance, and number of
months from the user.
2. Monthly Transactions:
o For each month, the user inputs deposit and withdrawal amounts. The program
updates the account balance and applies monthly interest.
3. Interest Calculation:
o Monthly interest is calculated using the formula:
Monthly Interest=Current Balance×(Annual Interest Rate12×100)\text{Monthly
Interest} = \text{Current Balance} \times \left(\frac{\text{Annual Interest Rate}}
{12 \times 100}\
right)Monthly Interest=Current Balance×(12×100Annual Interest Rate)
4. Results Display:
o The final balance, total deposits, total withdrawals, and total interest earned are
displayed to the user.