第四次上机
Posted heguo194508
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第四次上机相关的知识,希望对你有一定的参考价值。
package electriccharge;
public class Power {
final double PRICE = 1.2;
private double lastmonthpower;
private double thismonthpower;
public void setlastmonthpower(double change){
this.lastmonthpower = change;
}
public double getlastmonthpower(){
return this.lastmonthpower;
}
public void setthismonthpower(double change){
this.thismonthpower = change;
}
public double getthismonthpower() {
return this.thismonthpower;
}
public double compute(double lastmonthpower,double thismonthpower){
return (thismonthpower-lastmonthpower)*PRICE;
}
}
package electriccharge;
public class Testpower {
public static void main(String[] args){
Power p1 = new Power();
Power p2 = new Power();
p1.setlastmonthpower(1000);
p1.setthismonthpower(1200);
p2.setlastmonthpower(1200);
p2.setthismonthpower(1450);
System.out.println("本月电费为:");
System.out.println (p1.compute(p1.getlastmonthpower(),p1.getthismonthpower()));
p2.setthismonthpower(1500);
System.out.println("本月电费为:");
System.out.println(p2.compute(p2.getlastmonthpower(),p2.getthismonthpower()));
}
}
以上是关于第四次上机的主要内容,如果未能解决你的问题,请参考以下文章