CQUPT Java平时作业05

选择题答案与代码如下,提交时直接在主函数中调用即可

import java.util.Scanner;

class Retangle {
    float length;
    float width;

    public Retangle(float length, float width) {
        this.length = length;
        this.width = width;
    }

    public float getArea() {
        return length * width;
    }

    public void show() {
        System.out.println("The lengh is:" + length);
        System.out.println("The width is:" + width);
        System.out.println("The area is:" + getArea());

    }
}

class Circle {
    private double radius;
    double PI = 3.1415926;

    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    double getPerimeter() {
        return 2*PI*radius;
    }
    double getArea(){
        return PI*radius*radius;
    }
    void disp(){
        System.out.printf("radius=%.4f\n",radius);
        System.out.printf("perimeter=%.4f\n",getPerimeter());
        System.out.printf("area=%.4f\n",getArea());
    }
}

class Employee{
    float sarary,bonus;
    String name;
    int age;

    public Employee( String name, int age,float sarary, float bonus) {
        this.sarary = sarary;
        this.bonus = bonus;
        this.name = name;
        this.age = age;
    }

    void display(){
        System.out.println("Employee's name: "+name);
        System.out.println("Employee's age: "+age);
        System.out.println("Employee's income: "+(bonus+sarary));
    }

}

class MyPotin{
    float x;
    float y;

    public MyPotin(float x, float y) {
        this.x = x;
        this.y = y;
    }

    void display(){
        System.out.println("Your location of horizontal (X) is :"+x);
        System.out.println("Your location of ordinate (Y) is :"+y);
    }
}

public class Main {

    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        //  选择题 ACCB
        //  在这里调用对应函数

    }
    // 第一题
    public static void T1() {
        System.out.println("Please input length: ");
        float len = in.nextFloat();
        System.out.println("Please input width: ");
        float wid = in.nextFloat();
        Retangle re = new Retangle(len, wid);
        re.show();
    }
    //  第二题
    public static  void T2(){
        Circle c = new Circle();
        c.setRadius(in.nextDouble());
        c.disp();
    }
    //    第三题
    public  static  void T3(){
        System.out.println("Please input the employee's name: ");
        String name = in.next();
        System.out.println("Please input the employee's age: ");
        int age = in.nextInt();
        System.out.println("Please input the employee's sarary: ");
        float salary = in.nextFloat();
        System.out.println("Please input the employee's bonus: ");
        float bonus = in.nextFloat();
        Employee e = new Employee(name,age,salary,bonus);
        e.display();
    }
    // 第四题
    public static  void T4()
    {
        System.out.println("Please input the horizontal (X) : ");
        float x = in.nextFloat();
        System.out.println("Please input the ordinate (Y) : ");
        float y = in.nextFloat();
        MyPotin mp = new MyPotin(x,y);
        mp.display();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渝北最后的单纯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值