Java: study demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | /** * 1.某小伙想定一份外卖,商家的优惠方式如下: * 鱼香肉丝ShreddedPork单点24元,油炸花生米FriedPeanuts单点8元,米饭 CookedRice单点3元。 * 订单满30元8折优惠。 discountedPrice * 鱼香肉丝优惠价16元,但是优惠价和折扣不能同时使用。preferentialPrice * 那么这个小伙要点这三样东西,最少要花多少钱? * */ package org.example; /** *就餐食物实体类 * @author geovindu * @version 1.0 * * */ public class FoodInfo { /** *鱼香肉丝价 * */ private int shreddedPork; /** * 鱼香肉丝优惠价 * */ private int preferentialPork; /** *油炸花生米价 * */ private int friedPeanuts; /** *米饭价 * */ private int cookedRice; /** *折扣价 * */ private double discountedPrice; /** *优惠价 * * */ private double preferentialPrice; /** *是否选择折扣 * * */ private boolean isDiscount; /** * 选择优惠价还是折扣价 * 真为折扣价 * */ private boolean checkDiscount; /** * * */ public FoodInfo() { } /** * * */ public FoodInfo( int shreddedPork, int friedPeanuts, int cookedRice, double discountedPrice, double preferentialPrice, boolean isDiscount) { this .shreddedPork=shreddedPork; this .preferentialPork= 16 ; this .friedPeanuts=friedPeanuts; this .cookedRice=cookedRice; this .discountedPrice=discountedPrice; this .preferentialPork=preferentialPork; this .isDiscount=isDiscount; } /** *鱼香肉丝价 * @param shreddedPork 输入参数 * * */ public void setShreddedPork( int shreddedPork) { this .shreddedPork = shreddedPork; } /** *鱼香肉丝价 * */ public int getShreddedPork() { return shreddedPork; } /** *输入油炸花生米价 * @param friedPeanuts 输入参数 * */ public void setFriedPeanuts( int friedPeanuts) { this .friedPeanuts = friedPeanuts; } /** *返回油炸花生米价 * @return 返回油炸花生米价 * */ public int getFriedPeanuts() { return friedPeanuts; } /** *设置米饭价格 * @param cookedRice 输入参数 * */ public void setCookedRice( int cookedRice) { this .cookedRice = cookedRice; } /** *返回米饭价 * @return 返顺米饭价格 * */ public int getCookedRice() { return cookedRice; } /** *设置折扣价 * @param discountedPrice 输入参数 * * */ public void setDiscountedPrice( double discountedPrice) { this .discountedPrice = discountedPrice; } /** *折扣价格 * @return 返回折扣价格 * */ public double getDiscountedPrice() { return discountedPrice; } /** *设置优惠价 * @param preferentialPrice 输入参数 * */ public void setPreferentialPrice( double preferentialPrice) { this .preferentialPrice = preferentialPrice; } /** *优惠价 * @return 返回优惠价 * */ public double getPreferentialPrice() { return preferentialPrice; } /** *设置是否折扣价 * @param discount 输入参数 * */ public void setDiscount( boolean discount) { isDiscount = discount; } /** *是否折扣价 * @return 返回折扣价 * */ public boolean getIsDiscount() { return isDiscount; } /** *鱼香肉丝优惠价 * @param preferentialPork 输入参数 * * */ public void setPreferentialPork( int preferentialPork) { this .preferentialPork = preferentialPork; } /** *香肉丝优惠价 * @return 返回鱼香肉丝优惠价 * * */ public int getPreferentialPork() { return preferentialPork; } public void setCheckDiscount( boolean checkDiscount) { this .checkDiscount = checkDiscount; } public boolean isCheckDiscount() { return checkDiscount; } /** *自然实际选择的最低的价格 * @return 返回自然选择最低价格 * */ public double getPrice() { double price; double issum= this .shreddedPork+ this .friedPeanuts+ this .cookedRice; double psum= this .preferentialPork+ this .friedPeanuts+ this .cookedRice; //总价大于30可以有折扣 if (issum> 30 ) { if (psum<(issum* 0.8 )) { setCheckDiscount( false ); price=psum; } else { setCheckDiscount( true ); price=issum* 0.8 ; } } else //不大于30 无折扣 { if (psum<issum) { setCheckDiscount( false ); price=psum; } else { setCheckDiscount( true ); price=issum; } } return price; } } /** * 2.身高是具有遗传性的,子女的身高和父母的身高有一定的关系。假定,父母和子女的身高遗传关系如下: * * 儿子身高(厘米)=(父亲身高+母亲身高) ×1.08÷2 * * 女儿身高(厘米)=(父亲身高×0.923+母亲身高) ÷2 * * 现有父亲身高177CM,母亲身高165CM。求子女身高分别预计为多少? * **/ package org.example; /** * 父母实体类 * @author geovindu * @version 1.0 * */ public class ParentsInfo { /** * * * */ private int fatherBodyHeight; /** * * * */ private int motherBodyHeight; public ParentsInfo() {} /** * * @param fatherBodyHeight 输入父亲身高 * @param motherBodyHeight 输入母亲身高 * * */ public ParentsInfo( int fatherBodyHeight, int motherBodyHeight) { this .fatherBodyHeight=fatherBodyHeight; this .motherBodyHeight=motherBodyHeight; } /** * 设置父样身高 * @param fatherBodyHeight 设置输入父亲身高参数 * * */ public void setFatherBodyHeight( int fatherBodyHeight) { this .fatherBodyHeight= fatherBodyHeight; } /** * 得到父亲身高 * @param * @return 得到父亲身高 * */ public int getFatherBodyHeight() { return fatherBodyHeight; } /** *设置母亲身高 * @param motherBodyHeight 输入母亲身高参数 * * */ public void setMotherBodyHeight( int motherBodyHeight) { this .motherBodyHeight= motherBodyHeight; } /** *得到母亲身高 * @return 返回母亲身高 * */ public int getMotherBodyHeight() { return motherBodyHeight; } } /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; /** *儿女的身高 * @author geovindu * @version 1.0 * */ public class SonDaughterInfo { /** * * */ private double sonBodyHeight; /** * * */ private double daughterBodyHeight; public SonDaughterInfo(){ } /** * * @param sonBodyHeight 输入儿子身高 * @param daughterBodyHeight 输入女儿身高 * */ public SonDaughterInfo( double sonBodyHeight, double daughterBodyHeight) { this .sonBodyHeight=sonBodyHeight; this .daughterBodyHeight=daughterBodyHeight; } /** * * @param sonBodyHeight 输入儿子的身高 * * */ public void setSonBodyHeight( double sonBodyHeight) { this .sonBodyHeight = sonBodyHeight; } /** * * @return 返回儿子身高 * */ public double getSonBodyHeight() { return sonBodyHeight; } /** * * @param daughterBodyHeight 输入女儿的身高 * * */ public void setDaughterBodyHeight( double daughterBodyHeight) { this .daughterBodyHeight = daughterBodyHeight; } /** * * @return 返回女儿的身高 * */ public double getDaughterBodyHeight() { return daughterBodyHeight; } /** * 得到女儿的身高 * @param parentsInfo 输入父母的资料实体类 * @return 得到女儿的身高 * */ public double getDaughterHeight(ParentsInfo parentsInfo) { double height= (parentsInfo.getFatherBodyHeight()* 0.923 +parentsInfo.getMotherBodyHeight())/ 2 ; return height; } /** *得到儿子的身高 * @param parentsInfo 输入父母的资料的实体类 * @return 得到儿子的身高 * */ public double getSonHeight(ParentsInfo parentsInfo) { double height=(parentsInfo.getFatherBodyHeight()+parentsInfo.getMotherBodyHeight())* 1.08 / 2 ; return height; } } /** *3.红茶妹妹有21元钱,她攒了几天钱之后自己的钱比原来的两倍还多三块。绿茶妹妹有24元钱, * 她攒了几天钱之后自己的钱正好是原来的两倍。 * 那么红茶和绿茶现在的钱一样多,请问对么? * * */ package org.example; /** * * */ public class TeaMoneyInfo { /** *红茶女原价格 * */ private int redTeaSister; /** *绿茶女原价格 * */ private int greenTeaSister; /** *红茶女计算的价 * */ private int redMoney; /** *绿茶女计算的价 * */ private int greenMoney; public TeaMoneyInfo() { } public TeaMoneyInfo( int redTeaSister, int greenTeaSister, int redMoney, int greenMoney) { this .redTeaSister=redTeaSister; this .greenTeaSister=greenTeaSister; this .redMoney=redMoney; this .greenMoney=greenMoney; } /** * * */ public void setRedTeaSister( int redTeaSister) { this .redTeaSister = redTeaSister; } /** * * */ public int getRedTeaSister() { return redTeaSister; } /** * * */ public void setGreenTeaSister( int greenTeaSister) { this .greenTeaSister = greenTeaSister; } /** * * */ public int getGreenTeaSister() { return greenTeaSister; } /** * * */ public void setRedMoney( int redMoney) { this .redMoney = redMoney; } /** * * */ public int getRedMoney() { return redMoney; } /** * * */ public void setGreenMoney( int greenMoney) { this .greenMoney = greenMoney; } /** * * */ public int getGreenMoney() { return greenMoney; } public String getMoney() { String str= "" ; this .redMoney= this .redTeaSister* 2 + 3 ; this .greenMoney= this .greenTeaSister* 2 ; if ( this .redMoney== this .greenMoney) { str= "两位妹妹一样多!为:" + this .redMoney; } else { if ( this .redMoney> this .greenMoney) { str= "红茶妹妹多,红茶妹妹为:" + this .redMoney+ " 绿茶妹妹为:" + this .greenMoney; } else { System.out.println( "绿茶妹妹多,红茶妹妹为:" + this .redMoney+ " 绿茶妹妹为:" + this .greenMoney); } } return str; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; /** * 儿女枚举类 * */ public enum SonDaughter { /** * 儿子 * */ Son, /** * 女儿 * */ Daughter; } /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; /** * 业务处理类 * @author geovindu * @version 1.0 * * */ public class FoodDal { /** *业务处理 * @param foodInfo * @return * */ public double getDiscount(FoodInfo foodInfo) { double price; if (foodInfo.getIsDiscount()== true ) { if (foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice() > 30 ) { price = (foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice() )* 0.8 ; foodInfo.setDiscountedPrice((foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice()) * 0.8 ); } else { price = foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice(); foodInfo.setDiscountedPrice(foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice()); } } else { price= foodInfo.getPreferentialPork()+ foodInfo.getFriedPeanuts()+ foodInfo.getCookedRice(); foodInfo.setPreferentialPrice(foodInfo.getPreferentialPork()+ foodInfo.getFriedPeanuts()+ foodInfo.getCookedRice()); } return price; } } /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; /** *求儿女身高业务操作类 * @author geovindu * @version 1.0 * * */ public class SonDaughterDal { /** * * */ public SonDaughterInfo getInfoHeight(ParentsInfo parentsInfo) { SonDaughterInfo sonDaughterInfo= new SonDaughterInfo(); double height=(parentsInfo.getFatherBodyHeight()+parentsInfo.getMotherBodyHeight())* 1.08 / 2 ; sonDaughterInfo.setSonBodyHeight(height); sonDaughterInfo.getDaughterHeight(parentsInfo); sonDaughterInfo.getSonHeight(parentsInfo); double height1=(parentsInfo.getFatherBodyHeight()* 0.923 +parentsInfo.getMotherBodyHeight())/ 2 ; sonDaughterInfo.setDaughterBodyHeight(height1); return sonDaughterInfo; } } /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; /** * 茶妹妹的处理业务 * @author geovindu * @version 1.0 * * */ public class TeaMoneyDal { /** * 得到谁钱的简要描述 * * */ public String getMoney(TeaMoneyInfo teaMoneyInfo) { String getStr= "" ; teaMoneyInfo.setRedMoney(teaMoneyInfo.getRedTeaSister()* 2 + 3 ); teaMoneyInfo.setGreenMoney(teaMoneyInfo.getGreenTeaSister()* 2 ); if (teaMoneyInfo.getRedMoney()==teaMoneyInfo.getGreenMoney()) { getStr= "两位妹妹一样多!为:" +teaMoneyInfo.getRedMoney(); } else { if (teaMoneyInfo.getRedMoney()>teaMoneyInfo.getGreenMoney()) { getStr= "红茶妹妹多,红茶妹妹为:" +teaMoneyInfo.getRedMoney()+ " 绿茶妹妹为:" +teaMoneyInfo.getGreenMoney(); } else { getStr= "绿茶妹妹多,红茶妹妹为:" +teaMoneyInfo.getRedMoney()+ " 绿茶妹妹为:" +teaMoneyInfo.getGreenMoney(); } } return getStr; } } |
调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | /** * geovindu,Geovin Du * 2023-03-12 * */ package org.example; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { /** * 鱼香肉丝全价 * */ int fish= 24 ; /** *鱼香肉丝优惠价 * */ int fish1= 16 ; /** *油炸花生米 * */ int peanut= 8 ; /** *米饭 * */ int rise= 3 ; /** *全价 * */ int sum= 0 ; /** *鱼香优惠全价 * */ int sum1= 0 ; /** * * */ sum=fish+peanut+rise; //总和价,便打折扣 Discount sum1=fish1+peanut+rise; //优惠鱼香肉丝价 Preferential /** *折扣价 * */ double price= 0 ; /** *优惠价 * */ double price2= 0 ; if (sum> 30 ) { price=sum*( 1 - 0.2 ); } else { price=sum; } price2=sum1; System.out.println( "优惠价:" +price2+ "; 折扣价:" +price); if (price2>price) { System.out.println( "选择折扣" ); } else { System.out.println( "选择鱼香肉丝优惠价" ); } price=getDiscount(fish,peanut,rise, true ); price2=getDiscount(fish1,peanut,rise, false ); System.out.println( "方法 优惠价:" +price2+ "; 折扣价:" +price); if (price2>price) { System.out.println( "方法 选择折扣" );} else { System.out.println( "方法 选择鱼香肉丝优惠价" );} //身高 int father= 177 ; int mother= 165 ; double son=getBodyHeight(father,mother,SonDaughter.Son); System.out.println( "生儿子身高" +son); double daughter=getBodyHeight(father,mother,SonDaughter.Daughter); System.out.println( "生女儿身高" +daughter); int redtea= 21 ; int greentea= 24 ; boolean istea=getMoney(redtea,greentea); if (istea) { System.out.println( "一样多" ); } else { System.out.println( "不一样多" ); } //实体类操作 //不折扣 FoodInfo foodInfoIsNo= new FoodInfo(); foodInfoIsNo.setDiscount( false ); foodInfoIsNo.setShreddedPork( 24 ); foodInfoIsNo.setPreferentialPork( 16 ); foodInfoIsNo.setFriedPeanuts( 8 ); foodInfoIsNo.setCookedRice( 3 ); double noDiscountPrice= new FoodDal().getDiscount(foodInfoIsNo); String ischeck=foodInfoIsNo.isCheckDiscount()? "折扣价" : "优惠价" ; System.out.println(noDiscountPrice+ "/ 实体操作" +foodInfoIsNo.getPrice()+ "/" +ischeck); //折扣 FoodInfo foodInfo= new FoodInfo(); foodInfo.setDiscount( true ); foodInfo.setShreddedPork( 24 ); foodInfo.setPreferentialPork( 16 ); foodInfo.setFriedPeanuts( 8 ); foodInfo.setCookedRice( 3 ); double discountPrice= new FoodDal().getDiscount(foodInfo); ischeck=foodInfo.isCheckDiscount()? "折扣价" : "优惠价" ; System.out.println(discountPrice+ "/ 实体操作 " +foodInfo.getPrice()+ "/" +ischeck); if (noDiscountPrice>discountPrice) { System.out.println( "业务操作方法 选择折扣,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfo.getPreferentialPrice()); } else { System.out.println( "业务操作方法 选择鱼香肉丝优惠价,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfoIsNo.getPreferentialPrice()); } //1 ParentsInfo parentsInfo= new ParentsInfo(); SonDaughterInfo sonDaughterInfo= new SonDaughterInfo(); parentsInfo.setFatherBodyHeight( 177 ); parentsInfo.setMotherBodyHeight( 165 ); System.out.println( "女儿身高:" +sonDaughterInfo.getDaughterHeight(parentsInfo)+ " 儿子身高:" +sonDaughterInfo.getSonHeight(parentsInfo)); //2 SonDaughterInfo sonDaughter= new SonDaughterInfo(); sonDaughter= new SonDaughterDal().getInfoHeight(parentsInfo); System.out.println( "业务操作 女儿身高:" +sonDaughter.getDaughterBodyHeight()+ " 儿子身高:" +sonDaughter.getSonBodyHeight()); //1 TeaMoneyInfo teaMoneyInfo= new TeaMoneyInfo(); teaMoneyInfo.setRedTeaSister( 21 ); teaMoneyInfo.setGreenTeaSister( 24 ); System.out.println(teaMoneyInfo.getMoney()); //2 TeaMoneyDal teaMoneyDal= new TeaMoneyDal(); System.out.println( "业务操作 " +teaMoneyDal.getMoney(teaMoneyInfo)); } /** * A比B的大的逻辑结果: 真 否则为假 * @param a 输入参数 * @param b 输入参数 * @return 返回逻辑真假 * */ private static boolean getMore( int a, int b) { boolean isok= false ; if (a>b) { isok= true ; } else { isok= false ; } System.out.println( "a=" +a+ ", b=" +b); return isok; } /** * 计算折扣价和优惠价 * @param fish 鱼香肉丝价 价格 * @param peanut 油炸花生米 价格 * @param rise 米饭价格 * @param isDiscount 是否选择折扣价,否则是优惠价 * @return 返回价格 * */ private static double getDiscount( int fish, int peanut, int rise, boolean isDiscount) { int disfish= 16 ; //鱼香肉丝优惠价 double price= 0 ; if (isDiscount== true ) { if ((fish+peanut+rise)> 30 ) price=(fish+peanut+rise)* 0.8 ; else price=fish+peanut+rise; } else { price=(disfish+peanut+rise); } return price; } /** * 根据父母身高求儿女的身高方法 * @param fatherBodyHeight 父亲身高 * @param motherBodyHeight 母亲身高 * @param sonDaughter 输入选择是儿子还是女儿 * @return 返回身高 * */ private static double getBodyHeight( int fatherBodyHeight, int motherBodyHeight, SonDaughter sonDaughter) { double bodyHeithg= 0 ; if (sonDaughter==SonDaughter.Son) { bodyHeithg=(fatherBodyHeight+motherBodyHeight)* 1.08 / 2 ; } else { bodyHeithg=(fatherBodyHeight* 0.923 +motherBodyHeight)* 2 ; } return bodyHeithg; } /** * 红茶妹和绿茶妹是否一样多,真为一样多,假为不一样多 * @param redTeaSister 红茶妹妹的初始钱 * @param greenTeaSister 绿茶妹妹的初始钱 * @return 返回真假 * */ private static boolean getMoney( int redTeaSister, int greenTeaSister) { boolean isMore= false ; int redmoney= 0 ; int greenmoney= 0 ; redmoney=redTeaSister* 2 + 3 ; greenmoney=greenTeaSister* 2 ; if (redmoney==greenmoney) { isMore= true ; System.out.println( "两位妹妹一样多!为:" +redmoney); } else { if (redmoney>greenmoney) { System.out.println( "红茶妹妹多,红茶妹妹为:" +redmoney+ " 绿茶妹妹为:" +greenmoney); } else { System.out.println( "绿茶妹妹多,红茶妹妹为:" +redmoney+ " 绿茶妹妹为:" +greenmoney); } isMore= false ; } return isMore; } } |
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 优惠价: 27.0 ; 折扣价: 28.0 选择鱼香肉丝优惠价 方法 优惠价: 27.0 ; 折扣价: 28.0 方法 选择鱼香肉丝优惠价 生儿子身高 184.68 生女儿身高 656.742 绿茶妹妹多,红茶妹妹为: 45 绿茶妹妹为: 48 不一样多 27.0 / 实体操作 27.0 /优惠价 28.0 / 实体操作 27.0 /优惠价 业务操作方法 选择鱼香肉丝优惠价,折扣价为: 28.0 优惠价为: 27.0 女儿身高: 164.1855 儿子身高: 184.68 业务操作 女儿身高: 164.1855 儿子身高: 184.68 绿茶妹妹多,红茶妹妹为: 45 绿茶妹妹为: 48 业务操作 绿茶妹妹多,红茶妹妹为: 45 绿茶妹妹为: 48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | /** * 版权所有 2022 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc FoodDal.java * Interface * Record * Annotation * Enum * */ package Dal; import Model.*; /** * 业务处理类 * @author geovindu * @version 1.0 * * */ public class FoodDal { /** *业务处理 * @param foodInfo * @return * */ public double getDiscount(FoodInfo foodInfo) { double price; if (foodInfo.getIsDiscount()== true ) { if (foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice() > 30) { price = (foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice() )* 0.8; foodInfo.setDiscountedPrice((foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice()) * 0.8); } else { price = foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice(); foodInfo.setDiscountedPrice(foodInfo.getShreddedPork() + foodInfo.getFriedPeanuts() + foodInfo.getCookedRice()); } } else { price= foodInfo.getPreferentialPork()+ foodInfo.getFriedPeanuts()+ foodInfo.getCookedRice(); foodInfo.setPreferentialPrice(foodInfo.getPreferentialPork()+ foodInfo.getFriedPeanuts()+ foodInfo.getCookedRice()); } return price; } } /** * 版权所有 2023 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc FoodBll.java * Interface * Record * Annotation * Enum * */ package Bll; import Model.FoodInfo; import Dal.FoodDal; /** *购买快餐自动最优选择购买方式 * @author geovindu * @version 1.0 * * */ public class FoodBll { /** *直接在实体类业务操作方式 */ public void foodFunction() { FoodInfo foodInfoIsNo = new FoodInfo(); foodInfoIsNo.setDiscount( false ); foodInfoIsNo.setShreddedPork(24); foodInfoIsNo.setPreferentialPork(16); foodInfoIsNo.setFriedPeanuts(8); foodInfoIsNo.setCookedRice(3); //double noDiscountPrice=new FoodDal().getDiscount(foodInfoIsNo); String isCheck = foodInfoIsNo.isCheckDiscount() ? "应选择折扣价" : "应选择优惠价" ; System. out .println( "实际价格选择" + foodInfoIsNo.getPrice() + "/" + isCheck); } /** *直接在实体类业务操作方式 * @param shreddedPork 输入参数:鱼香肉丝价 * @param preferentialPork 输入参数:鱼香肉丝优惠价 * @param friedPeanuts 输入参数:油炸花生米价 * @param cookedRice 输入参数:米饭价 */ public void foodFunction( int shreddedPork, int preferentialPork, int friedPeanuts, int cookedRice) { FoodInfo foodInfoIsNo = new FoodInfo(); foodInfoIsNo.setDiscount( false ); foodInfoIsNo.setShreddedPork(shreddedPork); foodInfoIsNo.setPreferentialPork(preferentialPork); foodInfoIsNo.setFriedPeanuts(friedPeanuts); foodInfoIsNo.setCookedRice(cookedRice); //double noDiscountPrice=new FoodDal().getDiscount(foodInfoIsNo); String isCheck = foodInfoIsNo.isCheckDiscount() ? "应选择折扣价" : "应选择优惠价" ; System. out .println( "实际价格选择" + foodInfoIsNo.getPrice() + "/" + isCheck); } /** * 另用业务操作方式选择 * * */ public void foodCheck() { //不折扣 FoodInfo foodInfoIsNo= new FoodInfo(); foodInfoIsNo.setDiscount( false ); foodInfoIsNo.setShreddedPork(24); foodInfoIsNo.setPreferentialPork(16); foodInfoIsNo.setFriedPeanuts(8); foodInfoIsNo.setCookedRice(3); double noDiscountPrice= new FoodDal().getDiscount(foodInfoIsNo); //折扣 FoodInfo foodInfo= new FoodInfo(); foodInfo.setDiscount( true ); foodInfo.setShreddedPork(24); foodInfo.setPreferentialPork(16); foodInfo.setFriedPeanuts(8); foodInfo.setCookedRice(3); double discountPrice= new FoodDal().getDiscount(foodInfo); if (noDiscountPrice>discountPrice) { System. out .println( "业务操作方法 选择折扣方式,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfo.getPreferentialPrice()); } else { System. out .println( "业务操作方法 选择鱼香肉丝优惠价方式,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfoIsNo.getPreferentialPrice()); } } /** * 另用业务操作方式选择 * @param shreddedPork 输入参数:鱼香肉丝价 * @param preferentialPork 输入参数:鱼香肉丝优惠价 * @param friedPeanuts 输入参数:油炸花生米价 * @param cookedRice 输入参数:米饭价 * */ public void foodCheck( int shreddedPork, int preferentialPork, int friedPeanuts, int cookedRice) { //不折扣 FoodInfo foodInfoIsNo= new FoodInfo(); foodInfoIsNo.setDiscount( false ); foodInfoIsNo.setShreddedPork(shreddedPork); foodInfoIsNo.setPreferentialPork(preferentialPork); foodInfoIsNo.setFriedPeanuts(friedPeanuts); foodInfoIsNo.setCookedRice(cookedRice); double noDiscountPrice= new FoodDal().getDiscount(foodInfoIsNo); //折扣 FoodInfo foodInfo= new FoodInfo(); foodInfo.setDiscount( true ); foodInfo.setShreddedPork(24); foodInfo.setPreferentialPork(16); foodInfo.setFriedPeanuts(8); foodInfo.setCookedRice(3); double discountPrice= new FoodDal().getDiscount(foodInfo); if (noDiscountPrice>discountPrice) { System. out .println( "业务操作方法 选择折扣方式,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfo.getPreferentialPrice()); } else { System. out .println( "业务操作方法 选择鱼香肉丝优惠价方式,折扣价为:" +foodInfo.getDiscountedPrice()+ " 优惠价为:" +foodInfoIsNo.getPreferentialPrice()); } } } /** * 版权所有 2022 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc SonDaughterDal.java * Interface * Record * Annotation * Enum * */ package Dal; import Model.*;; /** *求儿女身高业务操作类 * @author geovindu * @version 1.0 * * */ public class SonDaughterDal { /** * * */ public SonDaughterInfo getInfoHeight(ParentsInfo parentsInfo) { SonDaughterInfo sonDaughterInfo= new SonDaughterInfo(); double height=(parentsInfo.getFatherBodyHeight()+parentsInfo.getMotherBodyHeight())*1.08/2; sonDaughterInfo.setSonBodyHeight(height); sonDaughterInfo.getDaughterHeight(parentsInfo); sonDaughterInfo.getSonHeight(parentsInfo); double height1=(parentsInfo.getFatherBodyHeight()*0.923+parentsInfo.getMotherBodyHeight())/2; sonDaughterInfo.setDaughterBodyHeight(height1); return sonDaughterInfo; } } /** * 版权所有 2022 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc SonDaughterBll.java * Interface * Record * Annotation * Enum * */ package Bll; import Model.SonDaughterInfo; import Model.ParentsInfo; import Dal.SonDaughterDal; /** *根据父母身高求儿女身高 * @author geovindu * @version 1.0 * */ public class SonDaughterBll { /** *函数方式 * * */ public void sonDaughterFunction() { ParentsInfo parentsInfo= new ParentsInfo(); SonDaughterInfo sonDaughterInfo= new SonDaughterInfo(); parentsInfo.setFatherBodyHeight(177); parentsInfo.setMotherBodyHeight(165); System. out .println( "女儿身高:" +sonDaughterInfo.getDaughterHeight(parentsInfo)+ " 儿子身高:" +sonDaughterInfo.getSonHeight(parentsInfo)); } /** *函数方式 * @param fatherHeight 输入参数:父亲的身高 * @param motherHeight 输入参数:母亲的身高 * * */ public void sonDaughterFunction( int fatherHeight, int motherHeight) { ParentsInfo parentsInfo= new ParentsInfo(); SonDaughterInfo sonDaughterInfo= new SonDaughterInfo(); parentsInfo.setFatherBodyHeight(fatherHeight); parentsInfo.setMotherBodyHeight(motherHeight); System. out .println( "女儿身高:" +sonDaughterInfo.getDaughterHeight(parentsInfo)+ " 儿子身高:" +sonDaughterInfo.getSonHeight(parentsInfo)); } /** *业务方式 * * */ public void sonDaughterBusiness() { ParentsInfo parentsInfo= new ParentsInfo(); parentsInfo.setFatherBodyHeight(177); parentsInfo.setMotherBodyHeight(165); SonDaughterInfo sonDaughter= new SonDaughterInfo(); sonDaughter= new SonDaughterDal().getInfoHeight(parentsInfo); System. out .println( "业务操作 女儿身高:" +sonDaughter.getDaughterBodyHeight()+ " 儿子身高:" +sonDaughter.getSonBodyHeight()); } /** *业务方式 * @param fatherHeight 输入参数:父亲的身高 * @param motherHeight 输入参数:母亲的身高 * * */ public void sonDaughterBusiness( int fatherHeight, int motherHeight) { ParentsInfo parentsInfo= new ParentsInfo(); parentsInfo.setFatherBodyHeight(fatherHeight); parentsInfo.setMotherBodyHeight(motherHeight); SonDaughterInfo sonDaughter= new SonDaughterInfo(); sonDaughter= new SonDaughterDal().getInfoHeight(parentsInfo); System. out .println( "业务操作 女儿身高:" +sonDaughter.getDaughterBodyHeight()+ " 儿子身高:" +sonDaughter.getSonBodyHeight()); } } /** * 版权所有 2022 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc TeaMoneyDal.java * Interface * Record * Annotation * Enum * */ package Dal; import Model.*; /** * 茶妹妹的处理业务 * @author geovindu * @version 1.0 * * */ public class TeaMoneyDal { /** * 得到谁钱的简要描述 * * */ public String getMoney(TeaMoneyInfo teaMoneyInfo) { String getStr= "" ; teaMoneyInfo.setRedMoney(teaMoneyInfo.getRedTeaSister()*2+3); teaMoneyInfo.setGreenMoney(teaMoneyInfo.getGreenTeaSister()*2); if (teaMoneyInfo.getRedMoney()==teaMoneyInfo.getGreenMoney()) { getStr= "两位妹妹一样多!为:" +teaMoneyInfo.getRedMoney(); } else { if (teaMoneyInfo.getRedMoney()>teaMoneyInfo.getGreenMoney()) { getStr= "红茶妹妹多,红茶妹妹为:" +teaMoneyInfo.getRedMoney()+ " 绿茶妹妹为:" +teaMoneyInfo.getGreenMoney(); } else { getStr= "绿茶妹妹多,红茶妹妹为:" +teaMoneyInfo.getRedMoney()+ " 绿茶妹妹为:" +teaMoneyInfo.getGreenMoney(); } } return getStr; } } /** * 版权所有 2023 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc TeaMoneyBll.java * Interface * Record * Annotation * Enum * */ package Bll; import Model.TeaMoneyInfo; import Dal.TeaMoneyDal; /** *求红茶和绿茶妹的赚的钱是不是一样多 * @author geovindu * @version 1.0 * * */ public class TeaMoneyBll { /** *函数操作处理 * * */ public void TeaMoneyFunction() { TeaMoneyInfo teaMoneyInfo= new TeaMoneyInfo(); teaMoneyInfo.setRedTeaSister(21); teaMoneyInfo.setGreenTeaSister(24); System. out .println(teaMoneyInfo.getMoney()); } /** *函数操作处理 * @param redTea 输入参数:红茶妹妹的初始钱款 * @param greenTea 输入参数:绿茶妹妹的初始钱款 * * */ public void TeaMoneyFunction( int redTea, int greenTea) { TeaMoneyInfo teaMoneyInfo= new TeaMoneyInfo(); teaMoneyInfo.setRedTeaSister(redTea); teaMoneyInfo.setGreenTeaSister(greenTea); System. out .println(teaMoneyInfo.getMoney()); } /** *业务操作处理 * * */ public void TeaMoneyBusiness() { TeaMoneyInfo teaMoneyInfo= new TeaMoneyInfo(); teaMoneyInfo.setRedTeaSister(21); teaMoneyInfo.setGreenTeaSister(24); TeaMoneyDal teaMoneyDal= new TeaMoneyDal(); System. out .println( "业务操作 " +teaMoneyDal.getMoney(teaMoneyInfo)); } /** *业务操作处理 * @param redTea 输入参数:红茶妹妹的初始钱款 * @param greenTea 输入参数:绿茶妹妹的初始钱款 * * */ public void TeaMoneyBusiness( int redTea, int greenTea) { TeaMoneyInfo teaMoneyInfo= new TeaMoneyInfo(); teaMoneyInfo.setRedTeaSister(redTea); teaMoneyInfo.setGreenTeaSister(greenTea); TeaMoneyDal teaMoneyDal= new TeaMoneyDal(); System. out .println( "业务操作 " +teaMoneyDal.getMoney(teaMoneyInfo)); } } |
调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /** * 版权所有 2022 涂聚文有限公司 * 许可信息查看: * 描述: * * 历史版本: JDK 8.01 * 2023-03-12 创建者 geovindu * 2023-03-12 添加 Lambda * 2023-03-12 修改:date * 接口类 * 2023-03-12 修改者:Geovin Du * 生成API帮助文档的指令: *javadoc - -encoding Utf-8 -d apidoc Main.java * Interface * Record * Annotation * Enum * */ import Bll.*; /** * * * */ public class Main { /** * * * */ public static void main(String[] args) { System. out .println( "Hello 涂聚文!" ); //快餐最优购买方式 FoodBll foodBll= new FoodBll(); foodBll.foodFunction(); foodBll.foodCheck(); //根据父母的身高计算儿女的年龄 SonDaughterBll sonDaughterBll= new SonDaughterBll(); sonDaughterBll.sonDaughterFunction(); sonDaughterBll.sonDaughterBusiness(); //红茶妹妹和绿茶妹妹是否赚得钱一样多 TeaMoneyBll teaMoneyBll= new TeaMoneyBll(); teaMoneyBll.TeaMoneyFunction(); teaMoneyBll.TeaMoneyBusiness(); } } |
输出
-Djava.library.path=C:\Users\geovindu\IdeaProjects\TankWindows\libs\natives\windows
vm options
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言
2015-03-12 csharp: Double Convert To String