I am currently trying to figure out where I went wrong in this logic of code for the assignment. Any remarks or advice would be appreciated!
The output I keep getting no matter what input I put in keeps giving me:
average temperature 0,
highest temperature 5,
lowest temperature 0,
average excluding lowest 0,
number of cold days 10
First Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TemperatureAverager
{
class Temperatures
{
public double[] weeksTemperatures;
public double threshTemp;
public double average;
public double averageExcludingLowest;
public double highest;
public double lowest;
public int numOfThreshs;
public double[] WeeksTemperatures
{
get
{
return weeksTemperatures;
}
}
public double ThreshTemp
{
get
{
return threshTemp;
}
}
public double Average
{
set
{
average = value;
}
get
{
return average;
}
}
public double AverageExcludingLowest
{
set
{
averageExcludingLowest = value;
}
get
{
return averageExcludingLowest;
}
}
public double Highest
{
set
{
highest = value;
}
get
{
return highest;
}
}
public double Lowest
{
set
{
lowest = value;
}
get
{
return lowest;
}
}
public int NumberOfThreshs
{
set
{
numOfThreshs = value;
}
get
{
return numOfThreshs;
}
}
public Temperatures()
{
}
public Temperatures(double[] wTemperatures, double threshT)
{
weeksTemperatures = wTemperatures;
threshTemp = threshT;
}
public double DetermineAverage()
{
double average = 0;
for (int x = 0; x < 7; x++)
{
average = average + weeksTemperatures[x];
}
average = average / 7;
return average;
}
public double DetermineAverageExcludingLowest()
{
for (int x = 0; x < 7; x++)
{
averageExcludingLowest = averageExcludingLowest + weeksTemperatures[x];
if (weeksTemperatures[x] < lowest)
{
lowest = weeksTemperatures[x];
}
}
averageExcludingLowest = ((averageExcludingLowest - lowest) / 7); // calculate average excluding lowest temperature
return averageExcludingLowest;
}
public double DetermineLowest()
{
for (int x = 0; x < 7; x++) //Traverse through the week's temperatures
{
if (weeksTemperatures[x] < lowest) //find the lowest temperature of the week
{
lowest = weeksTemperatures[x]; //and set it to lowest
}
}
return lowest;
}
public double DetermineHighest()
{
for (int x = 0; x < 7; x++) //Traverse through the week's temperatures
{
if (weeksTemperatures[x] > highest) //find the highest temperature of the week
{
highest = weeksTemperatures[x]; //and set it to highest
}
}
return highest;
}
public double DetermineNumberOfThreshs()
{
for (int x = 0; x < 7; x++) //Traverse through the week's temperatures
{
if (weeksTemperatures[x] < threshTemp) //find the lowest temperature of the week
{
numOfThreshs++;
}
}
return numOfThreshs;
}
public override string ToString()
{
return "=====================\nWeekly Statistics\n" + "---------------------\n" + "Average Temperature: " + average + "\nHighest Temperature: "
+ highest + "\nLowest Temperature: " + lowest + "\nAvg. Excl. Lowest: " + averageExcludingLowest + "\n# of Cold Days: " + numOfThreshs + "\n====================="; //Formats and the invoice to be printed
}
}
}
Second Class
namespace TemperatureAverager
{
class TemperatureApp
{
static void Main(string[] args)
{
double[] week = new double[7];
string[] days = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //array to track days of week
for (int x = 0; x < 7; x++)
{
Console.Write("What was the temperature on " + days[x] + "?: ");
string userTemperatureInput = Console.ReadLine();
week[x] = double.Parse(userTemperatureInput);
}
Console.Write("How cold is too cold?: ");
string userThreshInput = Console.ReadLine();
double thresh = double.Parse(userThreshInput);
Temperatures weekOne = new Temperatures(week, thresh);
Console.WriteLine(weekOne.ToString());
Console.ReadLine();
}
}
}
Class one
public class Temperatures
{
private double sum;
private int daysInWeek;
public double[] WeeksTemperatures { get; set; }
public double ThreshTemp { get; set; }
public double Average { get; set; }
public double AverageExcludingLowest { get; set; }
public double Highest { get; set; }
public double Lowest { get; set; }
public int NumOfThreshs { get; set; }
public Temperatures(double[] wTemperatures, double threshT)
{
this.WeeksTemperatures = wTemperatures;
this.ThreshTemp = threshT;
sum = 0.0;
daysInWeek = 7;
}
public void GetWeekStatistics()
{
GetSum();
DetermineLowest();
DetermineHighest();
DetermineAverage();
DetermineAverageExcludingLowest();
DetermineNumberOfThreshs();
}
private void GetSum()
{
for (int x = 0; x < daysInWeek; x++) //Traverse through the week's temperatures
{
this.sum = this.sum + this.WeeksTemperatures[x];
}
}
public void DetermineLowest()
{
this.Lowest = this.WeeksTemperatures[0];
for (int x = 0; x < daysInWeek; x++) //Traverse through the week's temperatures
{
if (this.WeeksTemperatures[x] < this.Lowest) //find the lowest temperature of the week
{
this.Lowest = this.WeeksTemperatures[x]; //and set it to lowest
}
}
}
public void DetermineHighest()
{
this.Highest = this.WeeksTemperatures[0];
for (int x = 0; x < daysInWeek; x++) //Traverse through the week's temperatures
{
if (this.WeeksTemperatures[x] > this.Highest) //find the highest temperature of the week
{
this.Highest = this.WeeksTemperatures[x]; //and set it to highest
}
}
}
private void DetermineAverage()
{
this.Average = this.sum / daysInWeek;
}
public void DetermineAverageExcludingLowest()
{
this.AverageExcludingLowest = ((this.sum - this.Lowest) / daysInWeek); // calculate average excluding lowest temperature
}
public void DetermineNumberOfThreshs()
{
for (int x = 0; x < daysInWeek; x++) //Traverse through the week's temperatures
{
if (this.WeeksTemperatures[x] < this.ThreshTemp) //find the lowest temperature of the week
{
this.NumOfThreshs++;
}
}
}
public override string ToString()
{
return "=====================\nWeekly Statistics\n" + "---------------------\n" + "Average Temperature: " + this.Average + "\nHighest Temperature: "
+ this.Highest + "\nLowest Temperature: " + this.Lowest + "\nAvg. Excl. Lowest: " + this.AverageExcludingLowest + "\n# of Cold Days: " + this.NumOfThreshs + "\n====================="; //Formats and the invoice to be printed
}
}
Change in class two
Temperatures weekOne = new Temperatures(week, thresh);
weekOne.GetWeekStatistics();
You have 7 all over the code. Make it a constant like
public static int DaysCount = 7 on the Tempratures class and reference that whenever needed (see example below).
class Temperatures
{
public static int DaysCount = 7;
}
You can then use it like this:
static void Main(string[] args)
{
double[] week = new double[Temperatures.DaysCount];
}
I can't see where you run the Determine...() functions, så the values are never calculated.
In the Determine...() functions you should set the value to an appropriate initial value before you run the loop as in:
public double DetermineHighest()
{
highest = -273 // degrees
for (int x = 0; x < DaysCount; x++) //Traverse through the week's temperatures
{
if (weeksTemperatures[x] > highest) //find the highest temperature of the week
{
highest = weeksTemperatures[x]; //and set it to highest
}
}
return highest;
}
Related
I want to write a method for a University class that takes a discipline as a parameter and returns the grade point average(GPA) of the students in that discipline, but I don't know how to do it, this is the signature of the method:
public double AverageOfDiscipline(discipline D)
{
double sum = 0;
for (int i = 0; i < students.Length; i++)
{
//???
}
return //????
}
and this is my project:
public enum discipline { Computer, Civil, Mechanical, Electrical}
public enum educationType { Undergraduate, Postgraduate}
class Student
{
public string nameAndLastName;
public double GPA;
public discipline discipline;
public educationType education;
public Student(string nameAndLastName, double GPA, discipline discipline, educationType education)
{
this.nameAndLastName = nameAndLastName;
this. GPA = GPA;
this.discipline = discipline;
this.education = education;
}
public string ToString()
{
return nameAndLastName + ": "+ education + ", "+ discipline+ "; "+"GPA: "+ GPA ;
}
}
class University
{
public string uniName;
public Student[] students;
public double AverageOfDiscipline(discipline D)
{
double sum = 0;
for (int i = 0; i < students.Length; i++)
{
//???
}
return //????
}
}
Thanks for your help.
For the university class you need to iterate through the students array,
check if they are pursuing the specified displine, sum then calculare average as below
public double AverageOfDiscipline(discipline D)
{
double sum = 0;
int totalStudentsForDispline = 0;
for (int i = 0; i < students.Length; i++)
{
if (students[i].discipline == D)
{
sum += students[i].GPA;
totalStudentsForDispline += 1;
}
}
return sum > 0 ? sum / totalStudentsForDispline : 0;
}
This is homework, but a small portion...
I'm trying to return the largest number in an array using arr.MAX(); , but I keep on getting zero.
After debugging, I can see that values are being stored (from the user) yet it still returns zero.
The method in question is at the bottom.
Class ElectionUI
{
public void candidateInfo()
{
do
{
for (int i = 0; i < theElection.CandidateNames.Length; i++)
{
Console.Write("Please enter the name for Candidate #" + (i +
1) + ": ");
theElection.CandidateNames[i] = Console.ReadLine();
Console.Write("Please enter the number of votes for: {0}: ",
theElection.CandidateNames[i]);
theElection.NumVotes[i] = int.Parse(Console.ReadLine());
Console.WriteLine("");
}
} while (theElection.NumVotes.Length < 5);
}
}
Class Election
{
private string[] candidateNames = new string[5];
private int[] numVotes = new int[5];
//get/set Candidate Names
public string[] CandidateNames
{
get { return candidateNames; }
set { candidateNames = value; }
}
//Get/Set Candidate votes
public int[] NumVotes
{
get { return numVotes; }
set { numVotes = value; }
}
public void findWinner()
{
int max = NumVotes.Max();
for (var i = 0; i < numVotes.Length; i++)
{
if (NumVotes[i] > max)
{
max = NumVotes[i];
}
}
Console.WriteLine(max);
}
}
from the code its not clear, how you are initializing you election class instance, and how you are calling findWinner method. And yes your Do-While looping doing nothing. Because you already set the name array length as 5 so it will run the for loop once and then it will exit. even if you remove your do-while you will get the same output.
check the fiddle your code is working fine. I just assume you are creating instance of Election and then passing it to ElectionUI class to use it.
https://dotnetfiddle.net/oiVK9g
using System;
using System.Linq;
public class Program
{
public static void Main()
{
var ele = new Election();
var ui = new ElectionUI(ele);
ui.candidateInfo();
ele.findWinner();
}
}
class ElectionUI
{
Election theElection;
public ElectionUI(Election obj)
{
theElection = obj;
}
public void candidateInfo()
{
do
{
for (int i = 0; i < theElection.CandidateNames.Length; i++)
{
Console.Write("Please enter the name for Candidate #" + (i +
1) + ": ");
theElection.CandidateNames[i] = Console.ReadLine();
Console.Write("Please enter the number of votes for: {0}: ",
theElection.CandidateNames[i]);
theElection.NumVotes[i] = int.Parse(Console.ReadLine());
Console.WriteLine("");
}
} while (theElection.NumVotes.Length < 5);
}
}
class Election
{
private string[] candidateNames = new string[5];
private int[] numVotes = new int[5];
//get/set Candidate Names
public string[] CandidateNames
{
get { return candidateNames; }
set { candidateNames = value; }
}
//Get/Set Candidate votes
public int[] NumVotes
{
get { return numVotes; }
set { numVotes = value; }
}
public void findWinner()
{
int max = NumVotes.Max();
Console.WriteLine(max);
}
}
I think that you wanted to return the candidate name of who won, right?
Using your code you should change the findWinner method to:
public void findWinner()
{
int max = NumVotes.Max();
string winnerName = null;
for (var i = 0; i < numVotes.Length; i++) {
if (NumVotes[i] = max) {
winnerName = CandidateNames[i];
}
}
Console.WriteLine(winnerName);
}
You need to initialize the local variable max with Int32.MinValue. That way any value encountered will replace it.
In my Inputs class I have an array named score. I need to use it in my MathFun class and get the sum of it.
class Inputs
{
int amountgames;
public void AmountOfGames()
{
Console.WriteLine("How many games did you play?");
amountgames = int.Parse(Console.ReadLine());
}
public void Scores()
{
int[] score = new int[amountgames];
Console.WriteLine("score for game ");
for (int i = 0; i < score.Length; i++)
{
score[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("\nThe scores you entered are");
for (int j = 0; j < score.Length; j++)
{
Console.WriteLine(score[j]);
}
}
}
class MathFun
{
int number1;
int number2;
int total;
int averaged;
public int Average;
public int Added1;
public MathFun()
{
}
public void DivideThem()
{
Average = number1 / number2;
}
public void Added()
{
Added1 = inputs.score.sum();
//This is where in the array and its sum
}
public MathFun(int innumber1, int innumber2)
{
number1 = innumber1;
number2 = innumber2;
}
public int Number1
{
get
{
return number1;
}
set
{
number1 = value;
}
}
public int Number2
{
get
{
return number2;
}
set
{
number2 = value;
}
}
public int Total
{
get
{
return total;
}
}
public int Averaged
{
get
{
return averaged;
}
}
public void CalcTotal()
{
total = Added1;
averaged = Average;
}
}
You have two choices
Create an instance of Inputs that you can use in MathFun.
Make Scores() static, so that an instance is not required. If you do that, amountgames and AmountOfGames() will also have to become static.
Either way, you will have to return the inputs from Scores() or store them in some way in the class.
public int[] Scores()
{
int[] score = new int[amountgames];
Console.WriteLine("score for game ");
for (int i = 0; i < score.Length; i++)
{
score[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("\nThe scores you entered are");
for (int j = 0; j < score.Length; j++)
{
Console.WriteLine(score[j]);
}
}
return score;
}
Here's how you could approach it with the first approach
Inputs inputs = new Inputs();
int[] scores = Scores();
// Use scores with MathFun
NOTE: I would not generally create a function that is both responsible for writing scores out to the console and returning them. A single responsibility per method is preferred. The solution here is one that modifies your current code as little as possible.
Found my own solution
int sum = 0;
for (int i = 0; i < score.Length; i++)
{
sum += score[i];
}
add this to the array to add it all up
then just make an instance of sum
I am having a problem getting my program to check the input previous and compare it so the user cannot duplicate an order number. Right now the program will run all the way through and look the way I want, but it accepts duplicate order numbers while I would like it to inform the user and ask them to reenter. The problem seems to be that my check[y] array does not contain any value when I compare it. How do I get this array to contain the previously entered order numbers so it will display the error message. I am just going to post the entire code so you can see what I have done so far. Others have suggested the List type, but I am a student and have not learned this yet. I believe I am supposed to use the Equals method. Any help would be appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment6_Hergott
{
class Order : IComparable <Order>
{
public int orderNumber { get; set; }
public string customerName { get; set; }
public int quanityOrdered { get; set; }
public double total;
public const double priceEach = 19.95;
public Order()
{
}
public Order(int number, string name, int quanity)
{
number = orderNumber;
name = customerName;
quanity = quanityOrdered;
}
public double totalPrice
{
get
{
return total;
}
}
public int CompareTo(Order o)
{
return this.orderNumber.CompareTo(o.orderNumber);
}
public override bool Equals(Object e)
{
bool equal;
Order temp = (Order)e;
if (orderNumber == temp.orderNumber)
equal = true;
else
equal = false;
return equal;
}
public override int GetHashCode()
{
return Convert.ToInt32(orderNumber);
}
public override string ToString()
{
return "ShippedOrder " + orderNumber + " " + customerName + " " + quanityOrdered +
" # " + priceEach + " each.";
}
}
class ShippedOrder : Order
{
public const int shippingFee = 4;
public override string ToString()
{
return base.ToString() + " Shipping is " + shippingFee + " Total is " + totalPrice;
}
}
class Program
{
static void Main(string[] args)
{
double sum = 0;
ShippedOrder[] orderArray = new ShippedOrder[5];
ShippedOrder[] check = new ShippedOrder[5];
bool wrong = true;
for (int x = 0; x < orderArray.Length; ++x)
{
orderArray[x] = new ShippedOrder();
Console.Write("Enter order number: ");
orderArray[x].orderNumber = Convert.ToInt32(Console.ReadLine());
for (int y = 0; y < x; y++)
{
check[y] = new ShippedOrder();
if (orderArray[x].Equals(check[y]))
wrong = false;
while (!wrong)
{
Console.WriteLine("Sorry, the order number {0} is a duplicate.
\nPlease reenter: ", orderArray[x].orderNumber);
for (y = 0; y < x; y++)
{
if (orderArray[x].Equals(check[y]))
wrong = false;
}
check[y] = orderArray[x];
}
}
Console.Write("Enter cusomer name: ");
orderArray[x].customerName = Console.ReadLine();
Console.Write("Enter quanity: ");
orderArray[x].quanityOrdered = Convert.ToInt32(Console.ReadLine());
orderArray[x].total = orderArray[x].quanityOrdered * Order.priceEach +
ShippedOrder.shippingFee;
sum += orderArray[x].total;
}
Array.Sort(orderArray);
for (int x = 0; x < orderArray.Length; x++)
{
Console.WriteLine(orderArray[x].ToString());
}
Console.WriteLine();
Console.WriteLine("Total for all orders is {0:c} ", sum);
}
}
}
I had a few minutes so I changed my answer to show you one way it could be done. If you just copy/paste this you'll be doing yourself a disservice, though (and your instructor will probably be able to tell). Take a look at the solution and see how it differs from yours. I hesitated to post a full solution but I thought this might be an okay way for you to figure out what you'd done wrong.
namespace ConsoleApplication2
{
using System;
using System.Linq;
public class Order : IComparable<Order>
{
public const double PriceEach = 19.95;
public Order()
{
}
public Order(int number, string name, int quanity)
{
this.OrderNumber = number;
this.CustomerName = name;
this.QuanityOrdered = quanity;
}
public int OrderNumber { get; set; }
public string CustomerName { get; set; }
public int QuanityOrdered { get; set; }
public int CompareTo(Order o)
{
return this.OrderNumber.CompareTo(o.OrderNumber);
}
public override bool Equals(object e)
{
int compareTo;
int.TryParse(e.ToString(), out compareTo);
return this.OrderNumber == compareTo;
}
public override int GetHashCode()
{
return Convert.ToInt32(this.OrderNumber);
}
public override string ToString()
{
return "Shipped order number " + this.OrderNumber + " for customer " + this.CustomerName + " " + this.QuanityOrdered +
" # $" + PriceEach + " each.";
}
}
public class ShippedOrder : Order
{
public const int ShippingFee = 4;
public double TotalPrice
{
get
{
return (this.QuanityOrdered * PriceEach) + ShippingFee;
}
}
public override string ToString()
{
return base.ToString() + " Shipping is $" + ShippingFee + ". Total is $" + this.TotalPrice;
}
}
public class Program
{
private static readonly int[] OrderNumbers = new int[5];
private static readonly ShippedOrder[] ShippedOrders = new ShippedOrder[5];
public static void Main(string[] args)
{
double sum = 0;
for (var i = 0; i < OrderNumbers.Length; i++)
{
OrderNumbers[i] = InputOrderNumber();
var name = InputCustomerName();
var quantity = InputQuantity();
ShippedOrders[i] = new ShippedOrder { CustomerName = name, QuanityOrdered = quantity, OrderNumber = OrderNumbers[i] };
sum += ShippedOrders[i].TotalPrice;
}
Array.Sort(ShippedOrders);
foreach (var t in ShippedOrders)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
Console.WriteLine("Total for all orders is {0:c} ", sum);
Console.WriteLine();
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
private static int InputOrderNumber()
{
Console.Write("Enter order number: ");
var parsedOrderNumber = InputNumber();
if (ShippedOrders.Any(shippedOrder => shippedOrder != null && shippedOrder.OrderNumber.Equals(parsedOrderNumber)))
{
Console.WriteLine("Order number {0} is a duplicate.", parsedOrderNumber);
return InputOrderNumber();
}
return parsedOrderNumber;
}
private static string InputCustomerName()
{
Console.Write("Enter customer name: ");
var customerName = Console.ReadLine();
if (customerName == null || string.IsNullOrEmpty(customerName.Trim()))
{
Console.WriteLine("Customer name may not be blank.");
return InputCustomerName();
}
return customerName;
}
private static int InputQuantity()
{
Console.Write("Enter quantity: ");
return InputNumber();
}
private static int InputNumber()
{
int parsedInput;
var input = Console.ReadLine();
if (!int.TryParse(input, out parsedInput))
{
Console.WriteLine("Enter a valid number.");
return InputNumber();
}
return parsedInput;
}
}
}
my check[y] array does not contain any value when I compare it. How do
I get this array to contain the previously entered order numbers
If you want check[] to contain order numbers, it needs to be of the type of order number (an int, in this case). So whenever you add a new order to the orderArray, also add its number to the check array. Then you can test against earlier numbers.
If this doesn't solve your problem, add a follow-up question as a comment telling us what you tried and we can go from there.
I have to build some logic to write some sort of scoreboard. The idea is this:
There are many stages:
1st stage you have 2 numbers. 7 and 3=10
2nd stage you have another 2 numbers. 5 and 1 =6
After the loop has finished, the wanted result should be:
Stage 1 total score=15 (total 1st Stage + firstTry of secondStage)
Stage 2 total score=21 (total 1st Stage + (firstTry + SecondTry of SecondStage)
What's wrong with my loop? I dont seem to get the wanted resoult.
private void Calculate(Player player)
{
for (int i = 0; i < player.Game.Stages.Length; i++)
{
int firstThrow = player.Game.Stages[i].FirstTry;
int secondThrow = player.Game.Stages[i].SecondTry;
int sumFirstAndSecond = firstThrow + secondThrow;
//If firstTry + SecondTry==10 is spare
if ((sumFirstAndSecond == 10) && (firstThrow != 10) && i != player.Game.Stages.Length- 1)
{
int stageScore= player.Game.Stages[i].TotalScore +
player.Game.Stages[i + 1].FirstTry;
player.Game.Stages[i].TotalScore = stageScore;
}
}
}
public class Stage
{
public int FirstTry { get; set; }
public int SecondTry { get; set; }
public int TotalScore { get; set; }
}
public class Player
{
public Player(string name)
{
Name = name;
Game = new Game(name);
}
public Game Game { get; set; }
public string Name { get; set; }
}
public class Game
{
public Game(string playerName)
{
PlayerName = playerName;
Stages = new Stage[10];
for (int i = 0; i < Stages.Length; i++)
{
Stages[i] = new Stage();
}
}
public Stage[] Stages { get; internal set; }
public string PlayerName { get; set; }
}
Change this:
private void Calculate(Player player)
{
for (int i = 0; i < player.Game.Stages.Length; i++)
{
int firstThrow = player.Game.Stages[i].FirstTry;
int secondThrow = player.Game.Stages[i].SecondTry;
int sumFirstAndSecond = firstThrow + secondThrow;
if ((sumFirstAndSecond == 10) && (firstThrow != 10) && i != player.Game.Stages.Length- 1)
{
int stageScore= player.Game.Stages[i].TotalScore + player.Game.Stages[i + 1].FirstTry;
player.Game.Stages[i].TotalScore = sumFirstAndSecond + stageScore;
}
else if (i > 0) player.Game.Stages[i].TotalScore = player.Game.Stages[i - 1].TotalScore + sumFirstAndSecond;
}
}
Bowling?
Try this, and do not forget to add misses (as 0).
Should work for both running and final scoring.
// All balls, including misses (0)!
public readonly IList<int> _balls = new List<int>();
private int _currentBall;
public int CalculateTotalScore()
{
int score = 0;
_currentBall = 0;
for (var frame = 0; frame < 10; frame++)
{
if (_currentBall >= _balls.Count)
break;
if (_balls[_currentBall] == 10)
{
// Strrrike!
score += AggregateScoreFromCurrentBall(3);
_currentBall++;
}
else if (AggregateScoreFromCurrentBall(2) == 10)
{
// Spare
score += AggregateScoreFromCurrentBall(3);
_currentBall += 2;
}
else
{
score += AggregateScoreFromCurrentBall(2);
_currentBall += 2;
}
}
return score;
}
private int AggregateScoreFromCurrentBall(int numberOfBallsToSum)
{
var sum = 0;
for (var i = 0; i < numberOfBallsToSum; i++)
if (_currentBall + i < _balls.Count)
sum += _balls[_currentBall + i];
return sum;
}