From 269ba344a342bbc6967e77fb7addd0b3f5d2fc5d Mon Sep 17 00:00:00 2001 From: Polyhymnia <2281017491@qq.com> Date: Wed, 2 Jun 2021 21:59:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E5=AE=8B=E5=98=89?= =?UTF-8?q?=E7=82=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\256\213\345\230\211\347\202\234/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/.keep" diff --git "a/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/.keep" "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 0906feb276b52722fe58bdd71b545aab42f3f601 Mon Sep 17 00:00:00 2001 From: Polyhymnia <2281017491@qq.com> Date: Wed, 2 Jun 2021 22:00:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\274\202\345\270\270\345\244\204\347\220\206/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/.keep" diff --git "a/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/.keep" "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From a7d987bba0f85d142f8047ed4e24eec375edbaee Mon Sep 17 00:00:00 2001 From: Polyhymnia <2281017491@qq.com> Date: Wed, 2 Jun 2021 22:01:07 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=AE=8B=E5=98=89=E7=82=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Program.cs" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/Program.cs" diff --git "a/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/Program.cs" "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/Program.cs" new file mode 100644 index 0000000..fface76 --- /dev/null +++ "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\274\202\345\270\270\345\244\204\347\220\206/Program.cs" @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; + +namespace try的练习 +{ + class Program + { + static void Main(string[] args) + { + //一个考试管理系统,需要录入考生成绩,只能录入数字,否则会报类型转换异常。 + //请编写相关代码, + //1、捕获FormatException异常,并打印输出“异常已处理; + //2、捕获OverflowException异常,数值超出double范围的异常,并打印输出“异常已处理; + //3、捕获一般异常Exception异常。 + //4、最终处理finally + //录入成绩结束后,请输出,总学生数,总分数,平均分。 + List score = new List(); + int sum = 0; + while (true) + { + Console.WriteLine("请输入学生成绩"); + try + { + double inputScore = double.Parse(Console.ReadLine()); + + if (!(inputScore>0 && inputScore<=150)) + { + throw new OverflowException(); + } + else + { + score.Add(inputScore); + Console.WriteLine("添加成功"); + } + } + catch (FormatException fe) + { + Console.WriteLine("异常已处理"); + Console.WriteLine(fe.Message); + Console.WriteLine(fe.Data); + Console.WriteLine(fe.Source); + continue; + } + + catch (Exception e) + { + Console.WriteLine("异常已处理"); + Console.WriteLine(e.Message); + Console.WriteLine(e.Data); + Console.WriteLine(e.Source); + continue; + + } + finally + { + Console.WriteLine("该学生成绩添加完成"); + + } + Console.WriteLine("请问是否还要添加成绩 Y/N"); + String yesOrNo = Console.ReadLine(); + if (yesOrNo.Equals("y", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + else + { + Console.WriteLine("退出"); + break; + } + } + + foreach (int multScore in score) + { + sum += multScore; + } + int count=1; + foreach (int item in score) + { + Console.WriteLine("第{1}位学生成绩{0}",item,count); + count++; + } + double avg = sum / score.Count; + Console.WriteLine("总学生数{0}",score.Count); + Console.WriteLine("总分数{0}",sum); + Console.WriteLine("平均分{0}",avg); + + Console.ReadKey(); + + } + } + +} -- Gitee From 069d8320ac2a9f23364c4c1003c65ad2df32c5c1 Mon Sep 17 00:00:00 2001 From: Polyhymnia <2281017491@qq.com> Date: Wed, 2 Jun 2021 22:01:24 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E5=AD=98=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\255\230\345\217\226/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/.keep" diff --git "a/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/.keep" "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 0749eec83b003ee9af17b05680987af9a84bf5c0 Mon Sep 17 00:00:00 2001 From: Polyhymnia <2281017491@qq.com> Date: Wed, 2 Jun 2021 22:01:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=AE=8B=E5=98=89=E7=82=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\255\230\345\217\226/Program.cs" | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 "\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/Program.cs" diff --git "a/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/Program.cs" "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/Program.cs" new file mode 100644 index 0000000..84b8f86 --- /dev/null +++ "b/\347\254\2546\346\254\241\344\275\234\344\270\232/\345\256\213\345\230\211\347\202\234/\345\255\230\345\217\226/Program.cs" @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 存钱取钱 +{ + class Program + { + + static void Main(string[] args) + { + + Count user1 = new Count("老赵", 2000); + /*编写一个程序,用以接收用户输入的两个浮点型的数值,一个值表示用户想要存放在银行账户中的余额, + 另一个值表示用户想要从银行账户中提取的金额。 + 实现存取款功能, + 用户功能选择:1、存款,2、取款 + 取款时: + 当用户想要提取的金额大于余额时,请手动抛出一个ArgumentOutOfRangeException + 参数超出范围的异常,异常信息可以写“取款金额大于余额,请重新输入” + ,如此以确保取款金额始终不大于当前余额。 + 操作结束,打印输出余额是多少。 + 最后再添加catch一般异常 Exception,使得数据类型转换的异常也能被捕获到。*/ + + while (true) + { + Console.WriteLine("1.存钱\t2.取钱\t其他键直接退出"); + string choose = Console.ReadLine(); + switch (choose) + { + case "1": + SaveMoney(user1); + + continue; + case "2": + Withdrawal(user1); + + break; + + default: + + break; + + } + Console.WriteLine("继续操作请按 “1”\t退出请按其他任意键 "); + string continueOrEnd = Console.ReadLine(); + if (continueOrEnd.Equals("1")) + { + Console.WriteLine("继续操作。。。。。"); + continue; + } + else + { + Console.WriteLine("退出程序,感谢使用,那好小票"); + break; + } + + + } + Console.WriteLine("正在打印小票,请稍等。。。。"); + Console.WriteLine(user1); + + + Console.ReadKey(); + + } + /// + /// 存钱 + /// + /// + static void SaveMoney(Count user1) + { + Console.WriteLine("情报钞票整理好放入ATM"); + decimal saveMoney = decimal.Parse(Console.ReadLine()); + user1.AllAmount += saveMoney; + Console.WriteLine("存款成功,现余额为{0}", user1.AllAmount); + } + + + /// + /// 取钱 + /// + /// + static void Withdrawal(Count user) + { + + while (true) + { + Console.WriteLine("请输入您要取款的金额"); + try + { + decimal withdrawal = decimal.Parse(Console.ReadLine()); + if (withdrawal >= user.AllAmount) + { + throw new ArgumentException(); + } + else + { + Console.WriteLine("取款成功"); + user.AllAmount -= withdrawal; + break; + } + } + catch (Exception) + { + Console.WriteLine("取款金额大于余额,请重新输入"); + continue; + } + + } + Console.WriteLine("操作完成,请问你是否还要继续操作吗?"); + } + } + class Count + { + private string _userName; + private decimal _allAmount; + + public Count(string userName, decimal allAmount) + { + AllAmount = allAmount; + UserName = userName; + } + + public decimal AllAmount { get => _allAmount; set => _allAmount = value; } + public string UserName { get => _userName; set => _userName = value; } + public override string ToString() + { + return $"用户名{UserName},户头存款{AllAmount}"; + } + } +} -- Gitee