package JavaPractice;
2 class ElectricCharge
3 {
4 private double lastnum,thisnum;
5 public ElectricCharge()
6 {
7
8 }
9 public ElectricCharge(double lastnum, double thisnum)
10 {
11 this.lastnum = lastnum;
12 this.thisnum = thisnum;
13 }
14 public double getLastnum()
15 {
16 return lastnum;
17 }
18 public void setLastnum(double lastnum)
19 {
20 this.lastnum = lastnum;
21 }
22 public double getThisnum()
23 {
24 return thisnum;
25 }
26 public void setThisnum(double thisnum)
27 {
28 this.thisnum = thisnum;
29 }
30 public void PrintMessage()
31 {
32 System.out.println("上月用电为:"+lastnum+" 本月用电为:"+thisnum);
33 }
34
35 }
36 public class TestEC
37 {
38 public static void main(String[] args)
39 {
40 ElectricCharge ec1=new ElectricCharge();
41 ec1.setLastnum(1000);
42 ec1.setThisnum(1200);
43 System.out.println("用户一家的用电情况为:");
44 ec1.PrintMessage();
45 System.out.println("本月电费为:"+ec1.getThisnum()1.2);
46 System.out.println();
47
48 ElectricCharge ec2=new ElectricCharge(1200,1450);
49 ec2.setThisnum(1500);
50 System.out.println("用户二家的用电情况为:");
51 ec2.PrintMessage();
52 System.out.println("本月电费为:"+ec2.getThisnum()1.2);
53
54
55 }
56 }