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.
The price of the steamboat per person is shown in Table 1:
Age (years) Price (RM)
________________________
6 - 12 RM 11
> 13 RM 25
________________________
*I can't draw a table so I do like this :'(
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.
import javax.swing.*;
public class Restaurant {
public double cost1 = 11; // For children from 6 to 12 years old
public double cost2 = 25; // For children aged 13 and over
public double bond = 5.60;
public double cost = 0;
public void Calculation(int age, String participant) {
if(age < 6){
JOptionPane.showMessageDialog(null, "Age input error","Error",JOptionPane.ERROR_MESSAGE);
} else if (age <= 12 & age >= 7) {
cost += cost1;
if (participant.equals("yes")) {
cost -= cost * 0.06;
}
cost += bond;
JOptionPane.showMessageDialog(null, cost, "Information", JOptionPane.INFORMATION_MESSAGE);
} else {
cost += cost2;
if (participant.equals("yes")) {
cost -= cost * 0.06;
}
cost += bond;
JOptionPane.showMessageDialog(null, cost, "Information", JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] args) {
Restaurant rez = new Restaurant();
String age1 = JOptionPane.showInputDialog("Enter customer age");
int age = Integer.parseInt (age1);
String participant = JOptionPane.showInputDialog("Whether the client is a member of the restaurant yes/no");
rez.Calculation(age, participant);
}
}
Comments
Leave a comment