Packagetop.hyself; Public classtest_1106 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubTestdemo Circle1 =NewTestdemo (); DoubleArea=Circle1.getarea (); System.out.println (area); Testdemo Circle2=NewTestdemo (10); System.out.println (Circle2.getarea ()); System.out.println (Circle1.getperimeter ()); System.out.println (Circle2.getperimeter ()); Doubleridius=10; Doubleareacircle=math.pi*ridius*Ridius; System.out.println (areacircle); Circle2.setradius (5); System.out.println (Circle2.getarea ()); }}
Packagetop.hyself; Public classTestdemo {Private Doubleradius; PublicTestdemo (Doubleradius) { This. Radius =radius; } PublicTestdemo () { This. Radius = 1.0; } Public DoubleGetarea () {returnMath.PI * RADIUS *radius; } Public DoubleGetperimeter () {return2 * Math.PI *radius; } Public voidSetradius (DoubleNewradius) { This. Radius =Newradius; }}
Packagetop.hyself; Public classtest_1106 {Private Doubleradius; Publictest_1106 (Doubleradius) { This. Radius =radius; } Publictest_1106 () { This. Radius = 1.0; } Public DoubleGetarea () {returnMath.PI * RADIUS *radius; } Public DoubleGetperimeter () {return2 * Math.PI *radius; } Public voidSetradius (DoubleNewradius) { This. Radius =Newradius; } Public Static voidMain (string[] args) {//TODO auto-generated Method Stubtest_1106 Circle1 =Newtest_1106 (); DoubleArea=Circle1.getarea (); System.out.println (area); test_1106 Circle2=Newtest_1106 (10); System.out.println (Circle2.getarea ()); System.out.println (Circle1.getperimeter ()); System.out.println (Circle2.getperimeter ()); Doubleridius=10; Doubleareacircle=math.pi*ridius*Ridius; System.out.println (areacircle); Circle2.setradius (5); System.out.println (Circle2.getarea ()); }}
Packagetop.hyself; Public class$TV {//Init Public intChannel = 1; Public intVolume = 1; Public BooleanPower =false; Public voidPowerOn () {Power=true; System.out.println ("Welcome to $TV, the TV has been started!" "); } Public voidPowerOff () {Power=false; System.out.println ("Off the computer ..."); System.out.println ("Turned off!" "); } Public intGetchannel () {returnChannel; } Public voidSetchannel (intChannel) { if(Power) {if(channel >= 1 && channel <= 100) { This. Channel =Channel; System.out.println ("Watching:" + Channel + "channel"); }Else{System.out.println ("You didn't buy this channel signal! "); } }Else{System.out.println ("Error! Error 404, please check if your TV is on or in trouble! "); } } Public voidChannelup () {if(Power && Channel < 100) Channel++; ElseSystem.out.println ("Can't go any further!") "); } Public voidChanneldown () {if(Power && Channel > 1) Channel--; ElseSystem.out.println ("The TV is also limited!") "); } Public voidVolumeup () {if(Power && Volume < 10) {Volume++; System.out.println (The current volume is: "+ volume +"%! "); }ElseSystem.out.println ("Can't go any further!") "); } Public voidVolumedown () {if(Power && Volume > 0) {Volume--; if(Volume = = 0) System.out.println ("The TV is muted!" "); }ElseSystem.out.println ("The TV is also limited!") "); }}
Packagetop.hyself;ImportJava.util.Scanner;ImportOrg.omg.CORBA.portable.ValueOutputStream; Public classTv$demo { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner scan =NewScanner (system.in); $TV Hyper=New$TV (); Hyper.poweron (); System.out.print ("Manually Enter the channel number:"); inttemp =integer.valueof (Scan.nextline ());; Hyper.setchannel (temp); Hyper.getchannel (); Hyper.volumedown (); Hyper.volumedown (); }}
Java 2017.11.06 Yang Haoning jobs (1)