In: Computer Science
Previously, you wrote a program named Admission for a college admissions office in which the user enters a numeric high school grade point average and an admission test score. The program displays Accept or Reject based on those values. Now, create a modified program named AdmissionModularized in which the grade point average and test score are passed to a method that returns a string containing Accept or Reject.
CODE:
using System;
using static System.Console;
class Admission
{
static void Main()
{
double gpa;
int testScore;
const double MINGPA = 3.0;
const int ADMIN1 = 60, ADMIN2 = 80;
string inputString;
WriteLine("Enter grade point average ");
inputString = ReadLine();
gpa = Convert.ToDouble(inputString);
WriteLine("Enter test score ");
inputString = ReadLine();
testScore = Convert.ToInt32(inputString);
if(gpa >= MINGPA)
if(testScore >= ADMIN1)
WriteLine("Accept");
else
WriteLine("Reject");
else
if(testScore >= ADMIN2)
WriteLine("Accept");
else
WriteLine("Reject");
}
public static string AcceptOrReject(double gpa, int testScore)
{
// Write your AcceptOrReject method here.
}
}
Below is modified program for AdmissionModularized in which the grade point average and test score are passed to a method that returns a string containing Accept or Reject.
using System;
using static System.Console;
class AdmissionModularized
{
const double MINGPA = 3.0;
const int ADMIN1 = 60, ADMIN2 = 80;
static void Main()
{
double gpa;
int testScore;
string inputString;
WriteLine("Enter grade point average ");
inputString = ReadLine();
gpa = Convert.ToDouble(inputString);
WriteLine("Enter test score ");
inputString = ReadLine();
testScore = Convert.ToInt32(inputString);
string result = AcceptOrReject(gpa,testScore);
WriteLine(result);
}
// AcceptOrReject method here.
public static string AcceptOrReject(double gpa, int testScore)
{
if(gpa >= MINGPA)
if(testScore >= ADMIN1)
return "Accept";
else
return "Reject";
else
if(testScore >= ADMIN2)
return "Accept";
else
return "Reject";
}
}
Output: