Java代写 | 4483 Software Technology COLT 2 2019 Assignment 2
使用Java完成一个模拟的Project
4483 Software Technology 1
COLT 2 2019
Assignment 2 (10% of the unit ) Marks 50
Total Marks 50 (Part A 35 + Part B 15)
Due: Friday Week 11 6th of September 2019 23.59 pm
PART A (35 Marks)
The warehouse managers’ helper program
GENERAL INSTRUCTIONS
This assignment should be done individually. The assignment consists of writing a program and demonstrating it and submitting it on canvas.
Assignment Briefing:
At a conceptual level this changes and builds on Assignment1. It removes the interesting discount handling but adds shipping, file reading and ordering complexity.
One key difference is that some orders are received as .txt files which must also be processed.
The wonderful Elon Musket, in the nation of ‘Tisisoddistan’ has opened a robotic distribution centre called ‘Bakov’ to distribute parts for his Space-hex rockets.
In this assignment, assume you are writing a program as part of the ‘Bakov’ distribution centre, which is in turn part of Elon’s vast business empire. Your tiny part is to write a program that takes orders, and then follows up with an invoice.
As part of the convoluted tax law in Tisisoddistan (which I made up for the assignment) all parts sold are charged at the shown price plus a 10% VAT. The VAT is a Value Added Tax like Australia’s GST, but administered differently.
However, it turns out that one subsidiary the “Blue Fish Space Company” is a registered charity and is not charged VAT.
No one can order more than we currently have in stock in the warehouse – as seen in the product table. (You do not need to keep a count of stock sold; nor should you reduce the amount when stock is sold. You can assume that stock is ‘magically’ replenished to the levels in the product table as it is sold – presumably by another program).
All inputs must be checked – company Id must be valid and as must product codes.
Orders of 0 or less are disallowed and assumed to be errors.
Here is a helpful table to show the various tax and discount statuses of the different subsidiaries.
Company Information
Company Id | Full Name | Pay Tax | Pickup
Bay Id |
BFSC | Blue Fish Space Co | No | MERCY |
ECP | Elon Cannon Personal | Yes | KIT |
NAASA | NAASA | Yes | MERCY |
AARG | AARG | Yes | KAT |
PUB | General Public | Yes |
Note: PUB is a general public mail order and must be shipped. The order is subject to additional shipping costs. Only the company PUB can ship by mail, all other orders are picked up from the warehouse – no annotation is necessary for them. Products or total orders heavier than 300Kg cannot be shipped and must be picked up by the ordering company. This should be annotated on the invoice.
Shipping cost (total KG’s) for the order line (only PUB customers pay shipping cost)
Less than 1.5 KG – $5 |
1.5kg to 20 kg – $6 plus 55c per kg |
Greater than 20 KG – $1.05 per Kg |
The warehouse has only 8 products as shown below in the product table
Product Code | Description | Price $ | Warehouse Location | Maximum to be ordered *1 | Weight in kg with packaging |
FENG | Fast Engine | 12,124.50 | ENG-894 | 5 | 1027 *2 |
SENG | Small Engine | 7,000.00 | ENG-895 | 5 | 72 |
FT | Fuel Tank | 7,000.00 | FT | 5 | 400 *2 |
HGA | High Gain Antenna | 7,003.11 | ANT-20 | 0 | 17 |
LWA | Light Weight Antenna | 4,950.20 | ANT | 5 | 1.2 |
PA | Polymer aerogel | 200.00 | PA | 101 | 0.3 |
AA | AA battery | $1.34 | BAT-AA | 1000 | 0.1 |
AA20 | AA batteries (20) | $14.99 | BAT-AA20 | 199 | 0.4 |
*1 – Current warehouse stock (Your program does not need to keep count)
*2 – This cannot be sent by mail
Note 3 – AA20 is a pack of 20 AA’s (cheaper in bulk)
Note 4 – HGA is out of stock and can’t be ordered – (should produce a sensible warning message)
Note 5- All parts of the order that can be sent by mail are sent by mail (PUB only).
Note 6- To keep it simple no need to add all weights – postage is per line
You program needs to have the following options in a menu which loops
Option | Effect |
Q | Quits the program |
C | Prints out the table Company Information for testing (which should be the same as the table above, in same order and general format) |
O | Process an order from keyboard input
This will need to input: · Company Id of the company that’s ordering parts; · product code; and · number of items ordered.
The fields that are input do (Repeat DO!) need to be checked for errors. (You need more sophisticated error handling code than in MT1.)
The program must then print the invoice line which shows · Company code (Id) · Product Code · Number of products ordered · Cost of one product · Gross cost (product cost * num products) · Tax (if applicable) · Weight (weight of one product * num products) · Shipping cost · Total cost (product + shipping +tax) · An extra line to describe shipping if the customer is PUB (see my example below)
|
F | Process an order from a file
This option will prompt for keyboard input of a file name. The file will contain the order information. The format of the .txt file is shown below |
W | Print a Product table (see above for format, see below for example) |
Layout of the orders .txt file:
On each line is the company Id of the company that’s ordering parts then a comma then
the product code a comma and the number of items ordered.
The files are supposed to be in upper case. (should a lower case character be found you can convert it to upper case safely).
…
… Format of these lines is repeated till last order
…
Then on the final line of the file is the word END
There are a minimum of 2 lines in the file the 3rd and subsequent lines are optional the fileay have any number of blank lines after the ‘END’
Your program is expected to handle errors in the file in a sensible way.
Example of an orders .txt file (supplied as test1.txt)
AARG,FENG,3
END |
Second Example of another orders .txt file (supplied as test2.txt)
NAASA,FENG,3
PUB,AA20,3 END |
A simple example worked through – NAASA orders 3 fast engines.
Step | Description | Computation / Notes |
Input | The Company code and name | NAASA |
Input | The Product Code and name | FENG |
Input | The number of products ordered | 3 |
Compute | The list cost of the product from the table | Lookup using FENG |
Compute | Multiply by number of products
|
3 * 12,124.50
= 36,373.50 |
Compute | The Tax paid
|
10% of 36,373.5
=3,637.35 |
Compute | The Tax Added to price
|
36,373.5 + 3,637.35
= 40,010.85 |
Compute | Compute the final cost of the order | =40,010.85 |
Display the order line | The number of products ordered 3
Cost of 1 product 12,124.50 Gross cost 36,373.50 Tax (if applicable) 3,637.35 Weight 3,081 Shipping cost 0 Total cost 40,010.85
|
Another example
Step | Description | Input or Output | Computation / Notes |
1 | The Company code | PUB | It’s mail order folks |
The Product Code and name | AA20 | ||
The number of products ordered | 3 | ||
Lookup cost | 14.99
Multiply by number of products 14.99*3 = 44.97 |
||
Tax is 10% | Tax = 44.97 *0.1 = 4.497
Rounds to 4.50 |
||
Weight is (lookup) | 0.4 | 0.4 *3 = 1.2kg | |
Shipping is | 5$ | Less than 1.5 kg | |
Shipping+tax+gross cost = | 5+4.50+44.97 = 54.47 | ||
Compute the final cost of the order | =54.47 + 40,010.85
Giving 40,065.32 Will be minor rounding errors |
HINTS
Look at the supplied code;
Create some (like a lot) of additional test cases. See the example test plan I provide.
Get it accurate first, then tidy it up. ‘doubles’ can print nicely with %11.2f format in printf.
Look at the example run further down in this document.
Sample Runs
PART B (15 Marks)
Basic Swing Form
Introduction
This part of your main assignment should be done individually. This assignment consists of writing a program and demonstrating it and submitting it on Canvas.
NOTE: You cannot do this using drag and drop in eclipse or some other java development environment. You are warned that; I will put coding questions in the exam that assume you wrote this swing form yourself, manually coding the listeners and attaching them to buttons. You are unlikely to learn how to do this if you use drag and drop GUI builders.
GENERAL INSTRUCTIONS
Write a simple swing form that has the following features and looks (more or less) like the following:
It has three buttons, each of which does one thing; Add, Subtract, Concatenate.
It has 1 checkbox ‘Facebook’ which modifies the add button so it displays “Facebook”, thus proving Facebook is more interesting than Math. (Joke)
Here are examples of each function
Add
Subtract
Concatenate (example 1)
Concatenate (example 2)
Add with Facebook checked
Hints :
- First define the GUI class which extends Jframe
- Set the frame size
- Set it to visible
- Add the 3 or 4 JLabels (I used a JLabel for ===== which is optional)
- Test it
- Add the 2 JTextField (input boxes)
- Test it
- Add the 3 buttons
- Test it
- Add the Facebook checkbox
- Test it
- Write 1 listener class for Add (which checks the checkbox)
- Connect the listener to the button
- Test it
- Write 2 more listener classes for Subtract and Concatenate
- Connect the listener to the button
- Test it
- Drink Vanilla coke (optional step)
- Fix formatting of the output
- Add a title to jframe
- Tidy it up
- Test it
- Show your tutor (get 5 easy marks)
Below are some useful code fragments:
// *******************************************************
getContentPane().setLayout(null);
setTitle(“Assignment PartA”);
// *******************************************************
String text = text1.getText();
try
{
val1 = Double.parseDouble(text);
}
catch (NumberFormatException e)
{
val1=0;
rc=false;
JOptionPane.showMessageDialog(null, “Enter a valid double precision number please”,
“<< First Number Error >>”,
JOptionPane.ERROR_MESSAGE);
}
// *******************************************************
public class bAddAction implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
///// —————–
////// Lines deleted here that parsed the JTextFields into val1 and val2
///// —————–
if (rc)
{displayText4.setText(String.format(“%12.4f”,(val1 + val2)));}
else
{displayText4.setText(“0”);}
}
}
// *******************************************************
int posX =260;
JButton buttonAdd = new JButton(“Add”);
buttonAdd.setLocation(posX,30);
buttonAdd.setSize(110,20);
buttonAdd.addActionListener(new bAddAction());
getContentPane().add(buttonAdd);
// *******************************************************