gpt4 book ai didi

java - 代码重构作业?

转载 作者:搜寻专家 更新时间:2023-10-30 21:36:36 26 4
gpt4 key购买 nike

这是我必须为作业重构的代码:

if (state == TEXAS) {
rate = TX_RATE;
amt = base * TX_RATE;
calc = 2 * basis(amt) + extra(amt) * 1.05;
} else if ((state == OHIO) || (state == MAINE)) {
rate = (state == OHIO) ? OH_RATE : MN_RATE;
amt = base * rate;
calc = 2 * basis(amt) + extra(amt) * 1.05;
if (state == OHIO)
points = 2;
} else {
rate = 1;
amt = base;
calc = 2 * basis(amt) + extra(amt) * 1.05;
}

我做过这样的事

if (state == TEXAS) {
rate = TX_RATE;
calculation(rate);
}
else if ((state == OHIO) || (state == MAINE))
{
rate = (state == OHIO) ? OH_RATE : MN_RATE;

calculation(rate);

if (state == OHIO)
points = 2;
}

else {
rate = 1;
calculation(rate);
}

function calculation(rate)
{
amt = base * rate;
calc = 2 * basis(amt) + extra(amt) * 1.05;
}

我怎样才能做得更好?
编辑 我已完成代码编辑amt = base * rate;

最佳答案

class State {
private :
double taxRate;
int baseWeight;
int extraWeight;
string name;
base;
public:
State(string name, double taxRate = 1, int point =0, double baseWeight=2, double extraWeight=1.05); //implement the method yourself
double extra(double base);
double basis(double base);
double calculate(double base){
return baseWeight * basis(base) + baseWeight * extra(base);
}
int point(){return point};

};

现在如何使用它:

State ohio ("OHIO", OH_RATE, 2);
cout << "OHIO result:" ohio.calculate() << " point:" << ohio.point() << endl;

关于java - 代码重构作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8193026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com