I have an assignment and I need to come up with a programming code for calculating the total bill for a Saloon Center.
The program requires me to come up with an interface to key in customer's details like name ,IC no, date of treatment,etc
So the codes which I came out with are as follows:
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JFrame;
import javax.swing.JButton;
public class SaloonApp {
public static void main(String[]args){
JFrame frame = new JFrame("Che Gayah's Saloon Center");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel =new JPanel(new GridLayout(30,30,10,10));
panel.add(new JLabel("Name:"));
panel.add(new JTextField(5));
panel.add(new JLabel("IC:"));
panel.add(new JTextField(5));
panel.add(new JLabel("Member or non member:"));
JRadioButton Yes,No;
ButtonGroup buttonGroup =new ButtonGroup();
Yes=new JRadioButton("Member (25% discount for each treatment)");
buttonGroup.add(Yes);
panel.add(Yes);
No=new JRadioButton("Non-member");
buttonGroup.add(No);
panel.add(No);
panel.add(new JLabel("Date of treatment:"));
panel.add(new JTextField(5));
panel.add(new JLabel("Please select a type of treatment:"));
JRadioButton Body,Hair;
ButtonGroup TypeOfTreatment= new ButtonGroup();
Body=new JRadioButton("Body");
TypeOfTreatment.add(Body);
panel.add(Body);
Hair=new JRadioButton("Hair");
TypeOfTreatment.add(Hair);
panel.add(Hair);
panel.add(new JLabel("For body treatment, please make your selection:"));
JRadioButton SeveralParts,AllParts;
ButtonGroup BTreatment =new ButtonGroup();
SeveralParts= new JRadioButton("Several parts - RM 320.00");
BTreatment.add(SeveralParts);
panel.add(SeveralParts);
AllParts=new JRadioButton("All parts - RM 600.00");
BTreatment.add(AllParts);
panel.add(AllParts);
panel.add(new JLabel("For hair treatment, please make your selection:"));
panel.add(new JLabel("Rebonding "));
JRadioButton Yes1,No1;
ButtonGroup Rebonding =new ButtonGroup();
Yes1=new JRadioButton("Yes (RM 250.00)");
Rebonding.add(Yes1);
panel.add(Yes1);
No1=new JRadioButton("No");
Rebonding.add(No1);
panel.add(No1);
panel.add(new JLabel("Cutting"));
JRadioButton Yes2,No2;
ButtonGroup Cutting =new ButtonGroup();
Yes2=new JRadioButton("Yes (RM 50.00)");
Cutting.add(Yes2);
panel.add(Yes2);
No2=new JRadioButton("No");
Cutting.add(No2);
panel.add(No2);
panel.add(new JLabel("Washing"));
JRadioButton Yes3,No3;
ButtonGroup Washing =new ButtonGroup();
Yes3=new JRadioButton("Yes (RM 15.00)");
Washing.add(Yes3);
panel.add(Yes3);
No3=new JRadioButton("No");
Washing.add(No3);
panel.add(No3);
panel.add(new JLabel("Dyeing "));
JRadioButton Yes4,No4;
ButtonGroup Dyeing =new ButtonGroup();
Yes4=new JRadioButton("Yes(RM 100.00)");
Dyeing.add(Yes4);
panel.add(Yes4);
No4=new JRadioButton("No");
Dyeing.add(No4);
panel.add(No4);
JButton button =new JButton("Submit");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String str = JOptionPane.showInputDialog(null, "Please enter your name : ",
"Customer info", 1);
if(str != null)
JOptionPane.showMessageDialog(null, "Name : " + str,
"Customer info", 1);
else
JOptionPane.showMessageDialog(null, "You did not enter your name. Please try again",
"Customer info", 1);
}
});
panel.add(button);
frame.add(panel);
frame.setSize(750, 750);
frame.setVisible(true);
}
}
So, what I want is for the JOptionPane to display the details of the billing. If the customer is a member, he or she will receive a 25% discount on each treatment. I wanted the program to calculate the billing for each selection of the treatment. I did a search on ActionListener for JRadioButton but not sure if it works for this case. Any advice or feedback on this matter is highly appreciated. Thanks!

New Topic/Question
Reply



MultiQuote








|