商品修改java代码 java代码在哪里修改

java 商品 系统 代码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 MapInteger,Market goods=new HashMapInteger, 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; itimes; i) {
System.out.print(" ");
}
System.out.print(row2);
for (int i = 0; i10; 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¥
Java使用字符串生成器来保存购物车中的商品信息,并能实现商品信息的添加、删除以及修改等功能public class Cart {
public StringBuilder data;
public float total;
public Cart(){
data=https://www.04ip.com/post/new StringBuilder();
}
public void buy(Goods g){
g.gtotal=g.gnum*g.gprice;
total=total g.gtotal;
data.append("[");
data.append(g.gname "|");
data.append(g.gprice "|");
data.append(g.gnum "|");//还是竖线看着方便
data.append(g.gtotal);
data.append("]");
}
public void delete(Goods g){
int s=data.indexOf(g.gname);
int e=data.indexOf("]", s);
data.delete(s-1, e 1);
total=total-g.gtotal;//删除商品 , 需要修改总额
}
public void update(Goods g){
data.replace(3, 10, "[" g.gname "|" g.gprice "|" g.gnum "|" g.gtotal);
}
public void show(){
System.out.print("总计金额:"total"") ;
System.out.println(data);
}
}
//Excute类里有点小错误,
//总觉得update方法 不对头 , 商品修改java代码你想怎么做商品修改java代码?
哪个高手帮我把下列JAVA程序加个 修改商品价格和打印数据的功能 。(要最后的代码,有额外加分)哈哈 。。。public class Goods {
private String GoodsNumbers;
private String GoodsName;
private Integer GoodsPrice;
Integer amount;
Goods(){
}
Goods(String GoodsNumbers, String GoodsName ,Integer GoodsPrice,Integer amount){
this.GoodsNumbers=GoodsNumbers;
this.GoodsName=GoodsName;
this.GoodsPrice=GoodsPrice;
this.amount=amount;
}
public String getGoodsNumbers() {
return GoodsNumbers;
}
public void setGoodsNumbers(String GoodsNumbers) {
this.GoodsNumbers = GoodsNumbers;
}
public String getGoodsName() {
return GoodsName;
}
public void setGoodsName(String GoodsName) {
this.GoodsName = GoodsName;
}
public Integer getGoodsPrice() {
return GoodsPrice;
}
public void setGoodsPrice(Integer GoodsPrice) {
this.GoodsPrice = GoodsPrice;
}
public void modifyPrice(Integer price){
this.GoodsPrice=price;
}
public void print(){
System.out.println(" " GoodsNumbers " , " GoodsName " , ¥" GoodsPrice ", 数量:" amount);
}
public static void main(String s[]){
Goods G1 = new Goods();
G1.amount = 111;
G1.setGoodsNumbers("2012325");
G1.setGoodsName("老坛酸菜方便面袋装");
G1.setGoodsPrice(12);
G1.print();
G1.modifyPrice(18);
G1.print();
}
}
加了构造函数,修改钱,打印函数
【商品修改java代码 java代码在哪里修改】商品修改java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java代码在哪里修改、商品修改java代码的信息别忘了在本站进行查找喔 。

    推荐阅读