From e1d78cab93d939357dfa41ffff853c3c638f012c Mon Sep 17 00:00:00 2001 From: speacil111 Date: Tue, 25 Jul 2023 16:39:50 +0800 Subject: [PATCH 1/2] first commit --- hw1/hw1/Program.cs | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/hw1/hw1/Program.cs b/hw1/hw1/Program.cs index e4f0e15..5309f38 100644 --- a/hw1/hw1/Program.cs +++ b/hw1/hw1/Program.cs @@ -57,6 +57,78 @@ public interface IProgress public class Progress : IProgress { + + public int num; + public int requiredprogress; + public int finishedprogress; + public int Num { get { return num; } } + public int RequiredProgress { get { return requiredprogress; } } + public int FinishedProgress { get { return finishedprogress; } } + + public bool Start(int requiredprogress) + { + finishedprogress = 0; + this.requiredprogress = requiredprogress; + if(requiredprogress < 0) + { + throw new ArgumentOutOfRangeException(nameof(Homework1.Progress), "RequiredProgress must be positive."); + } + if(requiredprogress==finishedprogress) + { + return true; + } + if(finishedprogress= requiredprogress) + { + + finishedprogress = requiredprogress; + } + else + { + finishedprogress+=addprogress; + } + } + } + public void Sub(int subprogress) + { + if (subprogress < 0) + Console.WriteLine("请输入正数!"); + else + { + if (finishedprogress - subprogress <=0) + { + finishedprogress = 0; + } + else + { + finishedprogress -= subprogress; + } + } + } + public void Double() + { + finishedprogress = finishedprogress * 2; + if(finishedprogress > requiredprogress) + { + finishedprogress = requiredprogress; + + } + } + public (int FinishedProgress, int RequiredProgress) GetProgress() + { + return (FinishedProgress, RequiredProgress); + } // 一个进度条 // 只允许修改Progress类中的代码 // 要求实现IProgress中的要求 From 8cf2521e869eaa6dffe5162b1901d1695943d9aa Mon Sep 17 00:00:00 2001 From: speacil111 Date: Tue, 25 Jul 2023 17:12:03 +0800 Subject: [PATCH 2/2] final commit --- hw1/hw1/Program.cs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hw1/hw1/Program.cs b/hw1/hw1/Program.cs index 5309f38..6601ddb 100644 --- a/hw1/hw1/Program.cs +++ b/hw1/hw1/Program.cs @@ -58,7 +58,7 @@ public interface IProgress public class Progress : IProgress { - public int num; + public static int num=0; public int requiredprogress; public int finishedprogress; public int Num { get { return num; } } @@ -67,22 +67,16 @@ public class Progress : IProgress public bool Start(int requiredprogress) { - finishedprogress = 0; - this.requiredprogress = requiredprogress; - if(requiredprogress < 0) - { - throw new ArgumentOutOfRangeException(nameof(Homework1.Progress), "RequiredProgress must be positive."); - } - if(requiredprogress==finishedprogress) + if (FinishedProgress >= RequiredProgress) { + if (requiredprogress <= 0) + throw new System.Exception("RequiredProgress must be positive. (Parameter 'Homework1.Progress')"); + this.requiredprogress = requiredprogress; + finishedprogress = 0; + num++; return true; } - if(finishedprogress= requiredprogress) { - + num++; finishedprogress = requiredprogress; } else @@ -106,7 +100,7 @@ public void Sub(int subprogress) Console.WriteLine("请输入正数!"); else { - if (finishedprogress - subprogress <=0) + if (finishedprogress <= subprogress ) { finishedprogress = 0; }