2条回答 默认 最新
- CSDN专家-showbo 2021-06-18 07:30关注
帮助到你可以点个采纳吗,谢谢~~
using System; namespace ConsoleApp1 { class Customer { private string cNo { get; set; } private string cName { get; set; } private int cPoints { get; set; } private string cTelephone { get; set; } public string CNo { get { return cNo; } } public string CName { get { return cName; } } public int CPoints { get { return cPoints; }set{ cPoints = value; } } public string CTelephone { get { return cTelephone; }set { cTelephone = value; } } public Customer() { } public void Input() { Console.Write("请输入客户编号:"); cNo = Console.ReadLine(); Console.Write("请输入客户姓名:"); cName = Console.ReadLine(); Console.Write("请输入客户电话:"); cTelephone = Console.ReadLine(); while (true) { Console.Write("请选择你的操作,1-增加积分;2-兑换积分,其他则退出--"); string op = Console.ReadLine(); if (op == "1" || op == "2") { Console.Write("请输入要" + (op == "1" ? "增加" : "兑换") + "的积分:"); string sScore = Console.ReadLine(); int score = 0; if (int.TryParse(sScore, out score)) { if (op == "1") { Buy(score); Console.WriteLine("已存入{0}积分", score); Show(); } else { Exchange(score); Console.WriteLine("本次兑换{0}积分", score); Show(); } } else Console.WriteLine("积分需要为数字,请重新选择操作!"); } else { Console.WriteLine("系统选择错误,退出!"); break; } } } private void Show() { Console.WriteLine("客户编号:" + cNo + ",客户姓名:" + cName + ",客户联系电话:" + cTelephone + ",客户积分:" + cPoints); } public void Buy(int x) { this.cPoints += x; } public void Exchange(int c) { if (c > cPoints) Console.WriteLine("积分不足!"); else this.cPoints -= c; } } class Program { static void Main(string[] args) { var kate = new Customer(); kate.Input(); Console.WriteLine("请安任意键继续!"); Console.ReadKey(); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报