1.编写Java应用程序,要求有3个类:CPU,PC,Test。要求:(1)CPU类有成员变量speed表示CPU的运行速度,有方法setSpeed(intm)设置运行速度,getSpeed()获取运行速度;(2)PC类有成员变量CPU,方法setCPU(CPUc)设置CPU,show()显示CPU的运行速度;(3)Test类为主类,main方法中创建一个CPU对象和一个PC对象,并调用setCPU(CPUc)设置CPU,调用show()方法显示CPU的运行速度。classCPU{intspeed;intgetSpeed(){returnspeed;}voidsetSpeed(intspeed){this.speed=speed;}}publicclassPC{CPUcpu;voidsetCPU(CPUcpu){this.cpu=cpu;}voidshow(){System.out.println(cpu速度:+cpu.getSpeed());}}classTest{publicstaticvoidmain(Stringargs[]){CPUcpu=newCPU();cpu.setSpeed(2000);PCpc=newPC();pc.setCPU(cpu);pc.show();}}2.编写Java应用程序,要求有4个类:Animal,Dog,Cat,Simulator。其中:(1)Animal为抽象类,有2个抽象方法cry()和getName(),具体动物可以给出自己的叫声及名称;(2)Dog和Cat类,为Animail的实现类;(3)Simulator类为测试类,该类包含1个main方法和1个playSound(Animalanimal)方法,在main方法中调用playSound方法模拟Dog和Cat的叫声publicabstractclassAnimal{publicabstractvoidcry();publicabstractStringgetAnimalName();}classDogextendsAnimal{publicvoidcry(){System.out.println(汪汪···汪汪);}publicStringgetAnimalName(){return狗;}}classCatextendsAnimal{publicvoidcry(){System.out.println(喵喵···喵喵);}publicStringgetAnimalName(){return猫;}}classSimulator{publicvoidplaySound(Animalanimal){System.out.print(现在播放+animal.getAnimalName()+类的声音:);animal.cry();}publicstaticvoidmain(Stringargs[]){Simulatorsimulator=newSimulator();simulator.playSound(newDog());simulator.playSound(newCat());}}6.用类描述计算机中CPU的速度和硬盘的容量。要求Java应用程序有4个类,名字分别是PC、CPU、HardDisk和Test是主类。publicclassTest{publicstaticvoidmain(String[]args){CPUcpu=newCPU();cpu.setspeed(2200);HardDiskdisk=newHardDisk();disk.setamount(200);PCpc=newPC();pc.setCPU(cpu);pc.setHardDisk(disk);pc.show();}}classCPU{privateintspeed;CPU(){}voidsetspeed(intm){this.speed=m;}intgetspeed(){returnthis.speed;}}classHardDisk{privateintamount;HardDisk(){}voidsetamount(intm){this.amount=m;}intgetamount(){returnthis.amount;}}classPC{privateCPUcpu;privateHardDiskHD;PC(){}voidsetCPU(CPUc){this.HD=h;}voidshow(){System.out.println(cpuspeedis”+this.cpu.getspeed()+HardDiskamountis+this.HD.getamount());}}补充1.编程计算8+88+888+8888---的前12项和。PublicclassTest{Publicstaticvoidmain(Stringargs[]){Longsum=0,a=8,item=a,n=12,i=1;For(i=1;Ii=n;i++){sum=sum+item;Item=item*10+a;}System.out.println(sum);}}2.用while语言编程计算1+1\2!+1\3!+1\4!---------的前20项和PublicclassText{Publicstaticvoidmain(stringargs[]){doublesum=0,a=1;Inti=1;While(i=20){Sum=sum+a;i=i+1;a=a*(1\i);}System.out.println(sum);}}