admin管理员组文章数量:1648425
- 风扇类
- 代码
package fan;
/**
*
* @author shinan
*/
public class Fan {
/**
* @param args the command line arguments
*/
static int SLOW=1;
static int MEDIUM=2;
static int FAST=3;
private int speed=SLOW;
private boolean on =false;
private double radius=5;
private String color ="blue";
public Fan(){
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public boolean getOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String tostring(){
if(on)
return " speed " + speed + " color " + color + " radius " + radius;
else
return " fan is off " + " color " + color + " radius " + radius;
}
public static void main(String[] args) {
Fan fan1=new Fan();
fan1.setSpeed(FAST);
fan1.setRadius(10);
fan1.setColor("yellow");
fan1.setOn(true);
Fan fan2=new Fan();
fan2.setSpeed(MEDIUM);
System.out.println("fan1:" + fan1.tostring());
System.out.println("fan2:" + fan2.tostring());
}
}
- 运行结果截图
- UML图:
- 账户类
- 代码
package account;
import java.util.Date;
/**
*
* @author shinan
*/
public class Account {
/**
* @param args the command line arguments
*/
private int id=0;
private double balance=0;
private double annualInterestRate=0;
private Date dateCreated;
public Account() {//无参构造函数
this.dateCreated=new Date();
}
public Account(int id,double balance){
this.id=id;
this.balance=balance;
this.dateCreated=new Date();
}
public int getId(){
return id;
}
public void setId(int id){
this.id=id;
}
public double getBalance(){
return balance;
}
public void setBalance(int balance){
this.balance=balance;
}
public double getAnnualInterestRate(){
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate){
this.annualInterestRate=annualInterestRate;
}
public Date getDateCreated(){//dateCreated的访问器
return dateCreated;
}
public double getMonthlyInterestRate(){//返回月利率
return annualInterestRate/12;
}
public void withDraw(double num){//提取特定数额
balance-=num;
}
public void deposit(double num){//存取特定数额
balance+=num;
}
public static void main(String[] args) {
// TODO code application logic here
Account account=new Account();
account.setId(1122);
account.setId(1122);
account.setAnnualInterestRate(0.045);
account.withDraw(2500);
account.deposit(3000);
System.out.println("the deposit is "+ account.getBalance());
System.out.println("the MonthlyInterestRate is "+ account.getMonthlyInterestRate());
System.out.println("the dateCreated is "+ account.getDateCreated());
}
}
- 运行结果截图
- UML图
版权声明:本文标题:设计一个名为Account的账户类和一个名为Fan的风扇类 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729498168a1203158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论