面向对象编程--超市小票java

将超市小票用面向对象的思想写出来。

小票样例:
面向对象编程--超市小票java_第1张图片
这次的小票中,我定义了三个类,N,Good,Massage。

import java.text.SimpleDateFormat;
import java.util.Date;//时间函数的包

public class N {
	public static void main(String args[]) {
		//小票开头信息
		Message t=new Message();
		t.storeName="杉木文化";
		System.out.printf("%33s\n",t.storeName);
		t.setDeviceNumber(123);
		t.setCashierNumber(1004);
		System.out.printf("机号:%d       收银员:%d\n",t.getDeviceNumber(),t.getCashierNumber());
		t.setOddNumber(123196275);
		System.out.printf("单号:%d\n",t.getOddNumber());
		System.out.println("品名\t"+"\t单价"+"\t数量"+"\t金额");
		System.out.println("-------------------------------------");
	//商品信息
		Good[] goods=new Good[2];
		goods[0]=new Good("康师傅泡椒牛肉面",2.5,2);
		goods[1]=new Good("可口可乐汽水",3,1);
		for(int i=0;i
class Good {
	private String goodName;
	private double goodPrice;
	private int goodNumber;
	private double totalPrice=0.00;
	
	public Good(String goodName, double goodPrice, int goodNumber) {
		super();
		this.goodName = goodName;
		this.goodPrice = goodPrice;
		this.goodNumber = goodNumber;
	}
	
	public String getGoodName() {
		return goodName;
	}
	public double getGoodPrice() {
		return goodPrice;
	}
	public int getGoodNumber() {
		return goodNumber;
	}
	public double getTotalPrice() {
		totalPrice=goodPrice*goodNumber;
		return totalPrice;
	}
	
}

class Message {
	String storeName;
	private int deviceNumber;//机号
	private int cashierNumber;//收银员
	private int oddNumber;//单机
	
	public int getCashierNumber() {
		return cashierNumber;
	}
	public void setCashierNumber(int cashierNumber) {
		this.cashierNumber = cashierNumber;
	}
	public int getDeviceNumber() {
		return deviceNumber;
	}
	public void setDeviceNumber(int deviceNumber) {
		this.deviceNumber = deviceNumber;
	}
	public int getOddNumber() {
		return oddNumber;
	}
	public void setOddNumber(int oddNumber) {
		this.oddNumber = oddNumber;
	}
	
}

这个是运行效果面向对象编程--超市小票java_第2张图片

你可能感兴趣的:(超市小票java,超市小票)