程序逻辑与算法01笔记

小涛 社区会员 2021-10-30 18:49:25

首先说一下自己的感受,通过第一道题发现了自己确实基础很水.....

说一下自己遇到的问题:

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类型的变量

...全文
606 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110

社区成员

发帖
与我相关
我的任务
社区描述
训练、训练、训练!
其他 其他
社区管理员
  • 实训001
  • 非鱼up
  • andy421
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

自律训练,自信挑战!

试试用AI创作助手写篇文章吧