Java 收货程序不显示结果
Java receipt program not displaying results
我创建了一个简单的应用程序,它读取一系列产品 * 售出数量并生成最终订单收据,其中包括售出商品名称、数量和每件商品的总计以及整个收据的总计(包括6% 的销售税)。我觉得我完成了这个,除了我无法测试应用程序,因为没有任何内容打印到 "receipt" AKA ContentPane。以下是我使用的三个 classes。
产品class:
public class Product
{
private int coffeeQTY;
private int teaQTY;
private int bagelQTY;
private int muffinQTY;
private double tax;
private double total;
private double price;
private int productNOM;
public Product()
{
total=price=0.00;
productNOM=coffeeQTY=teaQTY=bagelQTY=muffinQTY=0;
}
//setters
public void setcoffeeQTY(int c)
{
coffeeQTY += c;
}
public void setteaQTY(int t)
{
teaQTY += t;
}
public void setbagelQTY(int b)
{
bagelQTY += b;
}
public void setmuffinQTY(int m)
{
muffinQTY += m;
}
//getters
public int getcoffeeQTY()
{
return coffeeQTY;
}
public int getteaQTY()
{
return teaQTY;
}
public int getbagelQTY()
{
return bagelQTY;
}
public int getmuffinQTY()
{
return muffinQTY;
}
public double getTAX()
{
return tax;
}
public double getTotal()
{
return total;
}
private double coffeePrice;
private double teaPrice;
private double bagelPrice;
private double muffinPrice;
public void inputOrder()
{
for(int i = 0; i <= 3; i++)
{
String order = JOptionPane.showInputDialog("Product 1: Coffee .65 "
+ "\nProduct 2: Tea .45 "
+ "\nProduct 3: Bagel .50 "
+ "\nProduct 4: Muffins .85 "
+ "\nEnter the number of the product you would like to order. Enter -1 when your order is complete: ");
productNOM = Integer.parseInt(order);
boolean done = false;
switch(productNOM)
{
case 1:
coffeePrice = 3.65;
String cQTY = JOptionPane.showInputDialog("Enter the quantity of Coffee you would like to order: ");
setcoffeeQTY(Integer.parseInt(cQTY));
break;
case 2:
teaPrice = 2.45;
String tQTY = JOptionPane.showInputDialog("Enter the quantity of Tea you would like to order: ");
setteaQTY(Integer.parseInt(tQTY));
break;
case 3:
bagelPrice = 1.50;
String bQTY = JOptionPane.showInputDialog("Enter the quantity of Bagels you would like to order: ");
setbagelQTY(Integer.parseInt(bQTY));
break;
case 4:
muffinPrice = 1.85;
String mQTY = JOptionPane.showInputDialog("Enter the quantity of the Muffins you would like to order: ");
setmuffinQTY(Integer.parseInt(mQTY));
break;
default:
done = true;
break;
}
total += coffeePrice * coffeeQTY + teaPrice * teaQTY + bagelPrice * bagelQTY + muffinPrice * muffinQTY;
if(!done)
{
tax = ((coffeePrice * coffeeQTY) * 0.06) + ((teaPrice * teaQTY) * 0.06) + ((bagelPrice * bagelQTY) * 0.06) + ((muffinPrice * muffinQTY) * 0.06);
total = (coffeePrice * coffeeQTY) + (teaPrice * teaQTY) + (bagelPrice * bagelQTY) + (muffinPrice * muffinQTY) + tax;
continue;
}
else
{
break;
}
}
}
public void draw(Graphics g)
{
g.drawString("Coffee .65 x" +getcoffeeQTY(), 25, 100);
g.drawString("Tes .45 x" +getteaQTY(), 25, 125);
g.drawString("Bagel .50 x" +getbagelQTY(), 25, 150);
g.drawString("Muffin .85 x" +getmuffinQTY(), 25, 175);
g.drawString("Tax(6%): " +getTAX(), 25, 225);
g.drawString("Total: " +getTotal(), 25, 250);
}
}
销售额class
public class Sales extends JComponent
{
private Product merch;
public Sales(Product m)
{
merch = m;
}
public void printSales(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
merch.draw(g2);
}
}
印刷品销售class
public class PrintSales
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Product merch = new Product();
merch.inputOrder();
JFrame frame = new JFrame();
frame.setSize(500, 750);
frame.setTitle("Coffee Shop");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.WHITE);
Sales store = new Sales(merch);
frame.add(store);
frame.setVisible(true);
}
}
不知道是不是跟增加了tax
字段有关,貌似printSales(...)
函数从来没有调用过,所以什么也画不出来
我创建了一个简单的应用程序,它读取一系列产品 * 售出数量并生成最终订单收据,其中包括售出商品名称、数量和每件商品的总计以及整个收据的总计(包括6% 的销售税)。我觉得我完成了这个,除了我无法测试应用程序,因为没有任何内容打印到 "receipt" AKA ContentPane。以下是我使用的三个 classes。
产品class:
public class Product
{
private int coffeeQTY;
private int teaQTY;
private int bagelQTY;
private int muffinQTY;
private double tax;
private double total;
private double price;
private int productNOM;
public Product()
{
total=price=0.00;
productNOM=coffeeQTY=teaQTY=bagelQTY=muffinQTY=0;
}
//setters
public void setcoffeeQTY(int c)
{
coffeeQTY += c;
}
public void setteaQTY(int t)
{
teaQTY += t;
}
public void setbagelQTY(int b)
{
bagelQTY += b;
}
public void setmuffinQTY(int m)
{
muffinQTY += m;
}
//getters
public int getcoffeeQTY()
{
return coffeeQTY;
}
public int getteaQTY()
{
return teaQTY;
}
public int getbagelQTY()
{
return bagelQTY;
}
public int getmuffinQTY()
{
return muffinQTY;
}
public double getTAX()
{
return tax;
}
public double getTotal()
{
return total;
}
private double coffeePrice;
private double teaPrice;
private double bagelPrice;
private double muffinPrice;
public void inputOrder()
{
for(int i = 0; i <= 3; i++)
{
String order = JOptionPane.showInputDialog("Product 1: Coffee .65 "
+ "\nProduct 2: Tea .45 "
+ "\nProduct 3: Bagel .50 "
+ "\nProduct 4: Muffins .85 "
+ "\nEnter the number of the product you would like to order. Enter -1 when your order is complete: ");
productNOM = Integer.parseInt(order);
boolean done = false;
switch(productNOM)
{
case 1:
coffeePrice = 3.65;
String cQTY = JOptionPane.showInputDialog("Enter the quantity of Coffee you would like to order: ");
setcoffeeQTY(Integer.parseInt(cQTY));
break;
case 2:
teaPrice = 2.45;
String tQTY = JOptionPane.showInputDialog("Enter the quantity of Tea you would like to order: ");
setteaQTY(Integer.parseInt(tQTY));
break;
case 3:
bagelPrice = 1.50;
String bQTY = JOptionPane.showInputDialog("Enter the quantity of Bagels you would like to order: ");
setbagelQTY(Integer.parseInt(bQTY));
break;
case 4:
muffinPrice = 1.85;
String mQTY = JOptionPane.showInputDialog("Enter the quantity of the Muffins you would like to order: ");
setmuffinQTY(Integer.parseInt(mQTY));
break;
default:
done = true;
break;
}
total += coffeePrice * coffeeQTY + teaPrice * teaQTY + bagelPrice * bagelQTY + muffinPrice * muffinQTY;
if(!done)
{
tax = ((coffeePrice * coffeeQTY) * 0.06) + ((teaPrice * teaQTY) * 0.06) + ((bagelPrice * bagelQTY) * 0.06) + ((muffinPrice * muffinQTY) * 0.06);
total = (coffeePrice * coffeeQTY) + (teaPrice * teaQTY) + (bagelPrice * bagelQTY) + (muffinPrice * muffinQTY) + tax;
continue;
}
else
{
break;
}
}
}
public void draw(Graphics g)
{
g.drawString("Coffee .65 x" +getcoffeeQTY(), 25, 100);
g.drawString("Tes .45 x" +getteaQTY(), 25, 125);
g.drawString("Bagel .50 x" +getbagelQTY(), 25, 150);
g.drawString("Muffin .85 x" +getmuffinQTY(), 25, 175);
g.drawString("Tax(6%): " +getTAX(), 25, 225);
g.drawString("Total: " +getTotal(), 25, 250);
}
}
销售额class
public class Sales extends JComponent
{
private Product merch;
public Sales(Product m)
{
merch = m;
}
public void printSales(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
merch.draw(g2);
}
}
印刷品销售class
public class PrintSales
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Product merch = new Product();
merch.inputOrder();
JFrame frame = new JFrame();
frame.setSize(500, 750);
frame.setTitle("Coffee Shop");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.WHITE);
Sales store = new Sales(merch);
frame.add(store);
frame.setVisible(true);
}
}
不知道是不是跟增加了tax
字段有关,貌似printSales(...)
函数从来没有调用过,所以什么也画不出来