OPP最後兩次作業總結
前言
兩次題目集其實都是在前面的基礎上進行迭代,第一次作業說實話我沒花什麼時間,畢竟我從寫第一次PTA就是給電器使用兩個接點,我從拿到題目到達到及格分只用了半天時間,然後最後又花了點時間測試幾個樣例,拿到了82分。然後最後一次作業嘛,我幾乎是直接開擺了,總共有四個樣例,我只過了三個就沒管了,然後就直接交了,勉強拿到了25分,但是最後一看排名,沒想到居然是99名,也是有點出乎我的意料。這大概就是我這兩次作業是怎麼完成的了。
設計與分析
兩次作業都沒怎麼做設計方面的事情,就是把需求直接加到程式碼裡面,然後遇到問題就除錯幾下,最後除錯到樣例都過了就自己在那邊寫幾個樣例進行自測,最後寫的差不多了就交PTA上,沒設計這回事。
踩坑心得
在寫最後這次作業的時候我倒是踩了一些坑,首先就是我的線路連線方面的問題,我的線路連線函式設計比較混亂,導致從一個線路連線到另外一個線路比較難,其實大體的結構沒什麼問題,但是到後面出現一些新的需求的時候我就要反覆修改程式碼了,估計這是剛開始寫程式碼的時候幾乎從來沒有好好想過怎麼連線,就是直接上手開練的結果,導致最後就是反覆修改,改的自己都不知道怎麼執行的邏輯,然後在混亂的體系中嘗試理解,利用反覆的除錯來解決錯誤,最後雖然也能獲得一個正確的結構,但是說實話挺像在混日子的,
我的線路程式碼定義在四個類中,這是類設計的核心部分
Line(抽象電路類)
class Line {
public double resistance = 0;
public double inputVoltage = 0;
public double inVoltage = 0;
public double outVoltage = 0;
public double electricity = 0;
// public TreeMap <String, ArrayList
//public TreeMap <String, Double> PointVoltage = new TreeMap<>();
}
Circuit(串聯電路類)
class Circuits extends Line{
public String tick;
public Boolean mainState = false;
public ArrayList
public double electricity = 0;
public boolean judgeShortCircle(){
boolean state = false;
if(this.resistance == 0){
state = true;
}
return state;
}
}
ParallelConnection(並聯電路類)
class ParallelConnection extends Line{
public double resistance = -1;
public String tick;
public ArrayList
}
ConnectionManager(計算線路屬性的函式)
class ConnectionManager {
public static double getComponentResistance(Component component, Map<Component, Device> devices, TreeMap<String, Circuits> circuits, TreeMap<String, ParallelConnection> parallelConnections) {
double resistance = 0;
if (component.type.equals("T")) {
resistance = circuits.get(component.tick).resistance;
} else if (component.type.equals("M")) {
resistance = parallelConnections.get(component.tick).resistance;
} else {
resistance = devices.get(component).getResistance();
}
return resistance;
}
public static void chargeOpenParallelConnection(Map<Component, Device> devices, ParallelConnection parallelConnection, TreeMap<String, ParallelConnection> parallelConnections, TreeMap<String, Circuits> circuits) {
for (Circuits c : parallelConnection.parallelConnection) {
// if(parallelConnection.inputVoltage == -1){
// parallelConnection.inputVoltage = 0;
// }
if (c.resistance == -1) {
c.inVoltage = parallelConnection.inVoltage;
chargeOpenCircuits(devices, c, parallelConnections, circuits);
} else {
c.inVoltage = parallelConnection.inVoltage;
c.inputVoltage = parallelConnection.inputVoltage;
chargeCircuits(devices, c, parallelConnections, circuits);
}
}
}
public static void chargeOpenCircuits(Map<Component, Device> devices, Circuits circuit, TreeMap<String, ParallelConnection> parallelConnections, TreeMap<String, Circuits> circuits) {
double voltage = circuit.inVoltage;
for (Component c : circuit.circuits) {
if (c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
parallelConnections.get(c.tick).inVoltage = voltage;
chargeOpenParallelConnection(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
} else {
parallelConnections.get(c.tick).inVoltage = voltage;
parallelConnections.get(c.tick).outVoltage = voltage;
chargeOpenParallelConnection(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
}
} else if (c.type.equals("T")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
circuits.get(c.tick).inVoltage = voltage;
chargeOpenCircuits(devices, circuits.get(c.tick), parallelConnections, circuits);
} else {
circuits.get(c.tick).inVoltage = voltage;
circuits.get(c.tick).outVoltage = voltage;
chargeOpenCircuits(devices, circuits.get(c.tick), parallelConnections, circuits);
}
} else if (devices.get(c).ChargeCircuitsState) {
continue;
} else if (c.type.equals("F") || c.type.equals("L")) {
devices.get(c).setInputVoltage(circuit.inputVoltage);
circuit.inputVoltage = devices.get(c).getOutputVoltage();
devices.get(c).setOutVoltage(voltage);
}
if (!c.type.equals("T") && !c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
devices.get(c).setInVoltage(voltage);
devices.get(c).setChargeCircuitsState(true);
break;
} else {
devices.get(c).setInVoltage(voltage);
devices.get(c).setOutVoltage(voltage);
devices.get(c).setChargeCircuitsState(true);
}
}//這裡重複了兩次
}
}
public static void chargeCircuits(Map<Component, Device> devices, Circuits circuit, TreeMap<String, ParallelConnection> parallelConnections, TreeMap<String, Circuits> circuits) {
double voltage = circuit.inVoltage;
for (Component c : circuit.circuits) {
if (c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
parallelConnections.get(c.tick).inVoltage = voltage;
parallelConnections.get(c.tick).inputVoltage = 0;
chargeOpenParallelConnection(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
} else {
parallelConnections.get(c.tick).inVoltage = voltage;
parallelConnections.get(c.tick).inputVoltage = circuit.inputVoltage * (parallelConnections.get(c.tick).resistance / circuit.resistance);
voltage -= parallelConnections.get(c.tick).inputVoltage;
parallelConnections.get(c.tick).outVoltage = voltage;
chargeParallelConnection(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
}
} else if (c.type.equals("T")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
circuits.get(c.tick).inVoltage = voltage;
circuits.get(c.tick).inputVoltage = 0;
chargeOpenCircuits(devices, circuits.get(c.tick), parallelConnections, circuits);
} else {
circuits.get(c.tick).inVoltage = voltage;
circuits.get(c.tick).inputVoltage = circuit.inputVoltage * (circuits.get(c.tick).resistance / circuit.resistance);
voltage -= circuits.get(c.tick).inputVoltage;
circuits.get(c.tick).outVoltage = voltage;
chargeCircuits(devices, circuits.get(c.tick), parallelConnections, circuits);
}
} else if (devices.get(c).ChargeCircuitsState) {
continue;
} else if (c.type.equals("F") || c.type.equals("L")) {
devices.get(c).setInputVoltage(circuit.inputVoltage);
circuit.inputVoltage = devices.get(c).getOutputVoltage();
devices.get(c).setOutVoltage(voltage);
} else {
if(Math.abs(circuit.resistance + 1.0) < 0.0001){
devices.get(c).setInputVoltage(0);
}
else {
devices.get(c).setInputVoltage(circuit.inputVoltage * (devices.get(c).getResistance() / circuit.resistance));//注意這裡每個電路迴圈了兩遍
}
}
if (!c.type.equals("T") && !c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
devices.get(c).setInVoltage(voltage);
devices.get(c).setChargeCircuitsState(true);
break;
} else {
devices.get(c).setInVoltage(voltage);
voltage -= devices.get(c).inputVoltage;
devices.get(c).setOutVoltage(voltage);
devices.get(c).setChargeCircuitsState(true);
}
}//這裡重複了兩次
}
circuit.outVoltage = voltage;
}//為串聯電路充能
public static void chargeParallelConnection(Map<Component, Device> devices, ParallelConnection parallelConnection, TreeMap<String, ParallelConnection> parallelConnections, TreeMap<String, Circuits> circuits) {
for (Circuits c : parallelConnection.parallelConnection) {
// if(c.resistance != -1) {
// if (parallelConnection.inputVoltage == -1) {
// parallelConnection.inputVoltage = 0;
// }//不知道有什麼用
c.inVoltage = parallelConnection.inVoltage;
if(c.resistance != -1) {
c.inputVoltage = parallelConnection.inputVoltage;
}
chargeCircuits(devices, c, parallelConnections, circuits);
// }
}
}//為並聯電路充能
public static void GenerateCurcuitsEletricity(Map<Component, Device> devices, Circuits circuit, TreeMap<String, ParallelConnection> parallelConnections, TreeMap<String, Circuits> circuits) {
double eletricity = circuit.inputVoltage / circuit.resistance;
for (Component c : circuit.circuits) {
if (c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
parallelConnections.get(c.tick).electricity = -1;
GenerateParallelEletricity(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
} else {
GenerateParallelEletricity(devices, parallelConnections.get(c.tick), parallelConnections, circuits);
}
} else if (c.type.equals("T")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
circuits.get(c.tick).electricity = -1;
GenerateCurcuitsEletricity(devices, circuits.get(c.tick), parallelConnections, circuits);
} else {
GenerateCurcuitsEletricity(devices, circuits.get(c.tick), parallelConnections, circuits);
}
} else if (devices.get(c).isGenerateState()) {
continue;
} else {
devices.get(c).setInputVoltage(circuit.inputVoltage * (devices.get(c).getResistance() / circuit.resistance));//注意這裡每個電路迴圈了兩遍
}
if (!c.type.equals("T") && !c.type.equals("M")) {
if (getComponentResistance(c, devices, circuits, parallelConnections) == -1) {
devices.get(c).setGenerateState(true);
break;
} else {
devices.get(c).setEletricity(eletricity);
devices.get(c).setGenerateState(true);
}
}//這裡重複了兩次
}
}
public static void GenerateParallelEletricity(Map<Component, Device> devices,ParallelConnection parallelConnection,TreeMap<String, ParallelConnection> parallelConnections,TreeMap<String, Circuits> circuits){
for (Circuits c : parallelConnection.parallelConnection) {
// if (parallelConnection.electricity == -1) {
// parallelConnection.electricity = 0;
// }//不知道有什麼用
if(c.inputVoltage == -1) {
continue;
}
else if(c.inputVoltage == 0){
parallelConnection.electricity = 0;
break;
}
c.electricity = c.inputVoltage / c.resistance;
GenerateCurcuitsEletricity(devices, c, parallelConnections, circuits);
}
}
}
(在此附上類圖)
對本學期本門課程的改進建議及意見
我感覺今年的課程有點虎頭鼠尾了,剛開始上的各種物件導向原則都是必要的東西,但是到後面講的那些原則多數不能直接瞭解真正的用法,不使用也沒有太大關係,說實話,我這學期寫的程式碼確實多數是垃圾程式碼,老師並沒有真正教會我太多,倒是給了我幾個教訓,
1.那就是多數知識都是從小圈子裡面學習出來的,周圍人什麼樣自己常常就會什麼樣,就像PTA裡排名靠前的總是那一堆人,我嘛其實也不怎麼樣,雖然我給自己的要求比較低,每次PTA及格就行,但是就是發現就算這樣我也超過一半人了,也是很奇怪,我總覺得自己是比較開擺的人,這學期線代都沒考及格,但是這門課程確超過一半的人了,大概是我宿舍的其他三個人大部分PTA都是滿分把我逼上去的吧,。
2.原來學習成果確實不是和學習時間成正比,只是要養成一個習慣,每天學多久,玩多久,而且要以一種溝通的心態找到和自己一起學的人,這才算是有效的學習,自己一個人在圖書館學是造不出任何東西的,溝通始終是必要的,我的線代就是這麼掛的。
3.每次上完課記得回課,這樣才是有效率的學習,這學期我自己找了一個音樂學院的研究生教我美聲,我發現這才是主動學習,從小學到現在我所接受的教育都是被逼著去學的,我也是才明白有一門愛好的重要性,還有打遊戲確實有點浪費時間,畢竟現在的遊戲套路就那麼幾種,不同型別和風格的遊戲水平總是迭代上升的,那麼每隔兩個月玩七天貌似是更加合理的選擇。
4.然後就是刷影片的問題,現在的自媒體也總是在批評一些有的沒的東西,不管怎麼說都是套路化的,每個自媒體博主都像是一個小吃店,跟你講一些能夠讓你高興但卻是套路化的東西,看了多久都學不會做早餐,最多也只是供我們評價一下早餐的形狀和樣式,並不能教我多少東西,所以,除了聊天還是少刷影片吧
)前言:總結兩次題目集的題目的知識點、題量、難度等情況
(2)設計與分析:重點對題目的提交原始碼進行分析,可參考SourceMontor的生成報表內容以及PowerDesigner的相應類圖,要有相應的解釋和心得(做到有圖有真相),本次Blog必須分析題目集1~3的最後一題
(3)採坑心得:對原始碼的提交過程中出現的問題及心得進行總結,務必做到詳實,拿資料、原始碼及測試結果說話,切忌假大空
(4)改進建議:對相應題目的編碼改進給出自己的見解,做到可持續改進
(5)總結:對本階段兩次題目集的綜合性總結,學到了什麼,哪些地方需要進一步學習及研究
(6)最後一段,給出對本學期本門課程的改進建議及意見(難度大就不要提了)。