请问这个Java题怎么做?

Python013

请问这个Java题怎么做?,第1张

按照题目要求编写的Java程序如下

import java.util.Scanner

class RadiusException extends Exception{

public RadiusException(String message){

super(message)

}

}

public class Circle{

public double area(double r) throws RadiusException{

if(r<0)

throw new RadiusException("输入错误")

else

return Math.PI*r*r

}

public static void main(String[] args){

System.out.print("请输入圆的半径r:")

try{

Scanner sc=new Scanner(System.in)

double r=sc.nextDouble()

Circle c=new Circle()

System.out.println("圆的面积为"+c.area(r))

sc.close()

}catch(RadiusException re){

System.out.println(re.getMessage())

}

}

}

class GrandFather{

    private String name

    private int age

    public GrandFather(String name, int age){

        this.name = name

        this.age = age

    }

    public String getGrandFather(){

        return (name + ":" +age)

    }

}

class Father extends GrandFather{

    private String occupation

    public Father(String name, int age, String occupation){

        super(name, age)

        this.occupation = occupation

    }

    public String getFather(){

        return super.getGrandFather() + " " +this.occupation

    }

}

public class ClassMain{

    public static void main(String[] args){

        GrandFather gf = new GrandFather("Tom", 75)

        Father f = new Father("Gim", 49, "orgnizer")

        System.out.println(gf.getGrandFather())

        System.out.println(f.getFather())

    }    

}

import java.util.ArrayList

import java.util.List

public class Random {

    public static void main(String[] args) {

        String[] tiMu = new String[20]

        for (int i = 0 i < tiMu.length i++) {

            tiMu[i] = "第" + (i + 1) + "题"

        }

        String[] temp = new String[10]

        //开始抽取题目

        //产生10个随机数

        List<Integer> list = new ArrayList<Integer>()

        int i

        while(list.size() < 10){

            i = (int) (Math.random() * 20)

            if(!list.contains(i)){

                list.add(i)

            }

        }

        for (int j = 0 j < list.size() j++) {

            temp[j] = tiMu[list.get(j)]

        }

        for (int iloop = 0 iloop < temp.length iloop++) {

            System.out.print(temp[iloop] + "   ")

        }

    }

}

代码已经写完了,亲测可用,望采纳哦!