COIT11222 Programming Fundamentals Assignment - Central Queensland University, Australia
Develop a Windowed GUI Java Program to demonstrate you can use Java constructs including input/output via a GUI interface, Java primitive and built-in types, Java defined objects, arrays, selection and looping statements and various other Java commands. Your program must produce the correct results. Submit two source files: Order.java and RockyDryCleanersGUI.java.
EXPERTSMINDS.COM GIVES ACCOUNTABILITY OF YOUR TIME AND MONEY - AVAIL TOP RESULTS ORIGINATED COIT11222 PROGRAMMING FUNDAMENTALS ASSIGNMENT HELP SERVICES AT BEST RATES!
Answer - Order.java
public class Order {
private String customerName;
private int garments;
//default constructor
public Order()
{
customerName="";
garments=0;
}
//parameterised constructor
public Order(String name,int gar)
{
customerName=name;
garments=gar;
}
//set methods (mutators)
public void setCustomerName(String name){
customerName=name;
}
//setting garments
public void setGarments(int gar){
garments=gar;
}
//Two get methods (accessors)
//getting customer name
public String getCustomerName(){
return customerName;
}
//getting garments
public int getGarments(){
return garments;
}
/*CalculateCharge value returning method
* One to two garments: $8.50 per garment.
Three garments: $20.00.
More than three garments: $20.00 plus $6.50 per garment after that
* */
public double calculateCharge()
{
double charge=0;
if (garments ==1)
charge= 8.5;
else if (garments==2)
charge= 2*8.5;
else if( garments ==3)
charge = 20;
else if (garments>3)
{
int i=garments-3;
charge=20;
for( int j=0;j<i;j++)
{
charge +=6.5;
}
}
else
charge=0;
return charge;
}
}
ENROL WITH COIT11222 PROGRAMMING FUNDAMENTALS ASSIGNMENT HELP AND HOMEWORK WRITING SERVICES OF EXPERTSMINDS.COM AND GET BETTER RESULTS IN COIT11222 PROGRAMMING FUNDAMENTALS ASSIGNMENTS!
RockyDryCleanersGUI.java
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
// TODO -- create Order class (separate file)
public class RockyDryCleanersGUI extends JFrame implements ActionListener
{
private int MAX_ORDERS=10; // declare maximum orders constant
private Order [] orderArray = new Order[MAX_ORDERS];// declare Order object array
private int currentOrder = 0;// declare current order variable
private JLabel titleLabel = new JLabel("Rocky Dry Cleaners Management System"); // program title
private JLabel nameLabel = new JLabel("Customer name: ");// for prompt
private JTextField nameField = new JTextField(26); // for name entry
private JLabel garmentsLabel = new JLabel("Number of plain garments: ");// for prompt
private JTextField garmentsField = new JTextField(4); // for number of garments entry
private JTextArea displayTextArea = new JTextArea("", 16, 56); // declare text area
private JScrollPane scrollPane; // scroll pane for the text area
// declare all of the buttons
private JButton enterButton = new JButton("Enter"); // buttons
private JButton displayButton = new JButton("Display All");
private JButton searchButton = new JButton("Search");
private JButton exitButton = new JButton("Exit");
public RockyDryCleanersGUI()
{ // constructor create the Gui
this.setLayout(new FlowLayout()); // set JFrame to FlowLayout
titleLabel.setFont(new Font("Ariel", Font.BOLD, 22));
add(titleLabel);
add(nameLabel);
add(nameField);
add(garmentsLabel);
add(garmentsField);
// set text area to a monospaced font so the columns can be aligned using a format string
displayTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
displayTextArea.setEditable(false); // make text area read only
scrollPane = new JScrollPane(displayTextArea); // add text area to the scroll pane
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // just need vertical scrolling
add(scrollPane);
add(enterButton);
add(displayButton);
add(searchButton);
add(exitButton);
enterButton.addActionListener(this); // add the action listener to the buttons
displayButton.addActionListener(this);
searchButton.addActionListener(this);
exitButton.addActionListener(this);
// when the user pushes the system close (X top right corner)
addWindowListener( // override window closing method
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
exit(); // Attempt to exit application
}
}
);
}
public void actionPerformed(ActionEvent e)
{ // process the clicks on all of the buttons
String command = e.getActionCommand();
if (command.compareTo("Enter") == 0)
enter();
else if (command.compareTo("Display All") == 0)
displayAll();
else if (command.compareTo("Search") == 0)
search();
else if (command.compareTo("Exit") == 0)
exit();
}
private void enter()
{
//max order reached
if (currentOrder==10)
{
JOptionPane.showMessageDialog(this, "Maximum number of orders has been reached","Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
nameField.setText("");
garmentsField.setText("");
nameField.requestFocus();
}
else if(nameField.getText().compareTo("") == 0) //when name filed is empty
{
JOptionPane.showMessageDialog(this, "You must enter a customer name", "Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
nameField.requestFocus();
}
else if (garmentsField.getText().compareTo("") == 0) //when garments field is empty
{
JOptionPane.showMessageDialog(this, "You must enter number of garments ", "Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
garmentsField.requestFocus();
}
else // when name and garments field are non empty
{
//Read in customer name and number of garments information and add to the Order array
String customerName = nameField.getText();
int garments = Integer.parseInt(garmentsField.getText());
orderArray[currentOrder] = new Order(customerName, garments);
currentOrder++;
displayHeading();
//Clear input fields and return focus to the customer name field and increment current booking variable
nameField.setText("");
garmentsField.setText("");
nameField.requestFocus();
//Display customer name, number of garments and the order charge to the text area
for(int i=0;i<currentOrder;i++)
{
displayTextArea.append(String.format("%-30s%-17s\t$%5.2f\n",orderArray[i].getCustomerName(),String.valueOf(orderArray[i].getGarments()),orderArray[i].calculateCharge()));
}
}
}
private void displayHeading()
{
displayTextArea.setText(String.format("%-30s%-17s%-6s\n", "Customer Name", "Garments", "Charge"));
appendLine();
}
private void appendLine()
{
displayTextArea.append("-------------------------------------------------------\n");
}
private void displayAll()
{
double totalcharge=0;
double avergarments=0;
if (currentOrder==0) //when no order
{
JOptionPane.showMessageDialog(this, "No order entered ", "Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
displayTextArea.setText("");
}
else //display all of the entries entered so far
{
displayHeading();
for(int i=0;i<currentOrder;i++)
{
displayTextArea.append(String.format("%-30s%-17s\t$%5.2f\n",orderArray[i].getCustomerName(),String.valueOf(orderArray[i].getGarments()),orderArray[i].calculateCharge()));
totalcharge+=orderArray[i].calculateCharge();
avergarments+=orderArray[i].getGarments();
}
//display average garments per order and total charges collected
displayTextArea.append("------------------------------------------------------------\n");
displayTextArea.append(String.format("%-40s%5.2f\n","Average garments per order:",(avergarments/currentOrder)));
displayTextArea.append(String.format("%-40s\t$%5.2f\n","Total charges:",totalcharge));
}
}
private void search()
{
//read search key (customer name) from input dialog
String inp=JOptionPane.showInputDialog(this,"Enter a customer name to search","",JOptionPane.OK_OPTION);
int flag=0;
if (inp.compareTo("")==0) //when input search name is empty
{
JOptionPane.showMessageDialog(this, "You must enter a search name","Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
}
else
{
//iterate through array to search for the search key
for(int i=0;i<currentOrder;i++)
{
if(inp.compareTo(orderArray[i].getCustomerName())==0) //when search successful
{
displayHeading();
displayTextArea.append(String.format("%-30s%-17s\t$%5.2f\n",orderArray[i].getCustomerName(),String.valueOf(orderArray[i].getGarments()),orderArray[i].calculateCharge()));
nameField.requestFocus();
flag=1;
break;
}
}
if (flag==0) //when search name not found in order array
{
JOptionPane.showMessageDialog(this, inp+" not found","Rocky Dry Cleaners Management System", JOptionPane.ERROR_MESSAGE);
}
}
}
private void exit()
{
// display exit message
JOptionPane.showMessageDialog(this, "Thank you for using Rocky Dry Cleaners Management System","Rocky Dry Cleaners Management System", JOptionPane.OK_OPTION);
System.exit(0);
} // exit
// Main method create instance of class
public static void main(String[] args)
{
RockyDryCleanersGUI f = new RockyDryCleanersGUI(); // Create instance of class
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // allow the code to close the program
f.setBounds(200, 100, 470, 440); // Define position and size of app
f.setTitle("Rocky Dry Cleaners Management System"); // Set the title of the app
f.setVisible(true); // Make the application visible
f.setResizable(false); // Make the window not resizable
} // main
}
24/7 AVAILABILITY OF TRUSTED COIT11222 PROGRAMMING FUNDAMENTALS ASSIGNMENT WRITERS! ORDER ASSIGNMENTS FOR BETTER RESULTS!
Access our Top Quality Central Queensland University, Australia Assignment Help Service for Various Courses and Units, Such As -
- COIT20262 Advanced Network Security Assignment Help
- COIT13230 Application Development Project Assignment Help
- COIT13240 Applied Cryptography Assignment Help
- COIT13229 Applied Distributed Systems Assignment Help
- COIT29223 Blockchain Technologies for Sustainable Business Applications Assignment Help
- COIT13232 Business Analysis Project Assignment Help
- COIT20253 Business Intelligence using Big Data Assignment Help
- COIT20252 Business Process Management Assignment Help
- COIT20260 Cloud Computing for Smart Applications Assignment Help
- COIT20267 Computer Forensics Assignment Help
- COIT40206 Computing Skills for University Assignment Help
- COIT12209 Data Science Assignment Help
- COIT11240 Dashboard Design and Visualisation Assignment Help
- COIT20256 Data Structures and Algorithms Assignment Help
- COIT11237 Database Design & Implementation Assignment Help
- COIT20247 Database Design and Development Assignment Help
- COIT20257 Distributed Systems: Principles and Development Assignment Help
- COIT20255 ERP Systems Management Assignment Help
- COIT12201 Electronic Crime and Digital Forensics Assignment Help