选择题答案与代码如下,提交时直接在主函数中调用即可
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();
}
}