「java分发饼干」java分发器

博主:adminadmin 2023-03-17 17:14:05 589

今天给各位分享java分发饼干的知识,其中也会对java分发器进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

16块饼干有几种方法可以分给4个朋友

1种。16块饼干有1种方法可以分给4个朋友,因为16的倍数是4,一人4块是最好的分配方式。分发的方式最好的可以平均分配,是最公平的方式。

把10块饼干分给2个小朋友,共有几种不同的分发?

把10块饼干分给两个小朋友,有多种分法,一个小朋友没有一个小朋友10块一个小朋友一块一个小朋友9块,一个小朋友两块,一个小包8块一个小包,三块一个小包,7块一个小包,10块一个小包,6块一个小包5块一个小包,5块

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

public class ShopGoodsDemo {

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分发饼干和java分发器的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。