2013-11-09 2 views
1
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. Как я могу распечатать формат получения на физическом принтере.

Любая помощь будет замечательной! Вы, ребята, самые лучшие!

ответ

0
  1. Вы можете установить общее поле цены в классе ReceiptCode. Используя соответствующие сеттеры и геттеры, вы получаете общую цену.
  2. Сделав первый шаг, умножьте цену с вашим налогом.
  3. Adopt PrintService интерфейс. например:

    PrintService selectedPrinter = (PrintService) выбор; DocPrintJob printJob = selectedPrinter.createPrintJob();

Для получения более подробной информации см. Сообщение Java: Printing program output to a physical printer.

Смежные вопросы