董珈圻的第三次bolg,期末总结

一.前言

本学期开始接触java到现在已经有一学期时间,在这一学期之间里,我已经学习了很多关于面向对象的知识,做了老师布置给我的习题,并且自己通过老师的分享学习了很多新知识,这是我第三次写博客,下面我对第一学期相关内容做总结,其中包括滇西计费,javaFx等等。

二.学习总结

1.作业总结

1. 电信计费系列7.1-7.3

(1)7.1

题目:如下

 

 

 代码:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ArrayList<User> Users = new ArrayList<>();
        int numC = 0;
        String callNumber;
        String answerNumber;
        String startTime;
        String endTime;
        String line;
        LandPhoneInCityRule a0 =new LandPhoneInCityRule();
        LandPhoneInProvinceRule a1 = new LandPhoneInProvinceRule();
        LandPhoneInlandRule a2 =new LandPhoneInlandRule();
        ArrayList<ChargeRule> c = new ArrayList<>();
        c.add(a0);
        c.add(a1);
        c.add(a2);
        Scanner a = new Scanner(System.in);
        String kh = ("[u]-0791[0-9]{7,8}\\s[0]");
        String jl = "[t]-0791[0-9]{7,8}\\s" + "0[0-9]{9,11}\\s" +
                "((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.(((0?[13578]|1[02])\\.(0?[1-9]|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.((([13578]|1[02])\\.([1-9]|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])";
        line = a.nextLine();
        while (!line.equals("end")){
            if (line.matches(kh)) {
                String[] kh1 = line.split("-");
                kh1 = kh1[1].split(" ");
                    for(User x:Users){
                        if(x.getNumber().equals(kh1[0])){
                            numC = 1;
                            break;
                        }
                    }
                    if(numC == 0){
                        User user = new User();
                        user.setNumber((kh1[0]));
                        Users.add(user);
                    }
            }else if(line.matches(jl)){
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                callNumber = jl1[0];
                answerNumber = jl1[1];
                CallRecord callRecord = new CallRecord();
                callRecord.setCallingNumber(callNumber);
                callRecord.setCallingAddressAreaCode(callNumber.substring(0,4));
                callRecord.setAnswerNumber(answerNumber);
                callRecord.setAnswerAddressAreaCode(answerNumber.substring(0,4));
                try{
                    SimpleDateFormat aq2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    startTime = jl1[2]+" "+jl1[3];
                    endTime = jl1[4]+" "+jl1[5];
                    Date stareTimeDate = aq2.parse(startTime);
                    Date endTimeDate = aq2.parse(endTime);
                    callRecord.setStartTime(stareTimeDate);
                    callRecord.setEndTime(endTimeDate);
                    callRecord.setCallingNumber(callNumber);
                    callRecord.setCallingAddressAreaCode(callNumber.substring(0,4));
                    callRecord.setAnswerNumber(answerNumber);
                    callRecord.setAnswerAddressAreaCode(answerNumber.substring(0,4));
                    for(User user: Users){//存通话记录
                        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
                            if(user.getNumber().substring(0,4).equals(callRecord.getAnswerAddressAreaCode())){
                                user.getUserRecords().addAnswerInCityRecords(callRecord);
                            }else if(callRecord.getAnswerNumber().startsWith("079")|| callRecord.getAnswerNumber().startsWith("0701")){
                                user.getUserRecords().addAnswerInProvinceRecords(callRecord);
                            }else{
                                user.getUserRecords().addAnswerInLandRecords(callRecord);
                            }
                        }
                    }
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
                line = a.nextLine();
        }
        for(User user:Users){
            user.getChargeMode().setChargeRules(c);
        }
        for(int i=0;i<Users.size()-1;i++){
            for(int j=i+1;j<Users.size();j++){
                if(Double.parseDouble(Users.get(i).getNumber())>Double.parseDouble(Users.get(j).getNumber())){
                    User con;
                    con = Users.get(i);
                    Users.set(i,Users.get(j));
                    Users.set(j,con);
                }
            }
        }
        for(User user: Users){
            user.setBalance(user.getBalance()-user.getChargeMode().calCost(user.getUserRecords()));
            System.out.printf("%s ",user.getNumber());
            System.out.printf("%.1f ",80-user.getBalance());
            System.out.printf("%.1f\n",user.getBalance());
        }
    }
}
abstract class CallChargeRule extends ChargeRule{//计费规则父类
    public double calCost(ArrayList<CallRecord> callRecords){
        return 1;
    }
}
 class CallRecord extends CommunicationRecord {//具体的某一通话记录类
    private Date StartTime;
    private Date endTime;
    private String callingAddressAreaCode;
    private String answerAddressAreaCode;

    public Date getStartTime() {
        return StartTime;
    }

    public void setStartTime(Date startTime) {
        StartTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getCallingAddressAreaCode() {
        return callingAddressAreaCode;
    }

    public void setCallingAddressAreaCode(String callingAddressAreaCode) {
        this.callingAddressAreaCode = callingAddressAreaCode;
    }

    public String getAnswerAddressAreaCode() {
        return answerAddressAreaCode;
    }

    public void setAnswerAddressAreaCode(String answerAddressAreaCode) {
        this.answerAddressAreaCode = answerAddressAreaCode;
    }
}
abstract class ChargeMode {//计费规则的合计
    private ArrayList<ChargeRule> chargeRules = new ArrayList<ChargeRule>();

    public ArrayList<ChargeRule> getChargeRules() {
        return chargeRules;
    }

    public void setChargeRules(ArrayList<ChargeRule> chargeRules) {
        this.chargeRules = chargeRules;
    }

    public double calCost(UserRecords userRecords){
        return 1;
    }

    public double getMonthlyRen(){
        return 1;
    }
}
abstract class ChargeRule {
    public double calCost(ArrayList<CallRecord> callRecords){
        return 1;
    }
}
abstract class CommunicationRecord {
    private String callingNumber;
    private String answerNumber;

    public String getCallingNumber() {
        return callingNumber;
    }

    public void setCallingNumber(String callingNumber) {
        this.callingNumber = callingNumber;
    }

    public String getAnswerNumber() {
        return answerNumber;
    }

    public void setAnswerNumber(String answerNumber) {
        this.answerNumber = answerNumber;
    }
}
class LandlinePhoneCharging extends ChargeMode {
    private double monthlyRent = 20;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1,cost2,cost3;
        cost1 = getChargeRules().get(0).calCost(userRecords.getAnswerInCityRecords());
        cost2 = getChargeRules().get(1).calCost(userRecords.getAnswerInProvinceRecords());
        cost3 = getChargeRules().get(2).calCost(userRecords.getAnswerInLandRecords());
        return cost1 + cost2 + cost3 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class LandPhoneInCityRule extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long  miao = 0;
        long fen = 0;
        long sum= 0;
        for(int i=0;i<callRecords.size();i++){
            callRecords.get(i);
            miao=(callRecords.get(i).getEndTime().getTime()-callRecords.get(i).getStartTime().getTime())/1000;
            fen = miao / 60;
            if(miao % 60!=0){
                fen = fen + 1;
            }
            sum=sum+fen;
        }
        return sum*0.1;
    }
}
class LandPhoneInlandRule extends CallChargeRule{
    @Override
        public double calCost(ArrayList<CallRecord> callRecords){
        long  miao = 0;
        long fen = 0;
        long sum= 0;
        for(int i=0;i<callRecords.size();i++){
            callRecords.get(i);
            miao=(callRecords.get(i).getEndTime().getTime()-callRecords.get(i).getStartTime().getTime())/1000;
            fen = miao / 60;
            if(miao % 60!=0){
                fen = fen + 1;
            }
            sum=sum+fen;
        }
        return sum*0.6;
    }
}

class LandPhoneInProvinceRule extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long  miao = 0;
        long fen = 0;
        long sum= 0;
        for(int i=0;i<callRecords.size();i++){
            callRecords.get(i);
            miao=(callRecords.get(i).getEndTime().getTime()-callRecords.get(i).getStartTime().getTime())/1000;
            fen = miao / 60;
            if(miao % 60!=0){
                fen = fen + 1;
            }
            sum=sum+fen;
        }
        return sum*0.3;
    }
}
class MessageRecord extends CommunicationRecord{
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

class User {
    private UserRecords userRecords = new UserRecords();
    private double balance = 100;
    private ChargeMode chargeMode = new LandlinePhoneCharging();
    private String number ;

    public UserRecords getUserRecords() {
        return userRecords;
    }

    public void setUserRecords(UserRecords userRecords) {
        this.userRecords = userRecords;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public ChargeMode getChargeMode() {
        return chargeMode;
    }

    public void setChargeMode(ChargeMode chargeMode) {
        this.chargeMode = chargeMode;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public double calBalance(){

        return 1;
    }

    public double calCost(){

        return 1;
    }
}

class UserRecords {
    private ArrayList<CallRecord> callingInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<MessageRecord> sendMessageRecords = new ArrayList<MessageRecord>();
    private ArrayList<MessageRecord> receiveMessageRecords = new ArrayList<MessageRecord>();

    public ArrayList<MessageRecord> getSendMessageRecords() {
        return sendMessageRecords;
    }

    public ArrayList<MessageRecord> getReceiveMessageRecords() {
        return receiveMessageRecords;
    }

    public ArrayList<CallRecord> getCallingInCityRecords() {
        return callingInCityRecords;
    }

    public ArrayList<CallRecord> getCallingInProvinceRecords() {
        return callingInProvinceRecords;
    }

    public ArrayList<CallRecord> getCallingInLandRecords() {
        return callingInLandRecords;
    }

    public ArrayList<CallRecord> getAnswerInCityRecords() {
        return answerInCityRecords;
    }

    public ArrayList<CallRecord> getAnswerInProvinceRecords() {
        return answerInProvinceRecords;
    }

    public ArrayList<CallRecord> getAnswerInLandRecords() {
        return answerInLandRecords;
    }

    public void addCallingInCityRecords(CallRecord callRecord) {
        callingInCityRecords.add(callRecord);
    }

    public void addCallingInProvinceRecords(CallRecord callRecord) {
        callingInProvinceRecords.add(callRecord);
    }

    public void addCallingInLandRecords(CallRecord callRecord) {
         callingInLandRecords.add(callRecord);
    }

    public void addAnswerInCityRecords(CallRecord callRecord) {
         answerInCityRecords.add(callRecord);
    }

    public void addAnswerInProvinceRecords(CallRecord callRecord) {
         answerInProvinceRecords.add(callRecord);
    }

    public void addAnswerInLandRecords(CallRecord callRecord) {
        answerInLandRecords.add(callRecord);
    }
    public void addSendMessageRecords(CallRecord callRecord) {

    }

    public void addReceiveMessageRecords(CallRecord callRecord) {

    }

    public void addSendMessageRecords(MessageRecord messageRecord) {
        sendMessageRecords.add(messageRecord);
    }

    public void addReceiveMessageRecords(MessageRecord messageRecord) {
        receiveMessageRecords.add(messageRecord);
    }
}

遇到的困难:

本次题目系列是由老师降低难度为我们准备的,咯啊是为我们准备好了类图,为我们解决的设计问题,但是看懂类图是我遇到的第一份困难,然后就是计费方法的实现,因为计费规则比较复杂,所以浪费了很大部分时间,最后遇到的困难就是输入数据出理,因为还需要使用正则表达式,所以处理数据花了很长时间,因为要看懂类图和了解类之间的关系才可以处理数据,所以这是最大的困难,最后我遇到了个小bug,导致有个点过不去,是我傻逼了,要每次记录单独计算时间,我把所有时间加在一起计算了。

解决方法:最主要的就是看懂老师给的类图,如果看不懂真的就写不明白,你根本不知道这个数据怎么用,放到哪个里面,用什么来计算。

(2)7-2

 

 

 代码:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        ArrayList<User> Users1 = new ArrayList<>();
        ArrayList<User> Users2 = new ArrayList<>();
        String callNumber;
        String answerNumber;
        String startTime;
        String endTime;
        String line;
        CallRecord callRecord;
        LandPhoneInCityRule_1 a0 =new LandPhoneInCityRule_1();
        LandPhoneInProvinceRule_3 a1 = new LandPhoneInProvinceRule_3();
        LandPhoneInlandRule_6 a2 =new LandPhoneInlandRule_6();
        shoufei_2 b1 = new shoufei_2();
        ArrayList<ChargeRule> c = new ArrayList<>();
        c.add(a0);
        c.add(a1);
        c.add(a2);
        c.add(b1);
        LandlinePhoneCharging UserAAA= new LandlinePhoneCharging();
        UserAAA.setChargeRules(c);
        MPhoneCharging UserBBB = new MPhoneCharging();
        UserBBB.setChargeRules(c);
        Scanner a = new Scanner(System.in);
        String kh = ("u-0791\\d{7,8}\\s0");
        String dh = ("[u]-1\\d{10}\\s[1]");
        String jlzz = "[t]-0791[0-9]{7,8}\\s0[0-9]{9,11}\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9]" +
                "[0-9]{3})\\.(((0?[13578]|1[02])\\.(0?[1-9]|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12][0-9]|30))|" +
                "(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]|[2468][048]|[3579]" +
                "[26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9]" +
                "[0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.((([13578]|1[02])\\.([1-9]|[12][0-9]|3[01]))|(([469]|11)\\." +
                "([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]" +
                "|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])";
        String jlzd = "[t]-0[0-9]{9,11}\\s1[0-9]{10}\\s0[0-9]{2,3}\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9]" +
                "[0-9]{2}|[1-9][0-9]{3})\\.(((0?[13578]|1[02])\\.(0?[1-9]|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12]" +
                "[0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]|[2468]" +
                "[048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\\s((([0-9]{3}[1-9]" +
                "|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.((([13578]|1[02])\\.([1-9]|[12][0-9]|3[01]))" +
                "|(([469]|11)\\.([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|" +
                "[13579][26])|(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])";
        String jldd = "[t]-1[0-9]{10}\\s0[0-9]{2,3}\\s1[0-9]{10}\\s0[0-9]{2,3}\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|" +
                "[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.(((0?[13578]|1[02])\\.(0?[1-9]|[12][0-9]|3[01]))|(([469]|11)\\." +
                "([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|" +
                "(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\\s" +
                "((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.((([13578]|1[02])\\.([1-9]" +
                "|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})" +
                "([48]|[2468][048]|[13579][26])|(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3])" +
                ":([0-5][0-9]):([0-5][0-9])";
        String jldz = "[t]-1[0-9]{10}\\s0[0-9]{2,3}\\s0[0-9]{9,11}\\s((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]|[0-9][1-9]" +
                "[0-9]{2}|[1-9][0-9]{3})\\.(((0?[13578]|1[02])\\.(0?[1-9]|[12][0-9]|3[01]))|(([469]|11)\\.([1-9]|[12]" +
                "[0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|[13579][26])|(([48]|[2468]" +
                "[048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\\s((([0-9]{3}[1-9]" +
                "|[0-9]{2}[1-9][0-9]|[0-9][1-9][0-9]{2}|[1-9][0-9]{3})\\.((([13578]|1[02])\\.([1-9]|[12][0-9]|3[01]))" +
                "|(([469]|11)\\.([1-9]|[12][0-9]|30))|(2\\.([1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})([48]|[2468][048]|" +
                "[13579][26])|(([48]|[2468][048]|[3579][26])00))\\.2\\.29))\\s([0-1]?[0-9]|2[0-3]):([0-5][0-9])" +
                ":([0-5][0-9])";
        line = a.nextLine();
        while (!line.equals("end")){
            if (line.matches(kh)) {
                Cun(Users1,line);
            }
            else if(line.matches(dh)){
                Cun(Users2,line);
            }else if(line.matches(jlzz)){
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                callNumber = jl1[0];
                answerNumber = jl1[1];
                callRecord = new CallRecord();
                try{
                    SimpleDateFormat aq2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    startTime = jl1[2]+" "+jl1[3];
                    endTime = jl1[4]+" "+jl1[5];
                    Date stareTimeDate = aq2.parse(startTime);
                    Date endTimeDate = aq2.parse(endTime);
                    callRecord.setStartTime(stareTimeDate);
                    callRecord.setEndTime(endTimeDate);
                    callRecord.setCallingNumber(callNumber);
                    callRecord.setAnswerNumber(answerNumber);
                    callRecord.setCallingAddressAreaCode(callNumber.substring(0,4));
                    callRecord.setAnswerAddressAreaCode(answerNumber.substring(0,4));
                    for(User user: Users1){//存通话记录
                        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
                            if(user.getNumber().substring(0,4).equals(callRecord.getAnswerAddressAreaCode())){
                                user.getUserRecords().addCallingInCityRecords(callRecord);
                            }else if(callRecord.getAnswerNumber().startsWith("079")|| callRecord.getAnswerNumber().startsWith("0701")){
                                user.getUserRecords().addCallingInProvinceRecords(callRecord);
                            }else{
                                user.getUserRecords().addCallingInLandRecords(callRecord);
                            }
                        }
                    }
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            } else if (line.matches(jlzd)) {
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                callNumber = jl1[0];
                answerNumber = jl1[1];
                callRecord = new CallRecord();
                try{
                    SimpleDateFormat aq2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    startTime = jl1[3]+" "+jl1[4];
                    endTime = jl1[5]+" "+jl1[6];
                    Date stareTimeDate = aq2.parse(startTime);
                    Date endTimeDate = aq2.parse(endTime);
                    callRecord.setStartTime(stareTimeDate);
                    callRecord.setEndTime(endTimeDate);
                    callRecord.setCallingNumber(callNumber);
                    callRecord.setAnswerNumber(answerNumber);
                    callRecord.setCallingAddressAreaCode(callNumber.substring(0,4));
                    callRecord.setAnswerAddressAreaCode(jl1[2]);
                    for(User user: Users1){//存通话记录
                        shineiboda(Users2, callNumber, answerNumber, callRecord, stareTimeDate, endTimeDate, user);
                    }
                    for(User userA: Users2){
                        if(userA.getNumber().equals(answerNumber)){
                            if(!callRecord.getAnswerAddressAreaCode().startsWith("079")&&!callRecord.getAnswerAddressAreaCode().startsWith("0701")){
                                userA.getUserRecords().addAnswerInLandRecords(callRecord);
                            }
                        }
                    }
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }

            }else if(line.matches(jldd)){
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                callNumber = jl1[0];
                answerNumber = jl1[2];
                callRecord = new CallRecord();
                try{
                    SimpleDateFormat aq2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    startTime = jl1[4]+" "+jl1[5];
                    endTime = jl1[6]+" "+jl1[7];
                    Date stareTimeDate = aq2.parse(startTime);
                    Date endTimeDate = aq2.parse(endTime);
                    callRecord.setStartTime(stareTimeDate);
                    callRecord.setEndTime(endTimeDate);
                    callRecord.setCallingNumber(callNumber);
                    callRecord.setCallingAddressAreaCode(jl1[1]);
                    callRecord.setAnswerNumber(answerNumber);
                    callRecord.setAnswerAddressAreaCode(jl1[3]);
                    for(User user: Users2){//存通话记录
                        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
                            if(callRecord.getCallingAddressAreaCode().equals("0791")){//电话在市内
                                shineiboda(Users2, callNumber, answerNumber, callRecord, stareTimeDate, endTimeDate, user);
                            } else if (callRecord.getCallingAddressAreaCode().startsWith("079")|| callRecord.getCallingAddressAreaCode().startsWith("0701")) {//在省内打电话
                                user.getUserRecords().CallInP(callRecord);
                            }else{//省外打电话
                                user.getUserRecords().callInL(callRecord);
                            }
                        }
                    }
                    for(User userA: Users2){
                        if(userA.getNumber().equals(answerNumber)){
                            if(!callRecord.getAnswerAddressAreaCode().startsWith("079")&&!callRecord.getAnswerAddressAreaCode().startsWith("0701")){
                                userA.getUserRecords().addAnswerInLandRecords(callRecord);
                            }
                        }
                    }
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
            else if(line.matches(jldz)){
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                callNumber = jl1[0];
                answerNumber = jl1[2];
                callRecord = new CallRecord();
                try{
                    SimpleDateFormat aq2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    startTime = jl1[3]+" "+jl1[4];
                    endTime = jl1[5]+" "+jl1[6];
                    Date stareTimeDate = aq2.parse(startTime);
                    Date endTimeDate = aq2.parse(endTime);
                    callRecord.setStartTime(stareTimeDate);
                    callRecord.setEndTime(endTimeDate);
                    callRecord.setCallingNumber(callNumber);
                    callRecord.setCallingAddressAreaCode(jl1[1]);
                    callRecord.setAnswerNumber(answerNumber);
                    callRecord.setAnswerAddressAreaCode(jl1[2].substring(0,4));
                    for(User user: Users2){//存通话记录
                        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
                            if(callRecord.getCallingAddressAreaCode().equals("0791")){//电话在市内
                                if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
                                    if(callRecord.getCallingAddressAreaCode().equals(callRecord.getAnswerAddressAreaCode())){
                                        user.getUserRecords().addCallingInCityRecords(callRecord);
                                    }else if(callRecord.getAnswerAddressAreaCode().startsWith("079")|| callRecord.getAnswerAddressAreaCode().startsWith("0701")){
                                        user.getUserRecords().addCallingInProvinceRecords(callRecord);
                                    }else{
                                        user.getUserRecords().addCallingInLandRecords(callRecord);
                                    }
                                }
                            } else if (callRecord.getCallingAddressAreaCode().startsWith("079")|| callRecord.getCallingAddressAreaCode().startsWith("0701")) {//在省内打电话
                                user.getUserRecords().CallInP(callRecord);
                            }else{
                                user.getUserRecords().callInL(callRecord);
                            }
                        }
                    }
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
            line = a.nextLine();
        }
        for(User user:Users1){
            user.setChargeMode(UserAAA);
        }
        for(User user:Users2){
            user.setChargeMode(UserBBB);
        }
        for(int i=0;i<Users1.size()-1;i++){
            for(int j=i+1;j<Users1.size();j++){
                if(Double.parseDouble(Users1.get(i).getNumber())>Double.parseDouble(Users1.get(j).getNumber())){
                    User con;
                    con = Users1.get(i);
                    Users1.set(i,Users1.get(j));
                    Users1.set(j,con);
                }
            }
        }
        for(int i=0;i<Users2.size()-1;i++){
            for(int j=i+1;j<Users2.size();j++){
                if(Double.parseDouble(Users2.get(i).getNumber())>Double.parseDouble(Users2.get(j).getNumber())){
                    User con;
                    con = Users2.get(i);
                    Users2.set(i,Users2.get(j));
                    Users2.set(j,con);
                }
            }
        }
        for(User user: Users1){
            user.setBalance(user.getBalance()-user.getChargeMode().calCost(user.getUserRecords()));
            System.out.printf("%s ",user.getNumber());
            System.out.printf("%.1f ",80-user.getBalance());
            System.out.printf("%.1f\n",user.getBalance());
        }
        for(User user: Users2){
            user.setBalance(user.getBalance()-user.getChargeMode().calCost(user.getUserRecords()));
            System.out.printf("%s ",user.getNumber());
            System.out.printf("%.1f ",85-user.getBalance());
            System.out.printf("%.1f\n",user.getBalance());
        }

    }


    public static void shineiboda(ArrayList<User> users2, String callNumber, String answerNumber, CallRecord callRecord, Date stareTimeDate, Date endTimeDate, User user) {
        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
            if(callRecord.getCallingAddressAreaCode().equals(callRecord.getAnswerAddressAreaCode())){
                user.getUserRecords().addCallingInCityRecords(callRecord);
                for(User userA: users2){
                }
            }else if(callRecord.getAnswerAddressAreaCode().startsWith("079")|| callRecord.getAnswerAddressAreaCode().startsWith("0701")){
                user.getUserRecords().addCallingInProvinceRecords(callRecord);
            }else{
                user.getUserRecords().addCallingInLandRecords(callRecord);
            }
        }
    }


    public static void Cun(ArrayList<User> Users, String line){
        int numC = 0;
        String[] kh1 = line.split("-");
        kh1 = kh1[1].split(" ");
        for(User x:Users){
            if(x.getNumber().equals(kh1[0])){
                numC = 1;
                break;
            }
        }
        if(numC == 0){
            User user = new User();
            user.setNumber((kh1[0]));
            Users.add(user);
        }
    }
}


abstract class CallChargeRule extends ChargeRule{//计费规则父类
    public double calCost(ArrayList<CallRecord> callRecords){
        return 1;
    }
    public long getTime(ArrayList<CallRecord> callRecords){
        long  miao = 0;
        long fen = 0;
        long sum= 0;
        for(int i=0;i<callRecords.size();i++){
            callRecords.get(i);
            miao=(callRecords.get(i).getEndTime().getTime()-callRecords.get(i).getStartTime().getTime())/1000;
            fen = miao / 60;
            if(miao % 60!=0){
                fen = fen + 1;
            }
            sum=sum+fen;
        }
        return sum;
    }
}
class CallRecord extends CommunicationRecord {//具体的某一通话记录类
    private Date StartTime;
    private Date endTime;
    private String callingAddressAreaCode;
    private String answerAddressAreaCode;

    public Date getStartTime() {
        return StartTime;
    }

    public void setStartTime(Date startTime) {
        StartTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getCallingAddressAreaCode() {
        return callingAddressAreaCode;
    }

    public void setCallingAddressAreaCode(String callingAddressAreaCode) {
        this.callingAddressAreaCode = callingAddressAreaCode;
    }

    public String getAnswerAddressAreaCode() {
        return answerAddressAreaCode;
    }

    public void setAnswerAddressAreaCode(String answerAddressAreaCode) {
        this.answerAddressAreaCode = answerAddressAreaCode;
    }
}
abstract class ChargeMode {//计费规则的合计
    private ArrayList<ChargeRule> chargeRules = new ArrayList<ChargeRule>();

    public ArrayList<ChargeRule> getChargeRules() {
        return chargeRules;
    }

    public void setChargeRules(ArrayList<ChargeRule> chargeRules) {
        this.chargeRules = chargeRules;
    }

    public double calCost(UserRecords userRecords){
        return 1;
    }

    public double getMonthlyRen(){
        return 1;
    }
}
abstract class ChargeRule {
    public double calCost(ArrayList<CallRecord> callRecords){
        return 1;
    }
}
abstract class CommunicationRecord {
    private String callingNumber;
    private String answerNumber;

    public String getCallingNumber() {
        return callingNumber;
    }

    public void setCallingNumber(String callingNumber) {
        this.callingNumber = callingNumber;
    }

    public String getAnswerNumber() {
        return answerNumber;
    }

    public void setAnswerNumber(String answerNumber) {
        this.answerNumber = answerNumber;
    }
}
class LandlinePhoneCharging extends ChargeMode {
    private double monthlyRent = 20;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1,cost2,cost3;
        cost1 = getChargeRules().get(0).calCost(userRecords.getCallingInCityRecords());
        cost2 = getChargeRules().get(1).calCost(userRecords.getCallingInProvinceRecords());
        cost3 = getChargeRules().get(2).calCost(userRecords.getCallingInLandRecords());
        return cost1 + cost2 + cost3 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class LandPhoneInCityRule_1 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.1;
    }
}
class LandPhoneInlandRule_6 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.6;
    }
}
class LandPhoneInProvinceRule_3 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.3;
    }
}
class MessageRecord extends CommunicationRecord{
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
class MPhoneCharging extends ChargeMode{
    private double monthlyRent = 15;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1,cost2,cost3,cost4,cost5,cost6;
        cost1 = getChargeRules().get(0).calCost(userRecords.getCallingInCityRecords());
        cost2 = getChargeRules().get(3).calCost(userRecords.getCallingInProvinceRecords());
        cost3 = getChargeRules().get(1).calCost(userRecords.getCallingInLandRecords());
        cost4 = getChargeRules().get(1).calCost(userRecords.getCallInP());
        cost5 = getChargeRules().get(2).calCost(userRecords.getCallInL());
        cost6 = getChargeRules().get(1).calCost(userRecords.getAnswerInLandRecords());
        return cost1 + cost2 + cost3+ cost4+ cost5+ cost6 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class shoufei_2 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        Long sum = getTime(callRecords);
        return sum*0.2;
    }
}
class User {
    private UserRecords userRecords = new UserRecords();
    private double balance = 100;
    private ChargeMode chargeMode;
    private String number ;

    public UserRecords getUserRecords() {
        return userRecords;
    }

    public void setUserRecords(UserRecords userRecords) {
        this.userRecords = userRecords;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public ChargeMode getChargeMode() {
        return chargeMode;
    }

    public void setChargeMode(ChargeMode chargeMode) {
        this.chargeMode = chargeMode;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public double calBalance(){

        return 1;
    }

    public double calCost(){

        return 1;
    }
}
class UserRecords {
    private ArrayList<CallRecord> callingInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callInP = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> CallInL = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<MessageRecord> sendMessageRecords = new ArrayList<MessageRecord>();
    private ArrayList<MessageRecord> receiveMessageRecords = new ArrayList<MessageRecord>();

    public ArrayList<MessageRecord> getSendMessageRecords() {
        return sendMessageRecords;
    }

    public ArrayList<MessageRecord> getReceiveMessageRecords() {
        return receiveMessageRecords;
    }


    public ArrayList<CallRecord> getCallingInCityRecords() {
        return callingInCityRecords;
    }

    public ArrayList<CallRecord> getCallingInProvinceRecords() {
        return callingInProvinceRecords;
    }

    public ArrayList<CallRecord> getCallingInLandRecords() {
        return callingInLandRecords;
    }

    public ArrayList<CallRecord> getCallInP() {
        return callInP;
    }
    public ArrayList<CallRecord> getCallInL() {
        return CallInL;
    }
    public ArrayList<CallRecord> getAnswerInCityRecords() {
        return answerInCityRecords;
    }

    public ArrayList<CallRecord> getAnswerInProvinceRecords() {
        return answerInProvinceRecords;
    }

    public ArrayList<CallRecord> getAnswerInLandRecords() {
        return answerInLandRecords;
    }

    public void addCallingInCityRecords(CallRecord callRecord) {
        callingInCityRecords.add(callRecord);
    }

    public void addCallingInProvinceRecords(CallRecord callRecord) {
        callingInProvinceRecords.add(callRecord);
    }

    public void addCallingInLandRecords(CallRecord callRecord) {
         callingInLandRecords.add(callRecord);
    }
    public void CallInP(CallRecord callRecord) {
        callInP.add(callRecord);
    }
    public void callInL(CallRecord callRecord) {
        CallInL.add(callRecord);
    }

    public void addAnswerInCityRecords(CallRecord callRecord) {
         answerInCityRecords.add(callRecord);
    }

    public void addAnswerInProvinceRecords(CallRecord callRecord) {
         answerInProvinceRecords.add(callRecord);
    }

    public void addAnswerInLandRecords(CallRecord callRecord) {
        answerInLandRecords.add(callRecord);
    }
    public void addSendMessageRecords(CallRecord callRecord) {

    }

    public void addReceiveMessageRecords(CallRecord callRecord) {

    }

    public void addSendMessageRecords(MessageRecord messageRecord) {
        sendMessageRecords.add(messageRecord);
    }

    public void addReceiveMessageRecords(MessageRecord messageRecord) {
        receiveMessageRecords.add(messageRecord);
    }
}

遇到的困难:

此题在上一道题的基础上增加了移动电话,是处理数据的困难有又增大了,计费规则更多,需要更多的正则表达式,但是在上一道题的基础上,此题没有更多的困难。

解决方法:

认真看懂类图,类图看懂真的不难,而且扩展性很强,所以才可以使用上一道题的基础,计费方法还是靠逻辑

(3)7-3

 

 

 代码:

import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ArrayList<User> Users3 = new ArrayList<>();
        String line;
        ArrayList<MessageChargeRule> d = new ArrayList<MessageChargeRule>();
        SendMessageRule c1=new SendMessageRule();
        d.add(c1);
        LandlinePhoneCharging UserAAA= new LandlinePhoneCharging();
        MPhoneCharging UserBBB = new MPhoneCharging();
        Mess Userccc = new Mess();
        Userccc.setChargeRuless(d);
        Scanner a = new Scanner(System.in);
        String dx = ("[u]-1\\d{10}\\s[3]");
        String jldx = "[m]-1[0-9]{10}\\s1[0-9]{10}\\s[[A-Z][a-z][0-9]\\s,.]+" ;
        line = a.nextLine();
        while (!line.equals("end")){
            if (line.matches(dx)) {
                Cun(Users3,line);
            }
            else if(line.matches(jldx)){
                String[] jl1 = line.split("-");
                jl1 = jl1[1].split(" ");
                MessageRecord messageRecord= new MessageRecord();
                messageRecord.setMessage(line.substring(26));
                messageRecord.setCallingNumber(jl1[0]);
                messageRecord.setAnswerNumber(jl1[1]);
                for(User user: Users3){//存通话记录
                    if(user.getNumber().equals(messageRecord.getCallingNumber())){
                        user.getUserRecords().addSendMessageRecords(messageRecord);
                    }
                }
            }
            line = a.nextLine();
        }
                for(int i=0;i<Users3.size()-1;i++){
            for(int j=i+1;j<Users3.size();j++){
                if(Double.parseDouble(Users3.get(i).getNumber())>Double.parseDouble(Users3.get(j).getNumber())){
                    User con;
                    con = Users3.get(i);
                    Users3.set(i,Users3.get(j));
                    Users3.set(j,con);
                }
            }
        }
        for(User user:Users3){
            user.setChargeMode(Userccc);
        }
        for(User user: Users3){
            user.setBalance(user.getBalance()-user.getChargeMode().calCost(user.getUserRecords()));
            System.out.printf("%s ",user.getNumber());
            System.out.printf("%.1f ",100-user.getBalance());
            System.out.printf("%.1f\n",user.getBalance());
        }

    }


    public static void shineiboda(ArrayList<User> users2, String callNumber, String answerNumber, CallRecord callRecord, Date stareTimeDate, Date endTimeDate, User user) {
        if(user.getNumber().equals(callNumber)&&endTimeDate.getTime()>stareTimeDate.getTime()){
            if(callRecord.getCallingAddressAreaCode().equals(callRecord.getAnswerAddressAreaCode())){
                user.getUserRecords().addCallingInCityRecords(callRecord);
                for(User userA: users2){
                }
            }else if(callRecord.getAnswerAddressAreaCode().startsWith("079")|| callRecord.getAnswerAddressAreaCode().startsWith("0701")){
                user.getUserRecords().addCallingInProvinceRecords(callRecord);
            }else{
                user.getUserRecords().addCallingInLandRecords(callRecord);
            }
        }
    }


    public static void Cun(ArrayList<User> Users, String line){
        int numC = 0;
        String[] kh1 = line.split("-");
        kh1 = kh1[1].split(" ");
        for(User x:Users){
            if(x.getNumber().equals(kh1[0])){
                numC = 1;
                break;
            }
        }
        if(numC == 0){
            User user = new User();
            user.setNumber((kh1[0]));
            Users.add(user);
        }
    }
}

abstract class CallChargeRule extends ChargeRule{//计费规则父类
    public double calCost(ArrayList<CallRecord> callRecords){
        return 1;
    }
    public long getTime(ArrayList<CallRecord> callRecords){
        long  miao = 0;
        long fen = 0;
        long sum= 0;
        for(int i=0;i<callRecords.size();i++){
            callRecords.get(i);
            miao=(callRecords.get(i).getEndTime().getTime()-callRecords.get(i).getStartTime().getTime())/1000;
            fen = miao / 60;
            if(miao % 60!=0){
                fen = fen + 1;
            }
            sum=sum+fen;
        }
        return sum;
    }
}
class CallRecord extends CommunicationRecord {//具体的某一通话记录类
    private Date StartTime;
    private Date endTime;
    private String callingAddressAreaCode;
    private String answerAddressAreaCode;

    public Date getStartTime() {
        return StartTime;
    }

    public void setStartTime(Date startTime) {
        StartTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getCallingAddressAreaCode() {
        return callingAddressAreaCode;
    }

    public void setCallingAddressAreaCode(String callingAddressAreaCode) {
        this.callingAddressAreaCode = callingAddressAreaCode;
    }

    public String getAnswerAddressAreaCode() {
        return answerAddressAreaCode;
    }

    public void setAnswerAddressAreaCode(String answerAddressAreaCode) {
        this.answerAddressAreaCode = answerAddressAreaCode;
    }
}
abstract class ChargeMode {//计费规则的合计
    private ArrayList<CallChargeRule> chargeRules = new ArrayList<CallChargeRule>();
    private ArrayList<MessageChargeRule> chargeRuless = new ArrayList<MessageChargeRule>();

    public ArrayList<CallChargeRule> getChargeRules() {
        return chargeRules;
    }

    public ArrayList<MessageChargeRule> getChargeRuless() {
        return chargeRuless;
    }

    public void setChargeRules(ArrayList<CallChargeRule> chargeRules) {
        this.chargeRules = chargeRules;
    }

    public void setChargeRuless(ArrayList<MessageChargeRule> chargeRuless) {
        this.chargeRuless = chargeRuless;
    }

    public double calCost(UserRecords userRecords){
        return 1;
    }

    public double getMonthlyRen(){
        return 1;
    }
}
abstract class ChargeRule {

}
abstract class CommunicationRecord {
    private String callingNumber;
    private String answerNumber;

    public String getCallingNumber() {
        return callingNumber;
    }

    public void setCallingNumber(String callingNumber) {
        this.callingNumber = callingNumber;
    }

    public String getAnswerNumber() {
        return answerNumber;
    }

    public void setAnswerNumber(String answerNumber) {
        this.answerNumber = answerNumber;
    }
}
class LandlinePhoneCharging extends ChargeMode {
    private double monthlyRent = 20;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1,cost2,cost3;
        cost1 = getChargeRules().get(0).calCost(userRecords.getCallingInCityRecords());
        cost2 = getChargeRules().get(1).calCost(userRecords.getCallingInProvinceRecords());
        cost3 = getChargeRules().get(2).calCost(userRecords.getCallingInLandRecords());
        return cost1 + cost2 + cost3 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class LandPhoneInCityRule_1 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.1;
    }
}
class LandPhoneInlandRule_6 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.6;
    }
}
class LandPhoneInProvinceRule_3 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        long sum = getTime(callRecords);
        return sum*0.3;
    }
}
class Mess extends ChargeMode{
    private double monthlyRent = 0;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1;
        cost1 = getChargeRuless().get(0).calCost(userRecords.getSendMessageRecords());
        return cost1 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class MessageChargeRule extends ChargeRule{
    public double calCost(ArrayList<MessageRecord> messageRecords){
        return 0;
    }
}
class MessageRecord extends CommunicationRecord{
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
class MPhoneCharging extends ChargeMode{
    private double monthlyRent = 15;

    @Override
    public double calCost(UserRecords userRecords){//计算消费
        double cost1,cost2,cost3,cost4,cost5,cost6;
        cost1 = getChargeRules().get(0).calCost(userRecords.getCallingInCityRecords());
        cost2 = getChargeRules().get(3).calCost(userRecords.getCallingInProvinceRecords());
        cost3 = getChargeRules().get(1).calCost(userRecords.getCallingInLandRecords());
        cost4 = getChargeRules().get(1).calCost(userRecords.getCallInP());
        cost5 = getChargeRules().get(2).calCost(userRecords.getCallInL());
        cost6 = getChargeRules().get(1).calCost(userRecords.getAnswerInLandRecords());
        return cost1 + cost2 + cost3+ cost4+ cost5+ cost6 + monthlyRent;
    }

    @Override
    public double getMonthlyRen(){
        return monthlyRent;
    }
}
class SendMessageRule extends MessageChargeRule {
    public double calCost(ArrayList<MessageRecord> messageRecords){
        int num = 0;
        double cost;
        for(MessageRecord a : messageRecords){
            int length = a.getMessage().length();
            int sum = length/10;
            if(length%10!=0){
                sum++;
            }
            num = num+sum;
        }
        if(num<=3){
            cost = num*0.1;
        } else if (num>3&&num<=5) {
            cost = 0.3 + (num - 3) * 0.2;
        }else {
            cost = 0.7 + (num-5) * 0.3;
        }
        return cost;
    }

}
class shoufei_2 extends CallChargeRule{
    @Override
    public double calCost(ArrayList<CallRecord> callRecords){
        Long sum = getTime(callRecords);
        return sum*0.2;
    }
}
class User {
    private UserRecords userRecords = new UserRecords();
    private double balance = 100;
    private ChargeMode chargeMode;
    private String number ;

    public UserRecords getUserRecords() {
        return userRecords;
    }

    public void setUserRecords(UserRecords userRecords) {
        this.userRecords = userRecords;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public ChargeMode getChargeMode() {
        return chargeMode;
    }

    public void setChargeMode(ChargeMode chargeMode) {
        this.chargeMode = chargeMode;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public double calBalance(){

        return 1;
    }

    public double calCost(){

        return 1;
    }
}
class UserRecords {
    private ArrayList<CallRecord> callingInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callingInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> callInP = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> CallInL = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInCityRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInProvinceRecords = new ArrayList<CallRecord>();
    private ArrayList<CallRecord> answerInLandRecords = new ArrayList<CallRecord>();
    private ArrayList<MessageRecord> sendMessageRecords = new ArrayList<MessageRecord>();
    private ArrayList<MessageRecord> receiveMessageRecords = new ArrayList<MessageRecord>();

    public ArrayList<MessageRecord> getSendMessageRecords() {
        return sendMessageRecords;
    }

    public ArrayList<MessageRecord> getReceiveMessageRecords() {
        return receiveMessageRecords;
    }


    public ArrayList<CallRecord> getCallingInCityRecords() {
        return callingInCityRecords;
    }

    public ArrayList<CallRecord> getCallingInProvinceRecords() {
        return callingInProvinceRecords;
    }

    public ArrayList<CallRecord> getCallingInLandRecords() {
        return callingInLandRecords;
    }

    public ArrayList<CallRecord> getCallInP() {
        return callInP;
    }
    public ArrayList<CallRecord> getCallInL() {
        return CallInL;
    }
    public ArrayList<CallRecord> getAnswerInCityRecords() {
        return answerInCityRecords;
    }

    public ArrayList<CallRecord> getAnswerInProvinceRecords() {
        return answerInProvinceRecords;
    }

    public ArrayList<CallRecord> getAnswerInLandRecords() {
        return answerInLandRecords;
    }

    public void addCallingInCityRecords(CallRecord callRecord) {
        callingInCityRecords.add(callRecord);
    }

    public void addCallingInProvinceRecords(CallRecord callRecord) {
        callingInProvinceRecords.add(callRecord);
    }

    public void addCallingInLandRecords(CallRecord callRecord) {
         callingInLandRecords.add(callRecord);
    }
    public void CallInP(CallRecord callRecord) {
        callInP.add(callRecord);
    }
    public void callInL(CallRecord callRecord) {
        CallInL.add(callRecord);
    }

    public void addAnswerInCityRecords(CallRecord callRecord) {
         answerInCityRecords.add(callRecord);
    }

    public void addAnswerInProvinceRecords(CallRecord callRecord) {
         answerInProvinceRecords.add(callRecord);
    }

    public void addAnswerInLandRecords(CallRecord callRecord) {
        answerInLandRecords.add(callRecord);
    }
    public void addSendMessageRecords(CallRecord callRecord) {

    }

    public void addReceiveMessageRecords(CallRecord callRecord) {

    }

    public void addSendMessageRecords(MessageRecord messageRecord) {
        sendMessageRecords.add(messageRecord);
    }

    public void addReceiveMessageRecords(MessageRecord messageRecord) {
        receiveMessageRecords.add(messageRecord);
    }
}

遇到的困难:

再上两道题的基础和经验上,本题非常简单,问题还是数据处理和计费方式,因为每次印东西的加入只有这两部分发生改变。

解决方法:

看到你那个类图都好说!

javafx:

因为这是新接触的东西,所以学学习上遇到些困难,但是都千篇一律,就是对已经处理好的数据在布局上的处理,是界面更加好看和实用,困难就是方法的学习,编写,了解方法,并且知道方法如何使用。

2.在学习中学习到并使用的知识点

(1)继承与多态

继承使你可以定义一个通用的类(父类),之后通过继承得到一个更特殊的类(子类)

什么时候可以继承呢?

一般继承用于两种语境

(1)整体与部分之间的关系(不常用)

例如计算机和cpu的关系,我们一般采用聚集表示

因为继承的耦合性大于聚合的耦合性

(2)大类到小类的关系

例如人类和教师,学生,工人之间的关系

(3)supper:关键字,指代父类,可以调用父类的普通方法和构造方法

复制兼容性原则:可以将子类的对象赋给父类的引用

方法重写:需要在子类中使用和父类重定义的方法的实现

 

多态:意味着父类型的变量可以引用子类型的对象

(2)抽象类和接口

抽象类是专门做父类的,不能创建对象

接口:接口被看作一种特殊的类,与抽象类相似,不能使用new对象

(3)javaFx

总结:

1.bug的主要来源:

自己的疏忽,发生一些细节的小问题,比如字符数字没有加‘  ’,这也是我起初没有注意最困扰我的问题,导致判断不通过

没有认真读题导致题意理解错误或有偏差

2.学习到了什么:

除了类和继承的相关知识点,在其它题目集中学会了使用正则表达式,字符串的分割,在做最近一次的作业中我起初是使用字符串的分割,但是没法实现要求的全部功能,后来学习了正则表达式来解决这个问题,在正则表达式的使用时也会遇到很多问题,需要的形式自己没法正确表达出来,只能通过不断的调试来寻找自己需要的表达式,在课堂上老师也是教会了我很多

3.心得体会:

这是接触java这门语言第三次写博客,这是我第三次写学习总结,总而言之这种总结方法对我来说起到很大的作用,这是我第三次写学习总结,我认为在梳理过后我对知识在脑海里梳理的更加清晰,有助于对这些知识点的再次使用,这也是我第一次编写博客,所以有很多表达不清楚的地方,我因为过于追求pta的分数,所以我很多时间都花在了题目集上,导致自己没有太多时间来编写学习总结和博客,所以我会在下次编写中进行优化,尽可能写出更好的学习总结以及博客,也是很感谢老师在课堂上和课堂下做出的贡献,网课的购买以及对我们免费的开放让我甚是感动。

关于Java,这是我在第一学期学习之后的第一次学习总结,我对java学习还是不够,所以还需要继续在课上课下继续努力,继续在优秀的代码中学习,多看教程,多培养自己的逻辑

4.小建议:

因为只学了一个学期所以我是一个新手,所以还不能给出太多的权威的建议,但是我还是总结出了一些经验,在语法通关的情况下,我们要尽可能去提升自己的逻辑推理能力和数学能力,因为只有这样才能去解决生活中的实际问题,逻辑能力就像基本功,所以我们的数学专业在这个方面就体现了很强的重要性,再有就是培养自己的兴趣,因为我能感觉到我只有在兴趣高涨的时候才能写进去代码,坐得住板凳才能写得出好代码,多去实践,很多人为了快速学会java而不去时间,不要把所有时间都放在学上,快餐式学习不可取,更多的是去自己编写代码,从而学好java

 

posted @ 2022-06-16 14:54  珈圻  阅读(38)  评论(0)    收藏  举报