Answer to Question #314005 in Java | JSP | JSF for random

Question #314005

Seoul Garden Sdn Bhd serves a wide range of seafood selections such as tasty crabs, fresh prawns, chicken fillets & many more for steamboat and grill. This buffet restaurant serves up 150+ choices of fresh seafood, fruits, and cold & hot beverages.


Age 6-12 years old, the price is RM 11 while age 13 and above years old, the price was RM 25.

Seoul Garden Sdn Bhd also gives an appreciation for the member cardholder with 6% off from the total price. The above price excludes government tax of RM 5.60.


Write an application that accepts the customer’s age and member status (member or non-member) by using a JOptionPane procedure and prints out the total price.



1
Expert's answer
2022-03-19T05:14:33-0400
import javax.swing.JOptionPane;
import java.util.Scanner;

class Client{

    final double cost1 = 11; // For children from 6 to 12 years old
    final double cost2 = 25; // For children aged 13 and over
    final double bond = 5.60;

    int age;
    String participant;
    double cost = 0;

    Client(int age, String participant) {
        this.age = age;
        this.participant = participant;
    }

    public void Calculation(){

        if(age < 6){
            JOptionPane.showMessageDialog(null, "Age input error","Error",JOptionPane.ERROR_MESSAGE);
        } else if (age <= 12){
            cost += cost1;
        } else{
            cost += cost2;
        }

        if(participant.equals("yes")){
            cost -= cost*0.06;
        }
        cost += bond;

        JOptionPane.showMessageDialog(null, cost, "Information", JOptionPane.INFORMATION_MESSAGE);
    }

}


public class Restaurant {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.print("Enter customer age: ");
        int age = in.nextInt();

        System.out.print("Whether the client is a member of the restaurant yes/no: ");
        String participant = in.nextLine();

        Client client = new Client(age, participant);

        client.Calculation();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS