Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is a java code for a coffee shop. i need the UML diagram for all the classes in this code.(jGRASP or NetBeans will be

Below is a java code for a coffee shop. i need the UML diagram for all the classes in this code.(jGRASP or NetBeans will be used to run and test the application) Also a brief description of the class. At the start of each method, there should also be a comment clearly describing what the method does. Each class should be fully documented commencing with a heading.

import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; import java.lang.Math;

// Main class which extends Jfrae class public class CoffeeShop extends JFrame implements ActionListener { //Declare Class Level Variable JLabel l,l1,l2,l3,l4,rl1,rl2; JTextField tf1,tf2,tf3,tf4; JRadioButton c1,c2,c3,c4,c5; JButton calculate,reset; JTextArea r1,r2; double totalsale; //Class constructor which called automatically when class object is created CoffeeShop(){ // Label to define constant vale l = new JLabel("Coffee N Roll Register"); //Paneel to define sale price JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(1,2)); l1 = new JLabel("Sale price"); tf1=new JTextField(); p1.add(l1); p1.add(tf1); // Radio Button to chose one option c1 = new JRadioButton ("1. Schnitrel Roll $18.80"); c2 = new JRadioButton ("2. Fish Roll $17.25 "); c3 = new JRadioButton ("3. Lamb Roll $14.60"); c4 = new JRadioButton ("4. Ice Cream Roll $6.75"); c5 = new JRadioButton ("5. Coffee Latter $3.40"); // Putting Radio button in group so that only 1 value possible at a time ButtonGroup bg=new ButtonGroup(); bg.add(c1); bg.add(c2); bg.add(c3); bg.add(c4); bg.add(c5); // Adding all radio button inside pannel JPanel p2 = new JPanel(); p2.setLayout(new GridLayout(5,1)); p2.add(c1); p2.add(c2); p2.add(c3); p2.add(c4); p2.add(c5); // Pannel for user input information like quantity, Paid amount JPanel p3 = new JPanel(); p3.setLayout(new GridLayout(3,2)); l2 = new JLabel("Quantity"); tf2=new JTextField(); l3 = new JLabel("Paid (cents)"); tf3=new JTextField(); l4 = new JLabel("Change"); tf4 = new JTextField(); // adding field in pannel -3 p3.add(l2); p3.add(tf2); p3.add(l3); p3.add(tf3); p3.add(l4); p3.add(tf4); // Calculte and reset button calculate = new JButton("Calculate"); calculate.addActionListener(this); reset = new JButton("Reset"); reset.addActionListener(this); //Panel to add button JPanel p4 = new JPanel(); p4.setLayout(new GridLayout(1,2)); p4.add(calculate); p4.add(reset); //Panel for Left side JPanel main = new JPanel(); main.setLayout(new GridLayout(9,1)); JLabel space = new JLabel(); main.add(l); main.add(space); main.add(p1); main.add(space); main.add(p2); main.add(space); main.add(p3); main.add(space); main.add(p4); //Panel for right side JPanel main1 = new JPanel(); main1.setLayout(new GridLayout(4,1)); //Right side text field and label rl1 = new JLabel("Change Currency denominations"); r1 = new JTextArea(); rl2 = new JLabel("Daily tranding summary"); r2 = new JTextArea(); // Add element in right side panel main1.add(rl1); main1.add(r1); main1.add(rl2); main1.add(r2); //Main panel which add in Frame JPanel com = new JPanel(); com.setLayout(new GridLayout(1,2)); com.add(main); com.add(main1); //Setting Frame properties setTitle("CashReg"); add(com); pack(); setVisible(true); setSize(1000,1000); setLayout(null); }

// Main method public static void main(String[] args) { //Calling class constructor new CoffeeShop(); }

// Action listner method when button in clicked @Override public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Calculate")) { //getting value from text field int quant = Integer.parseInt(tf2.getText()); double paid = Double.parseDouble(tf3.getText()); double n = 0; //getting information which radio button is selected if(c1.isSelected()) n = 18.80; if(c2.isSelected()) n = 17.25; if(c3.isSelected()) n = 14.60; if(c5.isSelected()) n = 6.75; if(c5.isSelected()) n = 3.40; // Calculate Total Bill amount double Total = n * quant; // Claculate Refund amount System.out.println(Total); //Calculate Total Sales totalsale = totalsale + Total; //Calculate Customer Refund amount double payToCust = (paid/100) - Total; System.out.println(payToCust); //Setting value in sale price and refund amount tf1.setText(String.format("%.2f",Total)); tf4.setText(String.format("%.2f",payToCust)); //String to print type of coin return to customer as refund StringBuffer buff = new StringBuffer(); int count = 0; //Login to calculate coins type while(payToCust >= 0.0) { while(payToCust >= 20.0) { count++; payToCust = payToCust - 20.0; } if(count > 0) { buff.append("|Number of 20 dollar notes: ").append(count).append(" |").append(" "); count = 0; } System.out.println(buff.toString()); while(payToCust >= 2.0) { count++; payToCust = payToCust - 2.0; } if(count > 0) { buff.append("|Number of 2 dollar coins: ").append(count).append(" |").append(" "); count = 0; } System.out.println(buff.toString()); while(payToCust >= 1.0) { count++; payToCust = payToCust - 1.0; } if(count > 0) { buff.append("|Number of 1 dollar coins: ").append(count).append(" |").append(" "); count = 0; } System.out.println(buff.toString()); while(payToCust >= 0.50) { count++; payToCust = payToCust - 0.50; } if(count > 0) { buff.append("|Number of 50 cents coins: ").append(count).append(" |").append(" "); count = 0; } System.out.println(buff.toString()); while(payToCust >= 0.20) { count++; payToCust = payToCust - 0.20; } if(count > 0) { buff.append("|Number of 20 cents coins: ").append(count).append(" |").append(" "); count = 0; } System.out.println(buff.toString()); if(payToCust > 0 && payToCust < .50) payToCust = payToCust + .05; while(payToCust >= 0.05) { count++; payToCust = payToCust - 0.05; } if(count > 0) { buff.append("|Number of 5 cents coins: ").append(count).append(" |").append(" "); count = 0; } //setting refund coins value on GUI payToCust = -1; r1.setText(buff.toString()); //Setting up Daily Sales StringBuffer buf = new StringBuffer(); buf.append("Total ").append("Daily Sales: ").append("$").append(String.format("%.2f",totalsale)); r2.setText(buf.toString()); } } //Execute when click on reset button all field set to non. if(e.getActionCommand().equals("Reset")) { tf1.setText(""); tf2.setText(""); tf3.setText(""); tf4.setText(""); r1.setText(""); r1.setText(""); } }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Class Diagram Description Classes CoffeeShop extends JFrame implements ActionListener Attributes Lab... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Business Statistics

Authors: Ronald M. Weiers

7th Edition

978-0538452175, 538452196, 053845217X, 2900538452198, 978-1111524081

More Books

Students also viewed these Programming questions