JAVA exercises 9 and java exercises

Source: Internet
Author: User

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 );}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.