国开《JAVA语言程序设计》形考任务三源代码及输出截图

时间:2022-05-20 04:36:13 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
1 package org. open. java; 2 3/** 4*任务1

5 * @author chenjunfeng02 6 * 7 */

8 public class FinalExam1 {

9 private float waterPrice = 3.0f; //矿泉水 10 private float breadPrice = 3.5f; //面包 11 private float icecreamPrice = 2.5f; //冰棍. 12 private float fastFoodPrice = 4.5f; //方便面 13 private float cocaColaPrice = 3.5f; //瓶装可乐 14

15 public FinalExam1() { 16 17 } 18 19 /**

20 *计算购物的总价格 21 *

22 * @param water矿泉水的数量 23 * @param bread 面包的数量 24 * @param icecream 冰棍的数量 25 *@return 26 */

27 public float calcPriceByXiaoMing(int waterNum, int breadNum, int cocaColaNum) { 28 System. out. println("==========小明购买的产品列表==============="); 29 System. out.println("矿泉水: " + waterNum); 30 System. out.printIn("面包:" + breadNum) ; 31 System. out.printIn("瓶装可乐:" + cocaColaNum) ; 32

33 float totalPrice = waterNum * waterPrice +

34 breadNum * breadPrice + cocaColaNum * this. cocaColaPrice;


35 System. out.printIn("计算总结price:" + totalPrice) ; 36

37 return totalPrice; 38 } 39

40 public float calcPriceByXiaoMei(int iceCreamNum, int cocaColaNum, int fastFoodNum) { 41 System. out.println("==========小美购买的产品列表=============="); 42 System. out.println("冰棍: "+ iceCreamNum); 43 System. out.println("可乐数量:" + cocaColaNum); 44 System. out.printIn("方便面数量:" + fastFoodNum); 45

46 float totalPrice = iceCreamNum * icecreamPrice + cocaColaNum * cocaColaPrice 47 + fastFoodNum * fastFoodPrice; 48 System. out. printIn("计算总价Price:" + totalPrice); 49

50 return totalPrice; 51 } 52

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

54 Fina LExam1 finalExam1 = new FinalExam1(); 55

56 //计算总价,小明:矿泉水2瓶,面包1个,可乐: 1

57 float XiaoMingPrice = finalExam1. calcPriceByXiaoMing(2, 1, 1); 58 System. out. println("小明购买Total Price:" + XiaoMingPrice); 59

60 //计算总价,小美:冰棍3个,瓶装可乐: 2个,方便面: 1 61 float XiaoMeiPrice = finalExam1. calcPriceByXiaoMei(3, 2, 1); 62 System. out. print1n("小美购买总价Total Price:" + xiaoMeiPrice); 63 } 64 } 65







本文来源:https://www.wddqw.com/doc/3f1f6d7369d97f192279168884868762caaebb2e.html