java第一次作业
可以继续改进,仅供参考(。・_・。):
1.在一个文件中创建一个商品类:
package carlos.way;
/**
* 商品
* @author Mr.zhang
*
*/
public class Shipping {
String no;
String name;
int count;
double price;
double sum;
}
2.在另一个文件中实现发票打印:
package carlos.way;
import java.math.RoundingMode;
import java.util.Scanner;
public class TrueList {
public static void main(String[] args) {
int i = 1;
while (i != -1) {
// 商品报价单
System.out.println("商品信息:");
System.out.println("文明之光:¥59.00");
System.out.println("大学之路:¥72.00");
System.out.println("硅谷之谜:¥59.00");
System.out.println("输入1:开始购物");
Scanner sc1 = new Scanner(System.in);
int no1 = sc1.nextInt();
if (no1 == 1) {
// 订单信息
String[] up = new String[6];
up[0] = "35201747366";
up[1] = "×××";
up[2] = "¥0.00";
up[3] = "¥0.00";
up[4] = "¥0.00";
up[5] = "2020-01-01";
// 文明之光
Shipping first = new Shipping();
first.no = "23494125";
first.name = "文明之光";
System.out.println("请输入第一件物品的购买的数量");
Scanner sc2 = new Scanner(System.in);
first.count = sc2.nextInt();
first.price = 59.00;
first.sum = first.count * first.price;
// 大学之路
Shipping second = new Shipping();
second.no = "23750508";
second.name = "大学之路";
System.out.println("请输入第二件物品的购买的数量");
Scanner sc3 = new Scanner(System.in);
second.count = sc3.nextInt();
second.price = 72.00;
second.sum = second.count * second.price;
// 硅谷之谜
Shipping third = new Shipping();
third.no = "23813967";
third.name = "硅谷之谜";
System.out.println("请输入第三件物品的购买的数量");
Scanner sc4 = new Scanner(System.in);
third.count = sc4.nextInt();
third.price = 72.00;
third.sum = third.count * third.price;
// 结账or退出
System.out.println("输入2:结账,并打印小票");
System.out.println("输入3:不想买了,直接退出");
Scanner sc5 = new Scanner(System.in);
int no2 = sc5.nextInt();
if (no2 == 2) {
// 清单顶部
System.out.println("-----------------当当发货清单"
+ "-----------------");
System.out.println("订单号:" + up[0] + " " + "收件人:"
+ up[1]);
System.out.println("应付款:" + up[2] + " "
+ "运费:" + up[3]);
System.out.println("包装费:" + up[4] + " "
+ "订购日期:" + up[5]);
// 清单中部
System.out
.println("------------------------------------------");
System.out.println("商品ID" + " " + "品名" + " "
+ "数量" + " " + "单价" + " "
+ "金额");
System.out.println(first.no + " " + first.name
+ " " + first.count + " " + first.price
+ " " + first.sum);
System.out.println(second.no + " " + second.name
+ " " + second.count + " " + second.price
+ " " + first.sum);
System.out.println(third.no + " " + third.name
+ " " + third.count + " " + third.price
+ " " + third.sum);
// 总计
int totalCount = first.count + second.count + third.count;
double totalSum = first.sum + second.sum + third.sum;
String workspace = "BZ001";
// 打折条件
System.out
.println("------------------------------------------");
double disCount;
if (totalSum > 0 && totalSum <= 300) {
disCount = 1;
System.out.println("客官,由于您消费未满300元,所以,很遗憾未达到优惠条件。");
} else if (totalSum <= 600) {
disCount = 0.95;
System.out.println("客官,由于您消费满300元,恭喜您获得了95折优惠!^_^");
} else if (totalSum <= 1000) {
disCount = 0.9;
System.out.println("客官,由于您消费满600元,恭喜您获得了9折优惠!^_^");
} else {
disCount = 0.8;
System.out.println("客官,由于您消费满1000元,恭喜您获得了8折优惠!^_^");
}
// 打折后总价
totalSum = totalSum * disCount;
totalSum = Math.round(totalSum);
System.out
.println("------------------------------------------");
System.out.println("总数量:" + totalCount + " " + "小计:"
+ totalSum + " " + "质检台:" + workspace);
System.out
.println("------------------------------------------");
} else {
System.out.println("已退出,谢谢您的光顾!");
}
}
System.out.println("------------------------------------------");
System.out.println("输入0再次购物,输入-1退出购物系统");
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
}
}
}