Lumumba is an entrepreneur based in eMalahleni. He has opened a sphaza shop called EveryThingFishy. The shop specializes in selling fast food related to fish. Table 1 below shows the menu they currently sell.
No. Menu Amount (R)
1 Large Hake Fish 100.00
2 Fish Burger 85.00
Their large hake fish is served with either salads or chips. The fish burger is either served as spicy or regular. As a starting company, they charge a small fee for the extras. The table below shows the amount charged for the extras. There’s no extra charge for the regular option.
No. Extra Amount (R)
1 Salads 10.00
2 Chips 5.00
3 Spice 2.00
Create an application for Lumumba that will help him run the business. The application must allow a customer to choose a menu item to buy. If an invalid menu code is entered, the application must display an error message and come to an end. If the user enters a valid menu code, the customer must be allowed to select the extras relating to that menu. The amount due must be determined and displayed. The application must give the customer an opportunity of making payment. If payment is insufficient, the application must display an error message and thereafter come to an end. If payment is valid, change must be determined and displayed. Lastly, the application must display the details of the food bought.
Here is my code:
package everythingfishyapp; import java.util.Scanner; /** * * @author SETH */ public class EveryThingFishyApp { /** * @param args the command line arguments */ public static void main(String[] args) { // declare variables final double AMOUNT1 = 100.00, AMOUNT2 = 85.00, AMOUNT3 = 10.00, AMOUNT4 = 10.00,AMOUNT5 = 10.00 ; double amount,amtDue,change,payment; String menu1="Large Hake Fish", menu2="Fish Burger", extra1="Salads",extra2="Chips",extra3="Spice"; final int CODE1=1, CODE2=2; int code,extra, extr1=1,extr2=2,extr3=3; Scanner sc = new Scanner(System.in); //prompt the user to choose a menu item to buy System.out.println("Please enter a menu item: "); code=sc.nextInt(); System.out.println("Please select an extra: "); extra=sc.nextInt(); amount = sc.nextDouble(); System.out.println("Please enter a payment of the menu item and the extra: "); payment = sc.nextDouble(); //determine the amount due amtDue = code + extra; //determine the change change = payment - amount; if((code==CODE1)||(code==CODE2) && (extra==extr1)||(extra==extr2)||(extra==extr3) && (payment >= 87.00) ){ System.out.println("Your menu item is: " + code + " and your extra is: "+ extra + "\n" + "you owe: " + code + extra + "The change is: " + (payment - amount)); } } }
here is the output:
run: Please enter a menu item: 2 Please select an extra: 2
--- Update ---
Later this year local government elections will be held in South African. Political parties are expected to register their candidates with the IEC (Independent Electoral Commission). The IEC requires parties to submit lists of candidates meeting the following basic requirements:
1. Candidates must be South Africans; and
2. Candidates must be 18 years old and above.
Create an application that will help parties check if their candidates meet the minimum requirements of IEC .
here is my code:
package candidateapp; import java.util.Scanner; /** * * @author SETH */ public class CandidateApp { /** * @param args the command line arguments */ public static void main(String[] args) { // declare variables String natnlity; int age; Scanner sc = new Scanner(System.in); //prompt the user to enter his nationality System.out.println("Please enter your nationality: "); natnlity = sc.next(); System.out.println("Please enter your age: "); age = sc.nextInt(); //check if the candidates meet the minimum requirements if((natnlity=="south african")&& (age >= 18)){ System.out.println("You qualify for the elections"); }else{ System.out.println("You don't qualify fot the elections"); } } }
here is the output
Please enter your nationality: south african Please enter your age: Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at candidateapp.CandidateApp.main(CandidateApp.java:29) Java Result: 1