首先說一下自己的感受,通過第一道題發現了自己確實基礎很水…
說一下自己遇到的問題:
1:再 System.out.println直接進行了result+500,這樣的字串拼接,然后知道要執行計算需要加上括號
2:不太會用回圈陳述句
附上自己寫的爛代碼:
import java.util.Scanner;
/**
* @author ${范濤之}
* @Description
* @create 2021-10-29 16:42
*/
public class Takeaway {
public static void main(String[] args) {
System.out.println("******************************************************");
System.out.println("* *\n");
System.out.println("* *\n");
System.out.println("* CSDN外賣騎士薪資系統 *\n");
System.out.println("* *\n");
System.out.println("* *");
System.out.println("******************************************************\n");
// 定義提成
double num1 = 0.0;
double num2 = 1.5;
double num3 = 2.2;
double num4 = 3.2;
double pay = 0;
// 第一次很麻煩的定義
String emp1 = "李雷";
String emp2 = "張偉";
String emp3 = "錢楓";
String emp4 = "吳謙";
String emp5 = "趙男";
String emp6 = "孫冬";
String emp7 = "夏嵐";
String emp8 = "胡宇";
// 后來想起了陣列
String epm[] = {"李雷","張偉","錢楓","吳謙","趙男","孫冬","夏嵐","胡宇"};
//定義底薪
int basic = 0;
Scanner s = new Scanner(System.in);
System.out.println("請輸入外賣小哥姓名:");
String human = s.nextLine();
if(human.equals(epm[0])){
basic = 3000;
}
if(human.equals(epm[1])){
basic = 3000;
}
if(human.equals(epm[2])){
basic = 2500;
}
if(human.equals(epm[3])){
basic = 4000;
}
if(human.equals(epm[4])){
basic = 2500;
}
if(human.equals(epm[5])){
basic = 3000;
}
if(human.equals(epm[6])){
basic = 3500;
}
if(human.equals(epm[7])){
basic = 3500;
}
Scanner input = new Scanner(System.in);
System.out.println("請輸入已完成的訂單數:");
int number = input.nextInt();
if (number>=0&&number<=100){
pay = basic;
}
if (number>=101&&number<=300){
pay = basic+number*num2;
}
if (number>=301&&number<=500){
pay = basic+number*num3;
}
if (number>500){
pay = basic+number*num4;
}
double result= pay+basic;
// System.out.println("["+human+"]"+"的收入是:"+result);
// 加入星期因素
// 如果沒有輸入日期
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入當前日期:");
String data = scanner.nextLine();
if (data == data){
if (human.equals( epm[0])){
System.out.println("["+human+"]"+"一周一共的收入是"+(500*3+result+400*2));
}
if (human.equals( epm[1])){
System.out.println("["+human+"]"+"一周一共的收入是"+(400*3+result+400));
}
if (human.equals( epm[2])){
System.out.println("["+human+"]"+"一周一共的收入是"+(500*3+result+400+300));
}
if (human.equals( epm[3])){
System.out.println("["+human+"]"+"一周一共的收入是"+(500*2+result+400+300*2));
}
if (human.equals( epm[4])){
System.out.println("["+human+"]"+"一周一共的收入是"+(500*2+result+400*3));
}
if (human.equals( epm[5])){
System.out.println("["+human+"]"+"一周一共的收入是"+(500*3+result+400));
}
if (human.equals( epm[6])){
System.out.println("["+human+"]"+"一周一共的收入是"+(400*3+result+300));
}
if (human.equals( epm[7])){
System.out.println("["+human+"]"+"一周一共的收入是"+(400+result+400*2+300*2));
}
}
//輸入日期以后
switch (data){
case "周一":
// 周一的早班
if(human.equals(emp1) || human.equals(emp3) || human.equals(emp6)){
System.out.println("["+human+"]"+"周一的收入是:"+(pay+500));
}
// 周一的中班
if (human.equals(emp2) || human.equals(emp5) || human.equals(emp7) || human.equals(emp8)){
System.out.println("["+human+"]"+"周一的收入是:"+(pay+400));
}
// 周一的晚班
if (human.equals(emp4)){
System.out.println("["+human+"]"+"周一的收入是:"+(pay+300));
}
// 周一的大夜 :無
break;
case "周二":
// 周二的早班
if(human.equals(emp3) || human.equals(emp5) || human.equals(emp6)){
System.out.println("["+human+"]"+"周二的收入是:"+(pay+500));
}
// 周二的中班
if (human.equals(emp1) || human.equals(emp7)){
System.out.println("["+human+"]"+"周二的收入是:"+(pay+400));
}
// 周二的晚班:無
// 周二的大夜:無
break;
case "周三":
// 周三的早班
if(human.equals(emp1) || human.equals(emp4)|| human.equals(emp6)){
System.out.println("["+human+"]"+"周三的收入是:"+(pay+500));
}
// 周三的中班
if(human.equals(emp5) || human.equals(emp7)){
System.out.println("["+human+"]"+"周三的收入是:"+(pay+400));
}
// 周三的晚班:無
// 周三的大夜
if(human.equals(emp2) || human.equals(emp8)){
System.out.println("["+human+"]"+"周三的收入是:"+(pay+400));
}
break;
case "周四":
// 周四的早班
if(human.equals(emp5) || human.equals(emp6)){
System.out.println("["+human+"]"+"周四的收入是:"+(pay+500));
}
// 周四的中班
if(human.equals(emp1) || human.equals(emp7)){
System.out.println("["+human+"]"+"周四的收入是:"+(pay+400));
}
// 周四的晚班:
if(human.equals(emp8)){
System.out.println("["+human+"]"+"周四的收入是:"+(pay+300));
}
// 周四的大夜
if(human.equals(emp3) || human.equals(emp4)){
System.out.println("["+human+"]"+"周四的收入是:"+(pay+400));
}
break;
case "周五":
// 周五的早班
if(human.equals(emp1) || human.equals(emp3) || human.equals(emp4)){
System.out.println("["+human+"]"+"周五的收入是:"+(pay+500));
}
// 周五的中班
if(human.equals(emp2) || human.equals(emp5) || human.equals(emp8)){
System.out.println("["+human+"]"+"周五的收入是:"+(pay+400));
}
// 周五的晚班:
if(human.equals(emp7)){
System.out.println("["+human+"]"+"周五的收入是:"+(pay+300));
}
// 周五的大夜:無
break;
case "周六":
// 周六的早班 :無
// 周六的中班
if(human.equals(emp2)){
System.out.println("["+human+"]"+"周六的收入是:"+(pay+400));
}
// 周六的晚班
if(human.equals(emp8)){
System.out.println("["+human+"]"+"周六的收入是:"+(pay+300));
}
// 周六的大夜
if(human.equals(emp4) || human.equals(emp6)){
System.out.println("["+human+"]"+"周六的收入是:"+(pay+300));
}
break;
}
}
}
ON java8 第五章控制流:
1:true false 條件運算式:“真” “假”
2:if else
3:while / do-while / for:do while 至少執行一次,while更為常用
4:for回圈
插入知識點:
isLowerCase() 方法用于判斷指定字符是否為小寫字母,
public class Test {
public static void main(String args[]) {
System.out.println( Character.isLowerCase('c'));
System.out.println( Character.isLowerCase('C'));
}
}
true
false
toCharArray() 方法將字串轉換為字符陣列,
public class Test {
public static void main(String args[]) {
String Str = new String("www.runoob.com");
System.out.print("回傳值 :" );
System.out.println( Str.toCharArray() );
}
}
回傳值 :www.runoob.com
5:for-in與語法,在java5中引入了“增強版for回圈”來操縱陣列與集合,還有很多檔案稱其為for-each語法,但是為了防止與java8新增的forEach()產生混淆,我們稱為for-in回圈
for(float x : f)
插入:
range(10) //0..9 等價于為:[0,1,2,3,4,5,6,7,8,9]
range(5,10) //5..9 等價于為:[5,6,7,8,9]
range(5,20,3) //5..20 step 3 等價于為:[5,8,11,14,17]
6:return 方法回傳值型別不是void,則必須return
7:break 和 continue
brake:中斷回圈
continue:注意,continue 陳述句可將控制權移回回圈的頂部,而不會執行 continue 之后的任何操作,
8:goto:,goto 起源于匯編(assemblylanguage)語言中的程式控制:“若條件 A 成立,則跳到這里;否則跳到那里”,
9:switch:
integral-selector(整數選擇因子)必須是 int、short、char、byte和enum 型別( JDK 1.7 之后,型別也可以是String了 )是一個能產生整數值的運算式或String型別的變數
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/342187.html
標籤:java
上一篇:JAVA中對類和物件的認識
