please help me out on this program in OOP(c# console program)?
An applicant will be accepted to the Jedi knight Military Academy if he is at least 200 cm. Tall; age is between 21 and 25, inclusive;and a citizen of the Planet Endor. However, if the applicant is a recommendee of Jedi Master Obi wan,he is accepted automatically regardless of his height, age,citizenship.write a program that would input the applicant's height,age,citizenship code("C" for citizen of Endor,"N" for non citizen), and recommendee code("R") for recommendee,"N" for non-recommendee).And then output whether the applicant is accepted or rejected.
1
Expert's answer
2012-07-19T08:50:38-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace JediAcademy { class Program { & static void Main(string[] args) & { int heightOfApplicant=0; int ageOfApplicant=0; string citizenshipCode; string recommendeeCode; string repeatAnswer=null;
do { Console.Clear(); Console.WriteLine("Examination of new applicant for Jedi Knight Military Academy.");
bool flag; do { & flag = true; & try & { Console.WriteLine("\nIput applicant's height(in cm): "); heightOfApplicant = Convert.ToInt32(Console.ReadLine()); & } & catch (FormatException)& //cheking correctness of the input & { Console.WriteLine("Incorrect input. Please repeat."); flag = false; & } } while (!flag);
do { & flag = true; & try & { Console.WriteLine("\nIput applicant's age: "); ageOfApplicant = Convert.ToInt32(Console.ReadLine()); & } & catch (FormatException)& //cheking correctness of the input & { Console.WriteLine("Incorrect input. Please repeat."); flag = false; & } } while (!flag);
Console.WriteLine("\nIput applicant's citizenship code\n(\"C\" for citizen of Endor,\"N\" for non citizen): "); citizenshipCode = Console.ReadLine();
Console.WriteLine("\nIput applicant's recommendee code\n(\"R\" for recommendee,\"N\" for non-recommendee): "); recommendeeCode = Console.ReadLine();
if (recommendeeCode == "R" || recommendeeCode == "r") & Console.WriteLine("\n Applicant is accepted!"); else { & //cheking all conditions for the acception & if ((heightOfApplicant >= 200) && (ageOfApplicant >= 21 && ageOfApplicant <= 25) && (citizenshipCode == "C" || citizenshipCode == "c")) Console.WriteLine("\n Applicant is accepted!"); & else Console.WriteLine("\n Applicant is not accepted!"); }
Console.WriteLine("\nDo you want to test another applicant(y/n)?"); repeatAnswer=Console.ReadLine();
Comments
Leave a comment