Implement a c# method CalculateCourseFee(double courseFee, double marks, double serviceFee) to calculate the total fees to be paid by a student.
The students are entitled to get scholarship based on the marks scored in the qualifying exam. Scholarship percentage should be considered as half of the marks scored by the student on the course fee. Apart from the course fee(after deducting the scholarship amount), the students have to pay extra service fees.
Assume that the marks is out of 100 and need not always be integer.
public class Program
{
// Input double number method with correct value control
public static bool InputDouble(out double value)
{
string str;
try
{
str = Console.ReadLine();
value = Convert.ToDouble(str);
if (value > 0) // fee value must be positive
return true;
else
return false;
}
catch
{
value = 0;
return false;
}
}
// input Course Fee method
public static double CourseFeeInput()
{
double courseFee;
do
{
Console.WriteLine();
Console.WriteLine("Please input CORRECT course fee value below: ");
Console.WriteLine();
}
while (!InputDouble(out courseFee));
return courseFee;
}
// input Marks method
public static double MarksInput()
{
double marks;
do
{
do
{
Console.WriteLine();
Console.WriteLine("Please input CORRECT marks value below: ");
Console.WriteLine();
}
while (!InputDouble(out marks));
}
while (!((marks >= 100) & (marks <= 200))); // marks value must be more than 100 and less than 200 because of non negative course fee value
return marks;
}
// input Extra Service Fee method
public static double ExtraServiceFeeInput()
{
double extraServiceFee;
do
{
Console.WriteLine();
Console.WriteLine("Please input CORRECT extra service fee value below: ");
Console.WriteLine();
}
while (!InputDouble(out extraServiceFee));
return extraServiceFee;
}
// calculating total fees to be paid by a student
public static void CalculateCourseFee(double courseFee, double marks, double serviceFee)
{
Console.WriteLine();
Console.WriteLine("Total fees paid by student: ");
Console.WriteLine();
Console.WriteLine('\t' + "Course Fee: " + courseFee.ToString());
Console.WriteLine('\t' + "minus Scholarship: " + ((marks / 200) * courseFee).ToString());
Console.WriteLine('\t' + "plus Extra Service: " + serviceFee.ToString());
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("TOTAL:" + '\t' + (courseFee * (1 - (marks / 200)) + serviceFee).ToString());
Console.WriteLine();
Console.WriteLine("Press any key to close app...");
}
public static void Main()
{
CalculateCourseFee(CourseFeeInput(), MarksInput(), ExtraServiceFeeInput());
Console.ReadKey();
}
}
Comments
Leave a comment