2月4日日报

2月4日日报,第1张

2月4日日报
package AbstractTest;

import java.util.Scanner;

public class PayrollSystem {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入当月月份");
        int m = sc.nextInt();
        Employee[] emps = new Employee[2];

        

        emps[0] = new SalariedEmployee("麻蛇", 1002, new MyDate(1990, 10, 10),1000);
        emps[1] = new HourlyEmployee("草泥马", 2200, new MyDate(1993, 5, 4), 60, 240);

        for (int i = 0; i < emps.length; i++) {
            System.out.println(emps[i]);
            double money = emps[i].earnings();
            if (m == emps[i].getBirthday().getMonth()) {
                money += 100;
                System.out.println("生日快乐,奖励一百元!");
            }
            System.out.println("月工资为: " + emps[i].earnings());
        }
    }

}



//InterviewTest
package Test1;

public class InterviewTest1 {
    public static void main(String[] args) {
        base1 b = new base1();
        b.add(1, 2, 3); //correct!

        base1 b2= new Sub1();
        b2.add(1,2,3); //Yes!

        Sub1 s = (Sub1) b2;
        s.add(1,2,3); //No!
    }
}


class base1 {
    public void add(int a, int... arr) {
        System.out.println("correct!");
    }
}

class Sub1 extends base1 {
    public void add(int a, int[] arr) {
        System.out.println("Yes!");
    }

    public void add(int a, int b, int c) {
        System.out.println("No!");
    }
}

//拆包
package Test1;

import java.util.Scanner;
import java.util.Vector;
import static java.lang.System.*;

public class ScoreTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Vector v = new Vector();

        int maxScore = 0;
        while (true) {
            out.println("请输入学生成绩(输入负数表示退出)");
            int nextScore = scan.nextInt();
            if (nextScore < 0) {
                break;
            } else if (nextScore > 100) {
                out.println("学生成绩不能超过100");
                continue;
            } else {
                Integer p = Integer.valueOf(nextScore);
                v.addElement(p);
                maxScore = Math.max(maxScore, nextScore);
            }
        }

        char grade;
        for (int i = 0; i < v.size(); i++) {
            Object obj = v.elementAt(i);
            //自动拆包
            //int cur = (Integer)obj;
            //包装转基本数据
            Integer cur1 = (Integer)obj;
            int cur = cur1.intValue();
            int diff = maxScore - cur;
            if (diff < 10) {
                grade = 'A';
            } else if (diff >= 10 && diff < 20) {
                grade = 'B';
            } else if (diff >= 20 && diff < 30) {
                grade = 'C';
            } else {
                grade = 'D';
            }

            out.println("Student " + i + " score is " + cur + " and grade is " + grade);
        }
    }
}


关键字static:

关键字Final:

抽象Abstract

接口Interface…

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5722553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存