Program Requirements
Display Welcome message
DO
PRINT “1. Enter House Prices”
PRINT “2. Enter Avocado on Toast Price”
PRINT “3. Deposit Calculator”
PRINT “4. Exit System”
READ menuChoice
IF menuChoice==1 THEN
Read “Cheapest Price”, dblCheapest
Read “Chosen Price”, dblSelected
Read “Median Price”, dblMedian
ELSE IF menuChoice==2 THEN
READ “Avocados on Toast Price : “, avocadoPrice
ELSE IF menuChoice==3 THEN
PRINT “DEPOSIT SAVING CALCULATOR”
PRINT “You will need to NOT buy”
PRINT “dblCheapest*discount/avocadoPrice+” smashed avocados on toast to save $”+dblCheapest*discount+” deposit for the cheapest house”
PRINT “dblSelected*discount/avocadoPrice+” smashed avocados on toast to save $”+ dblSelected*discount+” deposit for the chosen house”
PRINT “dblMedian*discount/avocadoPrice+” smashed avocados on toast to save $”+ dblMedian*discount+” deposit at the median price”
READ “How many times a week do you purchase avocado on toast?”,numAcocadoPerWeek
ADD Current date to Number of Week
PRINT “If you stop buying avocado on toast starting from today and save the moneny instead,nyour deposit for a $”, futureDate
END IF
WHILE (menuChoice!=4)
PRINT “The House Deposit Calculator is now exiting
Section 2: Program Development
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class Assign1
{
public static Scanner readData=new Scanner(System.in);
public static void printStar(int count) //print the star which depends upon the count value
{
int i;
for(i=1;i<=count;i++)
System.out.print(“*”);
System.out.println();
}
public static int readChoice()
int inData=-1;
do
try
System.out.println(“Please select an option from the menu :” );
System.out.println(“1. Enter House Pricesn2. Enter Avocado on Toast Pricen3. Deposit Calculatorn4. Exit System”);
inData=Integer.parseInt(readData.nextLine()); //read the menu choice
if(inData<0 || inData>4) //validate the menu choice is between 1 and 4
System.out.println(“nPlease enter the input between 1 and 4n”); //if the condition is false, print the error message
else
break;
catch(NumberFormatException nfe) //if any number format has exception, it displays an error message
System.out.println(“nInvalid input : please retryn”);
catch(Exception e)
System.out.println(“nInvalid input : please retryn”);
}while(inData>0 && inData<=4);
return inData;
public static double readPositive(String str)
double data=0;
do
try
System.out.println(str);
data=Double.parseDouble(readData.nextLine()); //read the value
if(data<=0) //validate the input data is less than or equal to zero
System.out.println(“nValue should be greater than 0n”); //if the condition is true, print an error message
else
break;
catch(NumberFormatException nfe)
System.out.println(“nInvalid input : please retryn”);
catch(Exception e)
System.out.println(“nInvalid input : please retryn”);
}while(true);
return data;
public static void main(String[] args)
int menuChoice=-1,flag=0,numAcocadoPerWeek=0,futureNumWeek;
double dblCheapest=0,dblSelected=0,dblMedian=0,avocadoPrice=0,discount=20.0/100;
GregorianCalendar currentDate=new GregorianCalendar();
SimpleDateFormat dFormat = new SimpleDateFormat(“dd/mm/yyyy”); //date formatting object
NumberFormat nFormat = new DecimalFormat(“#0.00”); //decimal number format
printStar(86);
System.out.println(“ntttSAVE A HOUSE DEPOSIT CALCULATORn”); //display the welcome message
System.out.println(“Developed by Mohammad Mozammel Hoque, Student ID 30332712 for ITECH1000 Sem 2 2017n”);
printStar(86);
do
menuChoice=readChoice(); //read menu choice
if(menuChoice==1)
System.out.println(“nHouse Details :”);
dblCheapest=readPositive(“Enter asking price for cheapest house listing : $”); //read the cheapest price of house
dblSelected=readPositive(“nEnter asking price for your chosen house : $”); //read the chosen price of house
if(dblCheapest<dblSelected) //check the cheapest is less than the selected value
dblMedian=readPositive(“nEnter the median value for this area : $”); //if yes, read the median value
if(dblCheapest<dblMedian) //validate the cheapest is less than median, set 1 to flat
flag=1;
else
dblCheapest=0.0; //if the cheapest is greater than median, set cheapest, chosen and median to zero
dblSelected=0.0;
dblMedian=0.0;
flag=0;
System.out.println(“nCheapest price should be less than median housen”);
else
System.out.println(“nCheapest price should be less than chosen housen”); //if the selected value is less than cheapest, display an error message
else if(menuChoice==2) //if the choice is 2,
if(flag==1) //if flag is 1 (it means that house data are entered successfully)
avocadoPrice=readPositive(“Enter the price (in dollars) of avocado on toast from a local cafe or restaurant: $”); //read the avocado on toast price
flag=2;
else
System.out.println(“nYou need to enter all the house prices firstn” ); //if house data are not entered, it displays an error message
else if(menuChoice==3)
if(flag==2)
System.out.println(“DEPOSIT SAVING CALCULATOR”);
printStar(95);
System.out.println(“You will need to NOT buy”); //display the deposit saving calculating information
System.out.println(nFormat.format(dblCheapest*discount/avocadoPrice)+” smashed avocados on toast to save $”+nFormat.format(dblCheapest*discount)+” deposit for the cheapest house”);
System.out.println(nFormat.format(dblSelected*discount/avocadoPrice)+” smashed avocados on toast to save $”+nFormat.format(dblSelected*discount)+” deposit for your chosen house”);
System.out.println(nFormat.format(dblMedian*discount/avocadoPrice)+” smashed avocados on toast to save $”+nFormat.format(dblMedian*discount)+” deposit for a house at the median price”);
printStar(95);
numAcocadoPerWeek=(int) readPositive(“How many times a week do you purchase avocado on toast?”);
futureNumWeek=(int) (dblSelected /(numAcocadoPerWeek * 4 * 20)); //read the number of toast per week purchased
currentDate.add(Calendar.WEEK_OF_MONTH, futureNumWeek); //add current date to number of avocado per week
System.out.println(“nIf you stop buying avocado on toast starting from today and save the moneny instead,nyour deposit for a $”+dblSelected+” house will be saved in the week of “+dFormat.format(currentDate.getTime()));
printStar(100);
else
System.out.println(“nYou need to enter all house and avocado prices firstn”);
}while(menuChoice!=4);
System.out.println(“nThe House Deposit Calculator is now exiting”); //print the exit message
Section 3: Testing
Document your testing here. Copy your test cases here from Section 1 as you need them. You can use screen captures to show the Actual Results – if using Microsoft Windows, the Snipping Tool is handy for this.
Note: If you find that a test case fails when you try it (i.e. the program does not return the expected results), make sure you include that in your results too. This is a GOOD thing and the reason for testing in the first place – even professional programmers make mistakes while coding and we need to test to find these issues. After you find an error, find the issue, try to fix it, and then test the code again. Show your updated results in the Actual Results section as well. You can include comments with this to explain what has happened.