• 内部类


    package com.tech.Apple;

    import com.sun.javaws.Main;

    import java.util.ArrayList;

    public class Invoice {
    private static class Item{
    String description;
    int quantity;
    double unitPrice;

    public String getDescription() {
    return description;
    }

    public int getQuantity() {
    return quantity;
    }

    public double getUnitPrice() {
    return unitPrice;
    }

    public Item() {
    }

    public Item(String description, int quantity, double unitPrice) {
    this.description = description;
    this.quantity = quantity;
    this.unitPrice = unitPrice;
    }
    double price(){
    return quantity * unitPrice;
    }
    }
    private ArrayList<Item> items = new ArrayList<>();
    public void add(Item item){
    items.add(item);
    System.out.println(item.getDescription() + " " + item.getQuantity() + " " + item.getUnitPrice() + " " + item.price());
    }
    public void addItem(String description, int quantity, double unitPrice){
    Item item = new Item();
    item.description = description;
    item.quantity = quantity;
    item.unitPrice = unitPrice;
    System.out.println(item.getDescription() + " " + item.getQuantity() + " " + item.getUnitPrice() + " " + item.price());
    }


    public static void main(String[] args) {
    Invoice.Item newItem = new Invoice.Item("BlackWell Toaster",2,19.95);
    System.out.println(newItem.getDescription() + " " + newItem.getQuantity() + " " + newItem.getUnitPrice() + " " + newItem.price());
    Invoice iv = new Invoice();
    iv.add(newItem);
    iv.addItem("pen",2,5);

    }

    }
  • 相关阅读:
    JavaScript高级-----8.函数进阶(2)
    JavaScript高级-----7.函数进阶(1)
    2014-10-18 来美半个月
    修手机记
    圆梦美利坚之三:租房记
    圆梦美利坚之二:买机票记
    Hadoop 停止Job
    IIS应用程序池数目
    HTML5 microdata
    Java sql helper[转]
  • 原文地址:https://www.cnblogs.com/zj1234/p/8604684.html
Copyright © 2020-2023  润新知