From f87034e75a0846e75c315a71404f46ec3340d688 Mon Sep 17 00:00:00 2001 From: youyc22 <125688164+youyc22@users.noreply.github.com> Date: Fri, 14 Jul 2023 17:02:10 +0800 Subject: [PATCH] Update Program.cs --- hw1/hw1/Program.cs | 72 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/hw1/hw1/Program.cs b/hw1/hw1/Program.cs index e4f0e15..e446a2f 100644 --- a/hw1/hw1/Program.cs +++ b/hw1/hw1/Program.cs @@ -55,11 +55,73 @@ public interface IProgress public (int FinishedProgress, int RequiredProgress) GetProgress(); } - public class Progress : IProgress + public class Progress : IProgress { - // 一个进度条 - // 只允许修改Progress类中的代码 - // 要求实现IProgress中的要求 + private int num; + private int requiredProgress; + private int finishedProgress; + + public Progress() + { + num = 0; + requiredProgress = 0; + finishedProgress = 0; + } + + public int Num => num; + public int RequiredProgress => requiredProgress; + public int FinishedProgress => finishedProgress; + + public bool Start(int RequiredProgress) + { + if (finishedProgress >= requiredProgress) + { + if (RequiredProgress < 0) + { + throw new ArgumentException("RequiredProgress must be positive.", nameof(Progress)); + } + this.requiredProgress = RequiredProgress; + finishedProgress = 0; + } + else + { + return false; + } + num++; + return true; + } + + public void Add(int addProgress) + { + finishedProgress += addProgress; + if (finishedProgress > requiredProgress) + { + finishedProgress = requiredProgress; + } + } + + public void Sub(int subProgress) + { + finishedProgress -= subProgress; + if (finishedProgress < 0) + { + finishedProgress = 0; + } + } + + public void Double() + { + finishedProgress *= 2; + if(finishedProgress > requiredProgress) + { + finishedProgress = requiredProgress; + } + } + + public (int FinishedProgress, int RequiredProgress) GetProgress() + { + return (finishedProgress, requiredProgress); + } } /* @@ -89,4 +151,4 @@ RequiredProgress must be positive. (Parameter 'Homework1.Progress') (18, 18) (19, 20) */ -} \ No newline at end of file +}