Java作业九(2017-11-6)
/*圆的类*/
public class R {
private double radius; // 构造方法,有参构造
public R(double radius) {
this.radius = radius;
}
//方法的重载,参数不同
// 构造方法,无参构造
public R() {
this.radius = 1;
} // 求圆面积的方法
public double getArea() {
return radius * radius * Math.PI; }
//求圆的周长
public double getPerimeter() {
return 2 * Math.PI * radius;
}
public void setRadius(double newRadius) {
this.radius=newRadius;
} }
public class TR {
public static void main(String[] args) {
R circle1=new R();
double area=circle1.getArea();
System.out.println(area);
R circle2=new R(20);
System.out.println(circle2.getArea());
System.out.println(circle1.getPerimeter());
System.out.println(circle2.getPerimeter());
double ridius=8;
double areaCircle=Math.PI*ridius*ridius;
System.out.println(areaCircle);
circle2.setRadius(10);
System.out.println(circle2.getArea());
}
}

/*圆类的和并*/
public class TR { private double radius;
public TR() {
this.radius=1;
}
public TR(double radius){
this.radius=radius;
}
public double getArea() {
return Math.PI*radius*radius;
}
public double getPerimeter() {
return 2*Math.PI*radius;
} public static void main(String[] args) {
TR cir1=new TR();
System.out.println("The area of the circle of radius "+cir1.radius+" is "+cir1.getArea());
TR cir2=new TR(100);
System.out.println("The area of the circle of radius "+cir2.radius+" is "+cir2.getArea());
} }

/*造电视*/
public class TV {
public int channel=1;
public int volumeLevel=1;
public boolean on=false; public TV() { }
public void turnOn() {
on =true;
System.out.println("电视已启动");
}
public void turnOff() {
on=false;
System.out.println("电视已关闭");
}
public int getChannel() {
return channel;
}
public void setChannel(int channel) {
if(on) {
System.out.println("电视启动可以换台。");
if(channel>=1&&channel<=120) {
this.channel = channel;
System.out.println("频道已经调到 "+channel+" 台");
}else {
System.out.println("你要调的频道不存在。");
}
}else {
System.out.println("电视关闭不能换台");
}
}
public int getVolumeLevel() {
return volumeLevel;
}
public void setVolumeLevel(int volumeLevel) {
if(on) {
System.out.println("电视启动可调声音");
if(volumeLevel>=1&&volumeLevel<=7) {
this.volumeLevel = volumeLevel;
System.out.println("声音的大小设置成了 "+volumeLevel+" 大小");
}
}else {
System.out.println("电视关闭不能调声音");
} }
public void channelUp() {
if(on&&channel<120) {
channel++;
}
}
public void channelDown() {
if(on&&channel>1) {
channel--;
}
}
public void volumeUp() {
if(on&&volumeLevel<7) {
volumeLevel++;
}
}
public void volumeDown() {
if(on&&volumeLevel>1) {
volumeLevel--;
}
}
}
public class TextTV {
public static void main(String[] args) {
TV tv1=new TV();
tv1.turnOff();
tv1.setChannel(30);
tv1.setVolumeLevel(3);
TV tv2=new TV();
tv2.turnOn();
System.out.println("CCTV1's channel is "+tv2.channel+" and volume is "+tv1.volumeLevel);
tv2.channelUp();
System.out.println("CCTV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
tv2.channelUp();
System.out.println("CCTV3's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
tv2.channelUp();
System.out.println("CCTV4's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
}
}

Java作业九(2017-11-6)的更多相关文章
- Java 面试宝典-2017
http://www.cnblogs.com/nelson-hu/p/7190163.html Java面试宝典-2017 Java面试宝典2017版 一. Java基础部分........... ...
- Java面试宝典-2017
Java面试宝典2017版 一. Java基础部分........................................................................... ...
- 201521123082 《Java程序设计》第11周学习总结
201521123082 <Java程序设计>第11周学习总结 标签(空格分隔):java 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. Answe ...
- 201521123067 《Java程序设计》第11周学习总结
201521123067 <Java程序设计>第11周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线 ...
- 2017/11/3 Leetcode 日记
2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...
- 20145202马超 2016-2017-2 《Java程序设计》第11周学习总结
20145202马超 2016-2017-2 <Java程序设计>第11周学习总结 教材学习内容总结 XX 教材学习中的问题和解决过程 教材学习有问题先去https://shimo.im/ ...
- 20175212童皓桢 《Java程序设计》第11周学习总结
20175212童皓桢 <Java程序设计>第11周学习总结 教材学习内容总结 一.URL类 1.一个URL对象通常包含最基本的三部分信息:协议.地址.资源 2.构造方法: public ...
- 第五次Java作业
作业一: 文件显示列表框. 增加了下拉式组合框,text区域设置颜色为红色. import javax.swing.*; import java.awt.*; import java.io.File; ...
- [LOJ 6249]「CodePlus 2017 11 月赛」汀博尔
Description 有 n 棵树,初始时每棵树的高度为 H_i,第 i 棵树每月都会长高 A_i.现在有个木料长度总量为 S 的订单,客户要求每块木料的长度不能小于 L,而且木料必须是整棵树(即不 ...
随机推荐
- 如何获取AWS的Access Key ID 和 Secret Access Key (Unable to find credentials)
获取AWS的Access Key ID 和 Secret Access Key 是你可以访问AWS的依据,比如S3的“使用预签名 URL 上传对象”. 1.登录AWS控制台 2.在“AWS servi ...
- 基于Https协议返回Jason字符串
一:代码结构 二:框架结果: spring+springMvc+springJdbc 三:源代码 1:Ctrl 层 package com.todaytech.yth.gdsd.base.DataIn ...
- 2-2、安装Filebeat
安装filebeat 第1步:安装Filebeat 开始之前:如果尚未安装Elastic Stack,请立即执行此操作. 请参阅Getting started with the Elastic Sta ...
- python json按输入顺序输出内容
通过使用collecions,进行排序.collections是一个python的内建模块. import collections dic = collections.OrderedDict() # ...
- 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165323
1.Kali下载路径 由于之前的课程中已经安装过VMware虚拟机,这一个步骤就省去 2.安装 (1)创建新的虚拟机->典型->添加镜像路径 (2)选择操作系统linux (3)进行虚拟机 ...
- 【Idea】idea code style配置eclipse code formatter
在eclipse中有自动配置code style的功能 ,但是idea上却没有,这个时候需要自己手工配置 1. 在idea中找到Preference->Plugins->Browse re ...
- ubuntu配置小飞机
现在有两种方式在ubuntu配置本地shadowsocks(前提已经在服务器上搭建好了ss) windows,ios和安卓配置都是gui,没什么好说的.然后前期工作什么买vps啊,比较无脑,不想记录这 ...
- James Munkres Topology: Lemma 21.2 The sequence lemma
Lemma 21.2 (The sequence lemma) Let \(X\) be a topological space; let \(A \subset X\). If there is a ...
- 小程序实现GBK编码数据转为Unicode/UTF8
首先,不存在一种计算算法将GBK编码转换为Unicode编码,因为这两套编码本身毫无关系. 要想实现两者之间的互转,只能通过查表法实现. 在浏览器中实现编码转换,只需要简单两句: var x = ne ...
- java写word转pdf
https://blog.csdn.net/csdnFlyFun/article/details/79523262