网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Java的超市购物代码,java编写一个超市购物的程序

java:小明去超市买东西,所有买到的东西都放在了购物车之中,最后到收银台一起结账。你编出来了是吗求助

public class ShopGoodsDemo {

栖霞网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

public static void main(String[] args) {

ShopCar s1=new ShopCar(5);

s1.add(new EatFood("面包",12.1));

s1.add(new EatFood("辣条",2.4));

s1.add(new EatFood("饼干",22.3));

s1.add(new WashGoods("洗发水",32.5));

s1.add(new WashGoods("卫生纸",22.8));

print(s1.search("饼干"));

System.out.println("=============");

print(s1.getGoods());

}

public static void print(Goods gs[]){

double sum=0;

for(int i=0;igs.length;i++){

if(gs[i]!=null){

//System.out.println(p[i]+",");

System.out.println(gs[i].getName()+","+gs[i].getPrice());

sum=sum+gs[i].getPrice();

}

}

System.out.println("总价格为:"+sum);

}

}

public interface Goods {

public String getName();

public double getPrice();

}

public class EatFood implements Goods{

private String name;

private double price;

public EatFood() {

}

public EatFood(String name, double price) {

super();

this.name = name;

this.price = price;

}

@Override

public double getPrice() {

return this.price;

}

public void setPrice(double price) {

this.price = price;

}

public void setName(String name) {

this.name = name;

}

@Override

public String getName() {

return this.name;

}

}

public class WashGoods implements Goods{

private String name;

private double price;

public WashGoods() {

}

public WashGoods(String name, double price) {

super();

this.name = name;

this.price = price;

}

@Override

public double getPrice() {

return this.price;

}

public void setPrice(double price) {

this.price = price;

}

public void setName(String name) {

this.name = name;

}

@Override

public String getName() {

return this.name;

}

}

public class ShopCar {

private Goods goods[]=null;

private int foot;

//数组的大小由程序外部决定

public ShopCar(int len) {

if(len0){

goods=new Goods[len];

}else{

goods=new Goods[1];

}

}

//判断数组的内容是否已满,未满,则添加

public boolean add(Goods g){

if(this.footthis.goods.length){

this.goods[foot]=g;

foot++;

return true;

}else{

return false;

}

}

//关键字查找

public Goods[] search(String keyword){

Goods go[]=null;

int count=0;

for(int i=0;ithis.goods.length;i++){

if(goods[i]!=null){

if(this.goods[i].getName().indexOf(keyword)!=-1){

count++;

}

}

}

go=new Goods[count];

int f=0;

for(int i=0;ithis.goods.length;i++){

if(goods[i]!=null){

if(this.goods[i].getName().indexOf(keyword)!=-1){

go[f]=this.goods[i];

f++;

}

}

}

return go;

}

//得到全部信息

public Goods[] getGoods(){

return this.goods;

}

}

JAVA作业,还请各位大佬帮帮忙!

超市类

1.超市类

商品类

2.商品类

购物者(客户端)

3.客户端

结果

结果

用JAVA编写程序实现如果超市有购物者所需商品则提示购物者买到了,反之则提示购物者白跑一趟了没买到

作业题?定义一个集合或数组存放所有商品,顾客买的时候判断这个东西是否在集合或者数组中存在就行了

求大神帮忙,谢谢!!!!!(要Java代码)

//第一题的答案:

import java.util.Scanner;

public class test {

public static void main(String[] args)

{

System.out.println("输入购买金额:");

Scanner input=new Scanner(System.in);

double a=input.nextDouble();

System.out.println("输入顾客类型(会员或普通):");

String b=input.next();

if(b=="会员")

{

if(a=100)

{

a=a*0.8;

System.out.println("需付款:"+a);

}

else

{

System.out.println("需付款:"+a);

}

}

if(b=="普通")

{

if(a=200)

{

a=a*0.75;

System.out.println("需付款:"+a);

}

else

{

System.out.println("需付款:"+a);

}

}

}

}

//下面是第二题答案:

public class test {

public static void main(String[] args)

{            

for(int i = 0; i  3; i++) 

for(int x = i + 1; x  3; x++) 

System.out.print(" "); 

for(int y = 0; y  (i + 1) * 2 - 1; y++) 

System.out.print("*"); 

System.out.println(); 

for(int i = 0; i  4; i++) 

for(int x = 0; x  i; x++) 

System.out.print(" "); 

for(int y = i; y  2 * 4 - i - 1; y++) 

System.out.print("*"); 

System.out.println(); 

}

}

}

用JAVA实现超市购物功能,购物时如果购物者所需商品在超市中有则提示购物者买

首先这个需求很奇怪。

购物者买的东西 应该在超市里选的才对。

那么意思就是 万一选的东西 没库存了怎么办?

2种解决方法:

1:每次购买前或者选择的时候,都去后台查询库存,然后提示,这种效率低。但也行就是了

2:在进入这个商品详情页时候查询本商品库存,为0 那就提示没库存了。

java超市管理系统源代码

只写个demo级的例程很好写,但用到生产环境中还得具体分析设计再编码。这种代码网上太多了内,你随便搜下就有了。


当前名称:Java的超市购物代码,java编写一个超市购物的程序
文章起源:http://bjjierui.cn/article/hseses.html

其他资讯