JAVA exercises 9 and java exercises
public class Circle { private double radius; public Circle(){ this.radius=1; } public Circle(double radius){ this.radius=radius; } public double getArea(){ return radius*radius*Math.PI; } public double getPerimeter(){ return 2*radius*Math.PI; } public void setRadius(double newRadius) { this.radius=newRadius; }}
Public class Democirle {public static void main (String [] args) {// method stub automatically generated by TODO Circle circle1 = new Circle (); System. out. println (circle1.getArea (); Circle circle2 = new Circle (10); System. out. println (circle2.getArea (); Circle circle3 = new Circle (); System. out. println (circle3.getPerimeter (); Circle circle4 = new Circle (10); System. out. println (circle4.getPerimeter (); circle2.setRadius (2); System. out. println (circle2.getPerimeter ());}}
Public class Simplecircle {private double radius; public Simplecircle () {this. radius = 1;} public Simplecircle (double radius) {this. radius = radius;} public double getArea () {return radius * Math. PI;} public double getPerimeter () {return 2 * radius * Math. PI;} public void setRadius (double newRadius) {this. radius = newRadius;} public static void main (String [] args) {// The method stub automatically generated by TODO Circle circle1 = new Circle (); System. out. println (circle1.getArea (); Circle circle2 = new Circle (5); System. out. println (circle2.getArea (); Circle circle3 = new Circle (); System. out. println (circle3.getPerimeter (); Circle circle4 = new Circle (10); System. out. println (circle4.getPerimeter (); circle2.setRadius (2); System. out. println (circle2.getPerimeter ());}}
Public class TestTV {public static void main (String [] args) {// The method used to generate automatically generated TODO methods. TV tv1 = new TV (); tv1.turnOn (); tv1.setChannel (6 ); tv1.setChannel (121); tv1.setVolumeLevel (5); tv1.setVolumeLevel (9); // tv1.turnOff (); // tv1.setChannel (6); // tv1.setVolumeLevel (5 ); TV tv2 = new TV (); tv2.turnOn (); System. out. println ("TV2's channel is" + tv2.channel + "and volume is" + tv2.volumeLevel); tv2.channelUp (); tv2.volumeUp (); System. out. println ("TV2's channel is" + tv2.channel + "and volume is" + tv2.volumeLevel );}}