真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

關(guān)于java菜譜結(jié)賬代碼的信息

求java大佬幫忙

import java.util.ArrayList;

成都創(chuàng)新互聯(lián)專注于福山企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),成都商城網(wǎng)站開發(fā)。福山網(wǎng)站建設(shè)公司,為福山等地區(qū)提供建站服務(wù)。全流程按需開發(fā)網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

import java.util.Arrays;

import java.util.List;

public class Recipe {

private String name; //菜譜名稱

private String style; //菜系 如:川菜、湘菜等

private int time; //烹飪時(shí)長(zhǎng) 分鐘

private String[] food; //食材

private String[] step; //操作步驟

public Recipe() {

}

public Recipe(String name, String style, int time, String[] food, String[] step) {

this.name = name;

this.style = style;

this.time = time;

this.food = food;

this.step = step;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getStyle() {

return style;

}

public void setStyle(String style) {

this.style = style;

}

public int getTime() {

return time;

}

public void setTime(int time) {

this.time = time;

}

public String[] getFood() {

return food;

}

public void setFood(String[] food) {

this.food = food;

}

public String[] getStep() {

return step;

}

public void setStep(String[] step) {

this.step = step;

}

@Override

public String toString() {

String foods="";

for (String f : food) {

foods+=f+" ";

}

String steps="";

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

steps += (i+1)+"."+step[i];

if(i!=step.length-1){

steps+=";";

}

}

return "菜譜名稱:" + name +

"\n菜系:" + style +

"\n時(shí)長(zhǎng):" + time +

"\n所需食材:" + foods +

"\n操作步驟:" + steps;

}

public static void print(Recipe[] recipes){

for (Recipe recipe : recipes) {

System.out.println(recipe);

}

}

public static Recipe[] searchRecipesContainName(Recipe[] recipes, String name){

ListRecipe list=new ArrayListRecipe();

for (Recipe recipe : recipes) {

if(recipe.getName().contains(name)){

list.add(recipe);

}

}

return list.toArray(new Recipe[list.size()]);

}

public static Recipe[] searchRecipes(Recipe[] recipes, String style){

ListRecipe list=new ArrayListRecipe();

for (Recipe recipe : recipes) {

if(recipe.getStyle().equals(style)){

list.add(recipe);

}

}

return list.toArray(new Recipe[list.size()]);

}

public static Recipe[] searchRecipeLessThan(Recipe[] recipes, int time){

ListRecipe list=new ArrayListRecipe();

for (Recipe recipe : recipes) {

if(recipe.getTime()time){

list.add(recipe);

}

}

return list.toArray(new Recipe[list.size()]);

}

public static Recipe[] searchRecipeContainsFood(Recipe[] recipes, String food){

ListRecipe list=new ArrayListRecipe();

for (Recipe recipe : recipes) {

for (String s : recipe.getFood()) {

if(s.equals(food)){

list.add(recipe);

}

}

}

return list.toArray(new Recipe[list.size()]);

}

public static void main(String[] args) {

//存儲(chǔ)5個(gè)菜譜的信息

Recipe[] recipes=new Recipe[5];

recipes[0]=new Recipe("醬牛肉","家常菜",120,

new String[]{

"牛腱子",

"黃豆醬油",

"黃酒",

"冰糖"

},

new String[]{

"準(zhǔn)備好主要食材",

"加入食材慢燉兩至三小時(shí)"

});

recipes[1]=new Recipe("紅燒牛肉","家常菜",120,

new String[]{

"牛腩",

"牛筋",

"生抽",

"冰糖"

},new String[]{

"準(zhǔn)備好主要食材",

"加入食材慢燉兩至三小時(shí)"

});

recipes[2]=new Recipe("小雞燉蘑菇","湘菜",100,

new String[]{

"小雞",

"蘑菇"

},

new String[]{

"準(zhǔn)備好主要食材",

"加入食材慢燉兩至三小時(shí)"

});

recipes[3]=new Recipe("地三鮮","川菜",25,

new String[]{

"茄子",

"辣椒"

},

new String[]{

"準(zhǔn)備好主要食材",

"加入食材慢燉"

});

recipes[4]=new Recipe("西紅柿","湘菜",20,

new String[]{

"西紅柿",

"味達(dá)美醬油"

},

new String[]{

"準(zhǔn)備好主要食材",

"加入食材慢燉"

});

System.out.println("找到所有名稱中包含牛肉的菜譜:");

Recipe[] result_1 = searchRecipesContainName(recipes, "牛肉");

print(result_1);

System.out.println("\n希望查找所有湘菜的菜譜:");

Recipe[] result_2=searchRecipes(recipes,"湘菜");

print(result_2);

System.out.println("\n查找烹飪時(shí)長(zhǎng)小于30分鐘的菜譜:");

Recipe[] result_3=searchRecipeLessThan(recipes,30);

print(result_3);

System.out.println("\n查找包含西紅柿的菜譜:");

Recipe[] result_4=searchRecipeContainsFood(recipes,"西紅柿");

print(result_4);

}

}

java新手求大神解答。主要求代碼,有思路但是寫不出啊。

import?java.util.HashMap;

import?java.util.Iterator;

import?java.util.Map;

import?java.util.Scanner;

enum?Huo?{

TX(1,?"T恤",?245),?WQX(2,?"網(wǎng)球鞋",?570),?WQP(3,?"網(wǎng)球拍",?320);

private?int?id;

private?String?name;

private?double?price;

private?Huo(int?id,?String?name,?double?price)?{

this.id?=?id;

this.name?=?name;

this.price?=?price;

}

public?int?getId()?{

return?id;

}

public?String?getName()?{

return?name;

}

public?double?getPrice()?{

return?price;

}

public?static?Huo?getById(int?id)?{

for?(Huo?item?:?Huo.values())?{

if?(item.id?==?id)?{

return?item;

}

}

return?null;

}

}

public?class?Test?{

private?static?MapInteger,?Integer?countMap?=?new?HashMapInteger,?Integer();

private?static?double?sum?=?0;

public?static?void?main(String?args[])?{

Scanner?in?=?new?Scanner(System.in);

while?(true)?{

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

System.out.println("請(qǐng)選擇購(gòu)買的商品編號(hào):");

for?(Huo?item?:?Huo.values())?{

System.out.print(item.getId()?+?":"?+?item.getName()?+?"??");

}

System.out.println();

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

System.out.print("輸入購(gòu)買商品編號(hào):");

int?id?=?in.nextInt();

System.out.print("輸入購(gòu)買商品數(shù)量:");

int?count?=?in.nextInt();

Integer?tmp?=?countMap.get(id);

if?(tmp?==?null)?{

tmp?=?0;

}

countMap.put(id,?tmp?+?count);

show();

while?(true)?{

System.out.print("是否繼續(xù)(y/n):");

String?jixu?=?in.next();

if?("Y".equalsIgnoreCase(jixu))?{

break;

}?else?if?("N".equalsIgnoreCase(jixu))?{

System.out.print("請(qǐng)支付:");

double?zhifu?=?in.nextDouble();

System.out.println("應(yīng)付金額:"?+?sum);

System.out.println("客戶支付:"?+?zhifu);

System.out.println("找錢:"?+?(zhifu?-?sum));

System.exit(0);

}?else?{

System.out.print("輸入錯(cuò)誤");

}

}

}

}

private?static?void?show()?{

IteratorInteger?it?=?countMap.keySet().iterator();

while?(it.hasNext())?{

Integer?key?=?it.next();

Integer?count?=?countMap.get(key);

Huo?huo?=?Huo.getById(key);

double?heji?=?huo.getPrice()?*?count;

System.out.println(huo.getName()?+?"¥"?+?huo.getPrice()?+?"???數(shù)量:"?+?count?+?"????合計(jì):"?+?heji);

sum?+=?heji;

}

}

}

java:小明去超市買東西,所有買到的東西都放在了購(gòu)物車之中,最后到收銀臺(tái)一起結(jié)賬。你編出來(lái)了是嗎求助

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("洗發(fā)水",32.5));

s1.add(new WashGoods("衛(wèi)生紙",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("總價(jià)格為:"+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;

//數(shù)組的大小由程序外部決定

public ShopCar(int len) {

if(len0){

goods=new Goods[len];

}else{

goods=new Goods[1];

}

}

//判斷數(shù)組的內(nèi)容是否已滿,未滿,則添加

public boolean add(Goods g){

if(this.footthis.goods.length){

this.goods[foot]=g;

foot++;

return true;

}else{

return false;

}

}

//關(guān)鍵字查找

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購(gòu)物結(jié)算,卡在不懂do...while跳出循環(huán)和最后的總金額。求解決,謝謝

剛幫你調(diào)測(cè)了一下,當(dāng)你輸入"n"的時(shí)候,已經(jīng)跳出循環(huán)了,只不過(guò)你沒(méi)有輸出提示,以為沒(méi)出來(lái),

又輸入字符了所有報(bào)錯(cuò)了,應(yīng)該是輸入金額的,我?guī)湍慵恿讼螺敵瞿憧梢钥聪陆Y(jié)果;

public static void main(String args[]){

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

System.out.println("");

System.out.println("請(qǐng)選擇購(gòu)買商品編號(hào):");

System.out.println("1.T恤(¥245.0) 網(wǎng)球鞋(¥570.0) 網(wǎng)球拍(¥500.0)");

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

System.out.println("");

double s=0;

String d;

do{

System.out.println("請(qǐng)輸入商品編號(hào):");

Scanner input=new Scanner(System.in);

int a=input.nextInt();

if(a==1){

System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");

int b=input.nextInt();

double c=245*b;

System.out.println("T恤¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);

s=s+c;

}

else if(a==2){

System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");

int b=input.nextInt();

double c=570*b;

System.out.println("網(wǎng)球鞋¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);

s=s+c;

}

else if(a==3){

System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");

int b=input.nextInt();

double c=500*b;

System.out.println("網(wǎng)球拍¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);

s=s+c;

}

else {System.out.println("無(wú)此商品");}

System.out.println("否繼續(xù)(y/n)");

d=input.next();

}while(d.equals("y"));

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

System.out.println("=====輸入金額=====");

Scanner input=new Scanner(System.in);

int x=input.nextInt();

double m=s*0.8;

System.out.println("折扣:0.8");

System.out.println("應(yīng)付金額:"+m);

System.out.println("實(shí)際金額:"+x);

double p=x-m;

System.out.println("找錢:"+p);

}


分享標(biāo)題:關(guān)于java菜譜結(jié)賬代碼的信息
文章網(wǎng)址:http://weahome.cn/article/doopgoh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部