Question: 1436-Lab5-sum18,docx gives the assignment. SoftwareSalesDriver,java is the GUI driver file mentioned in the assigment file. Make no changes to this file. SoftwareSales,java is the start
1436-Lab5-sum18,docx gives the assignment. SoftwareSalesDriver,java is the GUI driver file mentioned in the assigment file. Make no changes to this file. SoftwareSales,java is the start of the class file you are to implement.
Software Sales
Part I: Class Implementation: A software company gives discounts based on the number of packages purchased, according to the following table:
Quantity Discount
-less than 10 -none
-10-19 -20%
-20-49 -30%
-50-99 -40%
-100-more -50%
Design a class that can compute the total cost of a software purchase, based on the base price of a package and the number of packages bought. The class implementation should follow the following UML specification:
SoftwareSales
- numberOfPackages : integer
- basePrice : double
+ SoftwareSales()
+ setNumberOfPackages(numPackages : integer ) : void
+ setBasePrice(price : double) : void
+ getNumberOfPackages() : integer
+ getBasePrice() : double
+ getTotalPrice(): double
Part II: A GUI interface. Your instructor will provide a copy of SoftwareSalesDriver.java. If your class follows the given UML specification, you should be able to compile and run the GUI interface, using your class for computations. Once you have implemented your class, test it using the following tests:
base price quantitiy total price
-$99.00 -3 -$297.00
-$99.00 -10 -$792.00
-$89.00 -90 -$4,806
-$109.00 -45 -$3,433.50
-$109.00 -100 -$5,450
// Driver program for Lab .
// (Make no changes to this program)
// COSC 1436 Summer 2018
//
// filename: SoftwareSalesDriver.java
//
// This program creates a user interface for a
// software sales program.
//
// Programmer: Dr. Tim McGuire
// Date: 12 June 2018
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.DecimalFormat;
public class SoftwareSalesDriver extends JFrame
{
// hold references to widgets that must be read
// or modified.
private JTextField basePriceField;
private JTextField numPackagesField;
private JLabel totalCostField;
//==================================================================
// constructor
public SoftwareSalesDriver()
{
// set panel titlebar
super("Software sales cost calculator.");
// create the graphical user interface
createGUI();
}
//==================================================================
// utility function:
// Read current input values.
// Creates and uses a SoftwareSales object to compute total cost.
// Update text values on display panel.
private void computeTotalCost()
{
// read user inputs
String strBasePrice = basePriceField.getText();
String strNumPackages = numPackagesField.getText();
DecimalFormat dollar = new DecimalFormat("#,###.00");
// convert input strings to numbers
double basePrice = Double.parseDouble(strBasePrice);
int numPackages = Integer.parseInt(strNumPackages);
// create SoftwareSales objec, set values and get result
SoftwareSales sales = new SoftwareSales();;
sales.setBasePrice(basePrice);
sales.setNumberOfPackages(numPackages);
double totalCost = sales.getTotalPrice();
// update display
basePriceField.setText(Double.toString(basePrice));
numPackagesField.setText(Integer.toString(numPackages) );
totalCostField.setText("$"+dollar.format(totalCost));
}
//==================================================================
// createGUI() creates the GUI components (widgits)
// and puts them together into one panel.
private void createGUI()
{
// create widgits
JLabel label1 = new JLabel("Base Cost");
basePriceField = new JTextField("0.00");
JLabel label2 = new JLabel("Number of Packages");
numPackagesField = new JTextField("0");
JLabel label3 = new JLabel("Total Cost");
totalCostField = new JLabel("$0.00");
JButton computeButton = new JButton("Compute Total Cost");
computeButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
computeTotalCost();
}
}
);
// configure window
setLayout(new GridLayout(4,2));
add(label1);
add(basePriceField);
add(label2);
add(numPackagesField);
add(label3);
add(totalCostField);
add(computeButton);
pack();
setVisible(true);
}
//==================================================================
// Program entry point: main()
// This simply creates the SoftwareSalesInterface object
// then waits for the interface window to be closed.
public static void main(String args[])
{
SoftwareSalesDriver app = new SoftwareSalesDriver();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
// Implementation file for SoftwareSales
// COSC 1436 Summer 2018
//
// filename SoftwareSales.java
//
// This file implements a class for software sales
//
// Programmer: Your name goes here
// Date: Date written goes here
public class SoftwareSales
{
private int numberOfPackages;
private double basePrice;
// implement the constructor here
public SoftwareSales()
{
// code to initialize data
}
// mutator method setNumberOfPackages allows driver program to set number of packages
public void setNumberOfPackages(int numPackages)
{
// complete code here
}
// mutator method setBase price allows driver program to set number of packages
// put code here
// accessor method getNumberOfPackages returns number of packages to driver program
public int getNumberOfPackages()
{
// fix this line
return 0;
}
//additional accessor methods getBasePrice() and getTotalPrice need to be implemented
// accessor method getBasePrice returns base price to driver program
// accessor method getTotalPrice returns total price to driver program
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
