chapter4程序代码
来源:互联网 发布:win10破解版office软件 编辑:程序博客网 时间:2024/05/16 02:02
private double salary=1800;
public void setSalary(double salary){
if(salary>1800&&salary<=6000){
this.salary=salary;
}
}
public double getSalary(){
return salary;
}
}
public class Example4_16{
public static void main(String args[]){
Employee zhang=new Employee();
Employee wang=new Employee();
zhang.setSalary(100);
System.out.println("zhang的薪水:"+zhang.getSalary());
wang.setSalary(3888);
System.out.println("wang的薪水:"+wang.getSalary());
}
}
2、public class Rectangle{
private double x,y,height;
private double width;
public void setX(double x){
this.x=x;
}
public double getX(){
return x;
}
public void setY(){
this.y=y;
}
public double getY(){
return y;
}
public void setWidth(double width){
if(width<=0)
this.width=0;
else
this.width=width;
}
public double getWidth(){
return width;
}
public void setHeight(double height){
if(height<=0)
height=0;
else
this.height=height;
}
public double getHeght(){
return height;
}
}
public class Circle {
private double x,y,radius;
public void setX(double x){
this.x=x;
}
public double getX(){
return x;
}
public void setY(){
this.y=y;
}
public double getY(){
return y;
}
public void setRadius(double radius){
if(radius<0)
this.radius=0;
else
this.radius=radius;
}
public double getRadius(){
return radius;
}
}
public class Geometry {
private Rectangle rect;
private Circle circle;
Geometry(Rectangle rect,Circle circle){
this.rect=rect;
this.circle=circle;
}
public void setCirclePosition(double x,double y){
circle.setX(x);
circle.setY();
}
public void setCircleRadius(double radius){
circle.setRadius(radius);
}
public void setRectanglePosition(double x,double y){
rect.setX(x);
rect.setY();
}
public void setRectangleWidthAndHeight(double w,double h){
rect.setWidth(w);
rect.setHeight(h);
}
public void showState(){
double circleX=circle.getX();
double rectX=rect.getX();
if(rectX-circleX==circle.getRadius()*2)
System.out.println("图形中的矩形在圆的右侧");
if(circleX-rectX==rect.getWidth())
System.out.println("图形中的矩形在圆的左侧");
}
}
public class MainClass {
public static void main(String args[]){
Rectangle rect1=new Rectangle(),rect2=new Rectangle();
Circle circle1=new Circle(),circle2=new Circle();
Geometry geometryOne,geometryTwo;
geometryOne=new Geometry(rect1,circle1);
geometryOne.setRectanglePosition(30,40);
geometryOne.setRectangleWidthAndHeight(120,80);
geometryOne.setCirclePosition(150,30);
geometryOne.setCircleRadius(60);
geometryTwo=new Geometry(rect2,circle2);
geometryTwo.setRectanglePosition(160, 160);
geometryTwo.setRectangleWidthAndHeight(120,80);
geometryTwo.setCirclePosition(40,30);
geometryTwo.setCircleRadius(60);
geometryOne.showState();
geometryTwo.showState();
}
}
3、
public class Example4_18 {
public static void main(String args[]){
char a[]={'a','b','c','D','E','F'};
for(int i=0;i<a.length;i++){
if(Character.isLowerCase(a[i])){
a[i]=Character.toUpperCase(a[i]);
}
else if(Character.isUpperCase(a[i])){
a[i]=Character.toLowerCase(a[i]);
}
}
for(int i=0;i<a.length;i++){
System.out.printf("%6c", a[i]);
}
}
}
4、
public class Example4_19 {
public static void main(String args[]){
Integer m[]=new Integer[10];
for(int i=0;i<m.length;i++){
m[i]=new Integer(101+i);
}
for(int i=0;i<m.length;i++){
System.out.println(m[i].intValue());
}
}
}
- chapter4程序代码
- chapter4
- chapter4
- Chapter4
- MFC与坦克大战系列(奇迹冬瓜)---chapter4(坦克总程序代码)
- 程序代码
- 程序代码
- 程序代码
- chapter4:ConfiguringtheNetworkEnvironment
- Chapter4 表达式
- MetaProgramming Chapter4
- CCNA-Cisco-Chapter4
- CCNA-Cisco-Chapter4
- CCNA2-Cisco-Chapter4
- 【C++】Chapter4:代理模式
- 【Chapter4】还是do_GET
- chapter4 CSS样式表
- chapter4 拦截器
- welcome to 学渣的专栏
- FBO
- js返回顶部实例
- 黑马程序员-------Java网络编程
- BMC项目中用到的python脚本整理
- chapter4程序代码
- 判断回文字符串
- 网页三剑客
- 链接动态库vs链接静态库
- zoj2110Tempter of the Bone
- 获取app图片
- 段寄存器的结构
- 第一部分 基本语言 第三章 标准库类型(3.3标准库vector类型)
- VC++程序导出数据到EXCEL