javatest

day4

2.

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("**************");
        System.out.println("存期      年利率");
        System.out.println("一年       2.25");
        System.out.println("两年       2.7");
        System.out.println("三年       3.25");
        System.out.println("五年       3.6");
        System.out.println("**************");
        int n = sc.nextInt();
        if (n >= 1000) {
            int year = sc.nextInt();
            double ans;
            if (year == 1) ans = n + n * 2.25 * year;
            else if (year == 2) ans = n + n * 2.7 * year;
            else if (year == 3) ans = n + n * 4.25 * year;
            else ans = n + n * 3.6 * year;
            System.out.println(ans);
        } else System.out.println("起存金额不足");
    }
}

 3.

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int flag = sc.nextInt();
        int before;
        if (flag == 0)
        {
            before = sc.nextInt();
            if (before >= 100) System.out.println(1.0 * before * 0.9);
            else System.out.println(before);
        }
        else
        {
            before = sc.nextInt();
            if (before >= 200) System.out.println(1.0 * before * 0.75);
            else System.out.println(1.0 * before * 0.8);
        }
    }
}

4.

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int before = sc.nextInt();
        double up = 0.0;
        double a = before * 0.1;
        double over = before - a - 5000;
        System.out.println(a);
        System.out.println(over);
        if (over >= 5000)
        {
            if (over >= 80000)
            {
                up += (over - 80000) * 0.45;
                over = 80000;
            }
            if (over >= 55000)
            {
                up += (over - 55000) * 0.3;
                over = 55000;
            }
            if (over >= 35000)
            {
                up += (over - 35000) * 0.25;
                over = 35000;
            }
            if (over >= 25000)
            {
                up += (over - 25000) * 0.25;
                over = 25000;
            }
            if (over >= 12000)
            {
                up += (over - 12000) * 0.2;
                over = 12000;
            }
            if (over >= 3000)
            {
                up += (over - 3000) * 0.1;
                over = 3000;

            }
            if (over >= 0)
            {
                up += over * 0.03;
            }
            System.out.println("纳税:" + up + "税后:" + (before - up - a));
        }
        else
            System.out.println("纳税:" + up + "税后:" + before);


    }
}

 5.

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int op = sc.nextInt();
       int ans;
       switch(op)
       {
           case 1 :
           {
               ans = a + b;
               System.out.println(a + " + " + b + " = " + ans);
               break;
           }
           case 2:
           {
               ans = a - b;
               System.out.println(a + " - " + b + " = " + ans);
               break;
           }
           case 3:
           {
               ans = a * b;
               System.out.println(a + " * " + b + " = " + ans);
               break;
           }
           default:
           {
               ans = a / b;
               System.out.println(a + " / " + b + " = " + ans);
                break;
           }
       }
    }
}

 6.

一元:0 5角:100
一元:1 5角:90
一元:2 5角:80
一元:3 5角:70
一元:4 5角:60
一元:5 5角:50
一元:6 5角:40
一元:7 5角:30
一元:8 5角:20
一元:9 5角:10
一元:10 5角:0
次数为:11

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 100;
        int cnt = 0;
        for (int i = 0;i < 15;i ++)
            for (int j = 0;j < 105;j ++)
            {
                if (10 * i + j == sum)
                {
                    cnt ++;
                    System.out.println("一元:" + i + " 5角:" + j);
                }

            }
        System.out.println("次数为:" + cnt);
    }
}

7.


public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1988;i <= 2019;i ++)
            if (i % 100 != 0 && i % 4 == 0 || i % 400 == 0)
                System.out.println(i);
    }
}

8.


public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1949;i <= 2019;i ++)
            if ((i - 1949) % 12 == 0)
                System.out.println(i);
    }
}

9.

10.

 

 11.

day5 

1.

 2.

 3.

4.

5. 

请录入第1件商品的名称:一
请录入第1件商品的数量:1
请录入第1件商品的单价:1
第一件商品录入成功!
请录入第2件商品的名称:二
请录入第2件商品的数量:2
请录入第2件商品的单价:2
第一件商品录入成功!
请录入第3件商品的名称:三
请录入第3件商品的数量:3
请录入第3件商品的单价:3
第一件商品录入成功!
***欢迎来到旺旺超市***
--------------------------
商品名称       数量        单价         金额
一         1         1.0         1.0
二         2         2.0         4.0
三         3         3.0         9.0
--------------------------
总数量:6
总金额:14.0
已优惠金额:0.0
实付金额:14.0

Process finished with exit code 0
public class SuperMarketTicket {
    public static void main(String[] args) {
        //1.录入商品的信息(商品的名称,数量,单价)
        //利用Scanner扫描录入
        Scanner scan = new Scanner(System.in);

        String[] a = new String[110];
        int[] b = new int[110];
        double[] c = new double[110];



        for (int i = 0;i < 3;i ++)
        {
            System.out.print("请录入第" + (i + 1) + "件商品的名称:");
            a[i] = scan.next();
            System.out.print("请录入第" + (i + 1) + "件商品的数量:");
            b[i] = scan.nextInt();
            System.out.print("请录入第" + (i + 1) + "件商品的单价:");
            c[i] = scan.nextDouble();
            System.out.println("第一件商品录入成功!");
        }
//        System.out.print("请录入第一件商品的名称:");
//        String goodsName01 = scan.next();//扫描键盘上录入的字符串
//        System.out.print("请录入第一件商品的数量:");
//        int goodsQuantity01 = scan.nextInt();//扫描键盘上录入的整数
//        System.out.print("请录入第一件商品的单价:");
//        double goodsPrice01 = scan.nextDouble();//扫描键盘上录入的小数
//        //System.out.println(goodsName+" "+goodsQuantity+" "+goodsPrice);
//        System.out.println("第一件商品录入成功!");
//
//        System.out.print("请录入第二件商品的名称:");
//        String goodsName02 = scan.next();//扫描键盘上录入的字符串
//        System.out.print("请录入第二件商品的数量:");
//        int goodsQuantity02 = scan.nextInt();//扫描键盘上录入的整数
//        System.out.print("请录入第二件商品的单价:");
//        double goodsPrice02 = scan.nextDouble();//扫描键盘上录入的小数
//        System.out.println("第二件商品录入成功!");
//
//        System.out.print("请录入第三件商品的名称:");
//        String goodsName03 = scan.next();//扫描键盘上录入的字符串
//        System.out.print("请录入第三件商品的数量:");
//        int goodsQuantity03 = scan.nextInt();//扫描键盘上录入的整数
//        System.out.print("请录入第三件商品的单价:");
//        double goodsPrice03 = scan.nextDouble();//扫描键盘上录入的小数
//        System.out.println("第三件商品录入成功!");

        //2.展示购买的商品信息(商品的名称,数量,单价,金额)
        System.out.println("***欢迎来到旺旺超市***");
        System.out.println("--------------------------");
        System.out.println("商品名称       数量        单价         金额");

        double[] sum = new double[110];

        for (int i = 0;i < 3;i ++)
            sum[i] = b[i] * c[i];

//        double goodsSubtotal01 = goodsQuantity01 * goodsPrice01;
//        double goodsSubtotal02 = goodsQuantity02 * goodsPrice02;
//        double goodsSubtotal03 = goodsQuantity03 * goodsPrice03;

        for (int i = 0;i < 3;i ++)
            System.out.println(a[i] + "         " + b[i] + "         " + c[i] + "         " + sum[i]);;

//        System.out.println(goodsName01 + "         " + goodsQuantity01 + "         " + goodsPrice01 + "         " + goodsSubtotal01);
//        System.out.println(goodsName02 + "         " + goodsQuantity02 + "         " + goodsPrice02 + "         " + goodsSubtotal02);
//        System.out.println(goodsName03 + "         " + goodsQuantity03 + "         " + goodsPrice03 + "         " + goodsSubtotal03);

        System.out.println("--------------------------");


        //3.小票的统计信息
//        int totalQuantity = goodsQuantity01 + goodsQuantity02 + goodsQuantity03;//将所有购买的商品数量加起来
//        double totalAmount = goodsSubtotal01 + goodsSubtotal02 + goodsSubtotal03;//将所有购买的商品的小计加起来
//        System.out.println("总数量:" + totalQuantity);
//        System.out.println("总金额:" + totalAmount);

        int totalQuantity = 0;
        for(int i = 0;i < 3;i ++)
            totalQuantity += b[i];
        double totalAmount = 0;
        for (int i = 0;i < 3;i ++)
            totalAmount += sum[i];
        System.out.println("总数量:" + totalQuantity);
        System.out.println("总金额:" + totalAmount);


        //购买总数量超过10件或者总金额大于100,就在总价的基础上打五折
        //||
        double discountAmount = (totalQuantity > 10 || totalAmount > 100) ? totalAmount * 0.5 : totalAmount;
        System.out.println("已优惠金额:" + (totalAmount - discountAmount));//已优惠金额=总金额-实付金额
        System.out.println("实付金额:" + discountAmount);

    }
}

6. 

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] a = {1,2,3,4,5,6,7,8,9,10};
        int[] b = new int[110];

        int l = 0,r = a.length - 1;
        for (int i = 0;i < a.length;i ++)
        {
            if ((a[i] & 1) == 1)  b[l ++] = a[i];
            else b[r --] = a[i];
        }

        for (int i = 0;i < a.length;i ++)
            System.out.print(b[i] + " ");
    }
}

day6

1

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(add(1,2));
        System.out.println(add(1.1,2.2));
        int n = sc.nextInt();
        solve(n);

    }

    public static int add(int a,int b)
    {
        return a + b;
    }
    public static double add(double a,double b)
    {
        return a + b;
    }
    public static void solve(int n)
    {
        for (int i = 1;i <= n;i ++)
        {
            for (int j = 1;j <= i;j ++)
                System.out.print(j + " * " + i + " = " + j * i + " ");
            System.out.println();
        }
    }
}

2

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt = 0;
        for (int i = 1;i <= 100;i ++)
        {
            if (check(i))
            {
                System.out.print(i + " ");
                cnt ++;
            }
            if (cnt == 5)
            {
                System.out.println();
                cnt = 0;
            }

        }

    }

   public static boolean check(int x)
   {
       while(x != 0)
       {
           if (x % 10 == 9)
           {
               return false;
           }
           x /= 10;
       }
       return true;
   }

}

 3

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt = 0;
        for (int i = 1;i <= 100;i ++)
        {
            if (is_prime(i))
            {
                System.out.print(i + " ");
                cnt ++;
                if (cnt % 5 == 0)
                {
                    System.out.println();
                }
            }
        }

        System.out.println("个数:" + cnt);
    }

    public static boolean is_prime(int n)
    {
        if (n < 2) return false;
        for (int i = 2;i <= n / i;i ++)
            if (n % i == 0)
                return false;

        return true;
    }
}

 day7

1.

public class phone {
    private String brand;
    private int price;
    private String color;

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void call()
    {
        System.out.println("正在使用价格为" + price + "元的" + color + brand + "的手机打电话");
    }

    public void sendMessage()
    {
        System.out.println("正在使用价格为" + price + "元的" + color + brand + "的手机发短信");
    }
}
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        phone ph = new phone();

        ph.setPrice(3998);
        ph.setBrand("小米");
        ph.setColor("黑色");

        ph.call();
        ph.sendMessage();

    }
}

2

public class grilFrind {
    private String name;
    private double high;
    private double weight;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public void wash()
    {
        System.out.println("女朋友帮我洗衣服");
    }

    public void cook()
    {
        System.out.println("女朋友帮我做饭");
    }

    public void show()
    {
        System.out.println("我的女朋友叫" + name + ",身高" + high + "厘米,体重" + weight + "斤");
        wash();
        cook();
    }
}
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        grilFrind g = new grilFrind();
        g.setName("小红");
        g.setHigh(165.6);
        g.setWeight(90);
        g.show();

    }
}

3.

public class Manager {
    private String name;
    private int id;
    private int salary;
    private int bonus;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public int getBonus() {
        return bonus;
    }

    public void setBonus(int bonus) {
        this.bonus = bonus;
    }

    public void work()
    {
        System.out.println("工号为" + id + "基本工资为" + salary + "奖金为" + bonus + "的" + name + "正在努力的做着管理工作...");
    }
}
public class Coder {
    private String name;
    private int id;
    private int salary;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public void work()
    {
        System.out.println("工号为" + id + "基本工资为" + salary +  "的" + name + "正在努力写代码...");
    }
}
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Manager mg = new Manager();
        mg.setName("项目经理");
        mg.setId(123);
        mg.setSalary(15000);
        mg.setBonus(6000);
        mg.work();

        Coder co = new Coder();
        co.setName("程序员");
        co.setId(111);
        co.setSalary(1100);
        co.work();

    }
}

4.

public class Cat {
    private String color;
    private String breed;

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getBreed() {
        return breed;
    }

    public void setBreed(String breed) {
        this.breed = breed;
    }

    public void eat()
    {
        System.out.println(color + "的" + breed + "正在吃鱼");
    }
    public void catchMouse()
    {
        System.out.println(color + "的" + breed + "正在抓老鼠");
    }
}
public class Dog {
    private String color;
    private String breed;

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getBreed() {
        return breed;
    }

    public void setBreed(String breed) {
        this.breed = breed;
    }

    public void eat()
    {
        System.out.println(color + "的" + breed + "正在吃骨头");
    }

    public void lookHome()
    {
        System.out.println(color + "的" + breed + "正在看家");
    }
}
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Dog dog = new Dog();
        dog.setBreed("藏獒");
        dog.setColor("黑色");

        dog.eat();
        dog.lookHome();

        Cat cat = new Cat();
        cat.setColor("花色");
        cat.setBreed("波斯猫");

        cat.eat();
        cat.catchMouse();

    }
}

day8

1.

public abstract class Employee {
    private String name;
    private String workNumber;
    private double salary;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getWorkNumber() {
        return workNumber;
    }

    public void setWorkNumber(String workNumber) {
        this.workNumber = workNumber;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public abstract void work();
}
public class ProjectManager extends Employee {

    private double bonus;

    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;
    }

    @Override
    public void work() {
        System.out.println("name: " + getName() + "id: " + getWorkNumber() + " salary: " + getSalary() + " bouns" + bonus);
    }
}
public class Programmer extends Employee{

    @Override
    public void work() {
        System.out.println("name: " + getName() + "id: " + getWorkNumber() + " salary: " + getSalary());
    }
}
public class test {
    public static void main(String[] args) {
        ProjectManager projectManager = new ProjectManager();
        projectManager.setName("老王");
        projectManager.setWorkNumber("123");
        projectManager.setSalary(123);
        projectManager.setBonus(12);
        projectManager.work();

        Programmer programmer = new Programmer();
        programmer.setName("小李");
        programmer.setWorkNumber("145");
        programmer.setSalary(12);
        programmer.work();
    }
}

2.

public abstract class Animal {
    private String color;
    private int legs;

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getLegs() {
        return legs;
    }

    public void setLegs(int legs) {
        this.legs = legs;
    }

    public abstract void eat();

}

public class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }

    public void show()
    {
        System.out.println(getColor() + " 猫抓老鼠");
    }
}
public class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("狗吃骨头");
    }

    public void show()
    {
        System.out.println(getColor() + " 狗看家");
    }
}
public class AnimalTest {
    public static void main(String[] args) {
        Cat cat = new Cat();
        cat.setColor("黄");
        cat.setLegs(4);
        cat.eat();
        cat.show();

        Dog dog = new Dog();
        dog.setColor("黑");
        dog.setLegs(4);
        dog.eat();
        dog.show();
    }
}

3.

public abstract class Sudent {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public abstract void show();
}

public class BaseSudent extends Sudent{
    @Override
    public void show() {
        System.out.println(getName() + "(基础学生)," + " 年龄: " + getAge() + "正在学基础");
    }
}
public class BetterSudent extends Sudent{
    @Override
    public void show() {
        System.out.println(getName() + "(进阶学生)," + " 年龄: " + getAge() + "正在学进阶");
    }
}
public class SudentTest {
    public static void main(String[] args) {
        BaseSudent baseSudent = new BaseSudent();
        baseSudent.setName("张三");
        baseSudent.setAge(18);
        baseSudent.show();

        BetterSudent betterSudent = new BetterSudent();
        betterSudent.setName("李四");
        betterSudent.setAge(19);
        betterSudent.show();
    }
}

day9

1.

class Animal{
    public void eat()
    {
        System.out.println("吃");
    }
}

class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }

    public void keepHome()
    {
        System.out.println("狗看家");
    }
}

class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }

    public void catchMouse(){
        System.out.println("猫抓老鼠");
    }
}

public class Demo03 {
    public static void main(String[] args) {
        Animal animal1 = new Dog();
        Animal animal2 = new Cat();

        if (animal1 instanceof Dog)
        {
            ((Dog) animal1).keepHome();
            animal1.eat();
        }
        if (animal2 instanceof Cat)
        {
            ((Cat) animal2).catchMouse();
            animal2.eat();
        }
    }
}

 2.

 

interface Play{
    void playGame();
}

abstract class Phone{
    public abstract void call();
    public abstract void sendMessage();
}

class OldPhone extends Phone{
    @Override
    public void call() {
        System.out.println("旧手机打电话");
    }

    @Override
    public void sendMessage() {
        System.out.println("旧手机发短信");
    }
}

class NewPhone extends Phone implements Play{
    @Override
    public void call() {
        System.out.println("新手机打电话");
    }

    @Override
    public void sendMessage() {
        System.out.println("新手机发短信");
    }

    @Override
    public void playGame() {
        System.out.println("新手机玩游戏");
    }
}

public class Demo04 {
    public static void main(String[] args) {
        OldPhone oldPhone = new OldPhone();
        oldPhone.call();
        oldPhone.sendMessage();
        NewPhone newPhone = new NewPhone();
        newPhone.call();
        newPhone.sendMessage();
        newPhone.playGame();
    }
}

3.

abstract class Car{
    public abstract void run();
}

class BaseCar extends Car{
    @Override
    public void run() {
        System.out.println("普通奥迪车正在跑");
    }
}

class UpperCar extends BaseCar{
    @Override
    public void run() {
        System.out.println("高端奥迪车正在跑");
    }

    public void part()
    {
        System.out.println("高端奥迪车可以自动泊车");
    }

    public void drive()
    {
        System.out.println("高端奥迪车可以无人驾驶");
    }
}

public class Demo05 {
    public static void main(String[] args) {
        BaseCar baseCar = new BaseCar();
        baseCar.run();
        UpperCar upperCar = new UpperCar();
        upperCar.run();
        upperCar.part();
        upperCar.drive();
    }
}

 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值