gpt4 book ai didi

java - 数组列表。总价 打印出来

转载 作者:行者123 更新时间:2023-12-01 04:11:22 26 4
gpt4 key购买 nike

import java.util.Scanner;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;


import java.util.*;


class ReceiptCode {
private static final char[] ItemPrice = null;

public static void main(String[] args) {
// TODO Auto-generated method stub
//Font f = new Font("Calibri", Font.BOLD, 20);

@SuppressWarnings("resource")
Scanner scan= new Scanner(System.in);
System.out.println("Enter Company Name");
String companyName= scan.nextLine();

System.out.println("Enter STREET ADDRESS");
String street=scan.nextLine();

System.out.println("Enter CITY, STATE, ZIP");
String CSZ=scan.nextLine();

//System.out.println(companyName + "\n" + street + "\n" + CSZ);


String breaker = "------------------------------";
List <Items> invList = new ArrayList<Items>();
System.out.println("How many items did you order?");
int counter = scan.nextInt();
double totalPrice = 0;
for (int i=0; i<counter; i++)
{
System.out.println("Enter Item Name");
String fName = scan.next();
System.out.println("Enter Quantity?");
int fType = scan.nextInt();
System.out.println("Enter Price?");
double fPrice = scan.nextDouble();
Items inv = new Items(fName, fType, fPrice);
double x = (fType * fPrice);
totalPrice += x;
invList.add(inv);
//System.out.println(totalPrice);
}

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
DateFormat timeFormat = new SimpleDateFormat ("HH:mm");
Date date = new Date();
Date time = new Date();
System.out.printf("%-15s %n", companyName);
System.out.printf("%-15s %14s %n",street + "\n" + CSZ,dateFormat.format(date));
System.out.printf("%-15s %n", timeFormat.format(time));
System.out.println(breaker);
for (Items c : invList) {

System.out.println (c.getItemQTY() + " x " + c.getItemName() + " : " + c.getItemPrice() + "$");
System.out.println (breaker);

}
}
}



public class Items {

private String ItemName;
private int ItemQTY;
private double ItemPrice;

public Items (String fdType, int fdAmount, double fdPrice)
{
ItemName = fdType;
ItemQTY = fdAmount;
ItemPrice = fdPrice;
}
public String getItemName()
{
return ItemName;
}
public int getItemQTY()
{
return ItemQTY;
}
public double getItemPrice()
{
return ItemPrice;
}
}

我有几个问题。

  1. 如何才能得到最后打印出来的所有商品的总价?
  2. 如何将该价格乘以固定百分比?(税费)
  3. 如何将收据格式打印到物理打印机上。

任何帮助都会很棒!你们是最棒的!

最佳答案

  1. 您可以在 ReceiptCode 类中设置总价字段。通过实现适当的 setter 和 getter,您可以获得总价。
  2. 完成第一步后,将价格乘以税费。
  3. 采用PrintService界面。例如:

    PrintService selectedPrinter = (PrintService) 选择;DocPrintJob printJob = selectedPrinter.createPrintJob();

有关更多详细信息,请查看 Java: Printing program output to a physical printer发布。

关于java - 数组列表。总价 打印出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19881766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com