https://www.myziyuan.com/
- 知了科技
- package entity;public class Market { private int id;//id private int num;//数量 private String goods;//商品 private double price;//价格public Market(int id, int num, String goods, double price) { super(); this.id = id; this.num = num; this.goods = goods; this.price = price; } public int getId() { return id; }public void setId(int id) { this.id = id; }public int getNum() { return num; }public void setNum(int num) { this.num = num; }public String getGoods() { return goods; }public void setGoods(String goods) { this.goods = goods; }public double getPrice() { return price; }public void setPrice(double price) { this.price = price; }public double calc( ){ double sum=price*num; System.out.println("您消费共计:"+sum+"¥"); return sum; }}package test;import java.util.HashMap;import java.util.Map;import java.util.Scanner;import entity.Market;public class Test { private static Map<Integer,Market> goods=new HashMap<Integer, Market>(); public static void main(String[] args) { System.out.println("-------超市计价系统-------"); String goods1="可口可乐"; String goods2="爆米花"; String goods3="益达"; printTable("编号","商品","价格"); printTable("1",goods1,"3.0¥"); printTable("2",goods2,"5.0¥"); printTable("3",goods3,"10.0¥"); goods.put(1, new Market(1, 1, goods1, 3.0)); goods.put(2, new Market(2, 1, goods2, 5.0)); goods.put(3, new Market(3, 1, goods3, 10.0)); Scanner input = new Scanner(System.in); System.out.println("请输入商品的编号:"); int num = input.nextInt(); System.out.println("请输入商品的数量"); int amount = input.nextInt(); Market market = goods.get(num); market.setNum(amount); market.calc(); } private static void printTable(String row1,String row2,String row3 ) { System.out.print(row1); int times=12; if (row2!="商品") { times=5; } for (int i = 0; i < times; i++) { System.out.print(" "); } System.out.print(row2); for (int i = 0; i < 10; i++) { System.out.print(" "); } System.out.print(row3); System.out.println("\n"); }}//测试结果:-------超市计价系统-------编号 商品 价格1 可口可乐 3.0¥2 爆米花 5.0¥3 益达 10.0¥请输入商品的编号:3请输入商品的数量5您消费共计:50.0¥
- 2021-12-28 12:30:53
- 礼品代发源码
- 2021-12-28 12:29:33
- 00萨满祭司00
- 什么是java源代码 怎么查看,你说的java源代码是指编译成的class文件前的java文件。当我们运行.java文件时,它会被系统编译成.class文件,例如Test.java编译之后就是Test.class,源文件就是指Test.java文件,一般部署项目时,有.class文件就可以发布运行了,但是如果想修改这个系统,.class是不能修改的,要有.java文件才能修改也可以上网去下反编译软件,就是能把.class文件大部分还原成.java文件的工具,但不是100%还原,而且如果不是正版的,小心有毒啊,什么的。
- 2021-12-28 12:29:33