patternjavaMinor
Determining prices for wholesalers or retailers
Viewed 0 times
determiningwholesalersretailerspricesfor
Problem
It is my first year in college and I have designed a code using pretty much my own basic knowledge. I have designed a program to work out the price of items for wholesalers or retailers. Special customers also get a special discount if they are to click on the button. Please take a look at my code and give me any feedback on how I can implement it. Also let me know if you believe I have done a good job.
```
import java.awt.Dimension;
import java.text.NumberFormat;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
public class packingcompany extends JPanel {
JTable jt;
public packingcompany() {
String[] columns = {"Wholesalers No.Units", "Wholesalers(£)", "Retailers No.Units", "Retailers (£)"};
String[][] data = {{"1-6", "£50", "1-4", "£60"},
{"7-11", "£40", "5-9", "£50"},
{"12-21", "£30", "10-15", "£40"},
{"22-60", "£20", "16-50", "£30"},
{"60+", "£15", "50+", "£25"}};
jt = new JTable(data, columns) {
public boolean isCellEditable(int data, int columns) {
return false;
}
};
jt.setPreferredScrollableViewportSize(new Dimension(550, 80));
jt.setFillsViewportHeight(true);
JScrollPane jps = new JScrollPane(jt);
add(jps);
}
public static void main(String[] args) {
JFrame jf = new JFrame();
packingcompany t = new packingcompany();
jf.setTitle("The Packing Company");
jf.setSize(600, 150);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(t);
String input, sinput, result;
int option, spec;
int wsquantity = 0, rtquantity = 0;
double wstotal = 0, rttotal = 0, special;
JTextArea display = new JTextArea(); //stating that i want a JText area
```
import java.awt.Dimension;
import java.text.NumberFormat;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
public class packingcompany extends JPanel {
JTable jt;
public packingcompany() {
String[] columns = {"Wholesalers No.Units", "Wholesalers(£)", "Retailers No.Units", "Retailers (£)"};
String[][] data = {{"1-6", "£50", "1-4", "£60"},
{"7-11", "£40", "5-9", "£50"},
{"12-21", "£30", "10-15", "£40"},
{"22-60", "£20", "16-50", "£30"},
{"60+", "£15", "50+", "£25"}};
jt = new JTable(data, columns) {
public boolean isCellEditable(int data, int columns) {
return false;
}
};
jt.setPreferredScrollableViewportSize(new Dimension(550, 80));
jt.setFillsViewportHeight(true);
JScrollPane jps = new JScrollPane(jt);
add(jps);
}
public static void main(String[] args) {
JFrame jf = new JFrame();
packingcompany t = new packingcompany();
jf.setTitle("The Packing Company");
jf.setSize(600, 150);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(t);
String input, sinput, result;
int option, spec;
int wsquantity = 0, rtquantity = 0;
double wstotal = 0, rttotal = 0, special;
JTextArea display = new JTextArea(); //stating that i want a JText area
Solution
A few comments:
-
The convention for class names is camel case with the first word Capitalized; eg PackingCompany instead of packingcompany - see here for details on java naming conventions
-
Your packingcompany class, for me at any rate, is doing too much; for OO design you should try and follow the single responsibility principle
-
Instead of relying on magic numbers for
-
The convention for class names is camel case with the first word Capitalized; eg PackingCompany instead of packingcompany - see here for details on java naming conventions
-
Your packingcompany class, for me at any rate, is doing too much; for OO design you should try and follow the single responsibility principle
-
Instead of relying on magic numbers for
spec and option look at using enumsContext
StackExchange Code Review Q#84152, answer score: 3
Revisions (0)
No revisions yet.