有10位评委对跳水运动员做评分,编写C#程序,计算去除最大得分和最小得分之后的平均得分 作为运动员的跳水成绩。
interface IMark
using System.Collections.Generic;namespace ConsoleApp1{ ////// 评分接口 /// interface IMark { Mark GetMaxScore(List list_Marks); Mark GetMinScore(List list_Marks); ////// 获取所有评分 /// ///List GetAllMarks(int athleteId); /// /// 获取除最大得分和最小得分之后的平均得分 /// ///float GetAvgScoreExceptFirstAndLast(); }}
class Mark
namespace ConsoleApp1{ ////// 评分实体 /// public class Mark { public int Id; public int JuryId; public int AthleteId; public float Score; }}
class MarkService
using System.Collections.Generic;using System.Linq;namespace ConsoleApp1{ ////// 实现评分接口 /// public class MarkService : IMark { public MarkService() { } ////// 获取所有评分 /// /// ///public List GetAllMarks(int athleteId) { List list = new List(); for (int i = 1; i < 11; i++) { list.Add(new Mark() { Id = i, JuryId = i, AthleteId = 1, Score = i, }); } return list.Where(x=>x.AthleteId ==athleteId).ToList(); } /// /// 获取除最小分数、最大分数之外的平均得分 /// ///public float GetAvgScoreExceptFirstAndLast() { List List_Marks = this.GetAllMarks(1); return List_Marks.Where( x => x.Id != this.GetMaxScore(List_Marks).Id && x.Id != this.GetMinScore(List_Marks).Id).Average(y=>y.Score); } /// /// 获取最大得分 /// /// ///public Mark GetMaxScore(List list_Marks) { float maxScore = list_Marks.Max(x => x.Score); return list_Marks.Where(x => x.Score == maxScore).FirstOrDefault(); } /// /// 获取最小得分 /// /// ///public Mark GetMinScore(List list_Marks) { float minScore = list_Marks.Min(x => x.Score); return list_Marks.Where(x => x.Score == minScore).FirstOrDefault(); } }}
class Program
using System;using System.Text; namespace ConsoleApp1{ class Program { static void Main(string[] args) { IMark t = new Test(); Console.WriteLine(t.GetAvgScoreExceptFirstAndLast()); Console.Read(); } }}