Answer to Question #343895 in C# for mee

Question #343895

Write a program which can be used to calculate bonus points to given scores in the range [1..9] according to the following rules:

 If the score is between 1 and 3, the bonus points is the score multiplied by 10

 If the score is between 4 and 6, the bonus points is the score multiplied by 100

 If the score is between 7 and 9, the bonus points is the score multiplied by 1000

 For invalid scores there are no bonus points (0) Your program must make use of 2 parallel arrays – one to store the scores and the other to store the bonus points. You need to make provision for 5 scores (and bonus points) that will need to be stored.


For this program implement the following methods and use these methods in your solution (do not change the method declarations):

static void getScores(int[] scores)

static void calcBonus(int[] scores, int[] bonusPoints)

static void displayAll(int[] scores, int[] bonusPoints)



1
Expert's answer
2022-05-25T10:25:03-0400
using System;
public class BonusPoints
{
    const int count = 5;
    static int[] scores = new int[count];
    static int[] bonusPoints = new int[count];
    public static void Main(string[] args)
    {
        getScores(scores);
        calcBonus(scores, bonusPoints);
        displayAll(scores, bonusPoints);
    }
    static void getScores(int[] scores)
    {
        string str = "";
        int Number;
        int i = 0;
        if (scores != null)
        {
            while (i < count)
            {
                Console.Write("Please enter integer:");
                str = Console.ReadLine();
                if (int.TryParse(str, out Number))
                {
                    scores[i] = Number;
                    i++;
                }
            }
        }
    }
    static void calcBonus(int[] scores, int[] bonusPoints)
    {
        if (scores != null && bonusPoints != null)
            for (int i = 0; i < count; i++)
            {
                if (scores[i] >= 1 && scores[i] <= 3)
                    bonusPoints[i] = scores[i] * 10;
                else if (scores[i] >= 4 && scores[i] <= 6)
                    bonusPoints[i] = scores[i] * 100;
                else if (scores[i] >= 7 && scores[i] <= 9)
                    bonusPoints[i] = scores[i] * 1000;
                else
                    bonusPoints[i] = 0;
            }
    }
    static void displayAll(int[] scores, int[] bonusPoints)
    {
        if (scores != null && bonusPoints != null)
        {
            Console.WriteLine("scores:");
            for (int i = 0; i < count; i++)
                Console.Write(scores[i] + " ");
            Console.WriteLine("");
            Console.WriteLine("bonusPoints:");
            for (int i = 0; i < count; i++)
                Console.Write(bonusPoints[i] + " ");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS