Question

In: Computer Science

programming language is c#. Create a method that prompts a user of your console application to...

programming language is c#.
Create a method that prompts a user of your console application to input the information for a student:

static void GetStudentInfo()
{
Console.WriteLine("Enter the student's first name: ");
string firstName = Console.ReadLine();
Console.WriteLine("Enter the student's last name");
string lastName = Console.ReadLine();
// Code to finish getting the rest of the student data
.....
}

static void PrintStudentDetails(string first, string last, string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday);
}

1. Using the above partial code sample, complete the method for getting student data.
2. Create a method to get information for a teacher, a course, and program, and a degree using a
similar method as above.
3. Create methods to print the information to the screen for each object such as static
void PrintStudentDetails(...).
4. Just enter enough information to show you understand how to use methods. (At least three
attributes each).
5. Call the Get methods from the Main method in the application.
6. Call the Print methods from within each Get method.
Exceptions
1. At times, developers create method signatures early on in the development process but leave the
implementation until later. This can lead to methods that are not complete if a developer forgets
about these empty methods. One way to help overcome the issue of not remembering to complete
a method is to throw an exception in that method if no implementation details are present.
2. For this task, use MSDN to research the NotImplementedException exception.
3. Create a new method for validating a student's birthday. You won't write any validation code in this
method, but you will throw the NotImplementedException in this method.
4. Call the method from Main() to verify your exception is thrown.
Challenge
Using MSDN, research the System.DateTime type. Using the information you learn, modify your birth
date field for the student and/or teacher to ensure it used a DateTime type if you did not already
include that in your data for these objects.
• Remove your NotImplementedException statement in the validate method you created above.
• Create a try/catch block to catch invalid date entries and display a message to the user if this
occurs. (Console output)
• Assume that your student must be at least 18 years of age to enroll at a university.
• Write code that validates the student is at least 18 years old. You can use birth year and math or
you can calcuate from today's date and work back.
• Output an error message to the console window if the student's age is less than 18

Solutions

Expert Solution

Hi,

Please find the below output for the program

using System;

namespace ConsoleApp1
{
    class Program
    {
        public static string sUpdatedbirthDate = string.Empty;
        static void Main(string[] args)
        {
            //Fetch and show student Details
            GetStudentInfo();

            //Fetch and show Teachers Details
            GetTeachersInfo();

            //Fetch and show Course Details
            GetcourseInfo();

            //Fetch and show Program Details
            GetProgramInfo();

            //Fetch and show Degree Details
            GetDegreeInfo();
        }

        /// <summary>
        /// students infor
        /// </summary>
        static void GetStudentInfo()
        {
            Console.WriteLine("Enter the student's first name: ");
            string firstName = Console.ReadLine();
            Console.WriteLine("Enter the student's last name");
            string lastName = Console.ReadLine();
            Console.WriteLine("Enter the student's Birthdate in dd/MM/yyyy format");
            string dtBirthDate = (Console.ReadLine());

            // validate Students Age
            
            int age = ValidateStudentsBirthday(dtBirthDate);
            string str = string.Empty;
            if (age < 18)
            {
                Console.WriteLine("student's age is : "+ age  + ", less than 18");

            }

            PrintStudentDetails(firstName, lastName, sUpdatedbirthDate.Length > 0 ? sUpdatedbirthDate : dtBirthDate, age);

        }

        /// <summary>
        /// Print Student Details
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        /// <param name="birthday"></param>
        static void PrintStudentDetails(string first, string last, string birthday, int age)
        {
            Console.WriteLine("{0} {1} was born on: {2} and age is: {3}", first, last, birthday, age);
        }

        /// <summary>
        /// teachers info
        /// </summary>
        static void GetTeachersInfo()
        {
            Console.WriteLine("Enter the Teacher's first name: ");
            string firstName = Console.ReadLine();
            Console.WriteLine("Enter the Teacher's last name");
            string lastName = Console.ReadLine();
            Console.WriteLine("Enter the Teacher's Birthdate in MM/DD/YYYY format");
            string dtBirthDate = (Console.ReadLine());

            PrintTeachersDetails(firstName, lastName, dtBirthDate);
        }

        /// <summary>
        /// Print Teacher Details
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        /// <param name="birthday"></param>
        static void PrintTeachersDetails(string first, string last, string birthday)
        {
            Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday);
        }

        /// <summary>
        /// Course Info
        /// </summary>
        static void GetcourseInfo()
        {
            Console.WriteLine("Enter the course name: ");
            string coursename = Console.ReadLine();
            Console.WriteLine("Enter the course duration in Years");
            string duration = Console.ReadLine();
            Console.WriteLine("Enter the cost of the course");
            string courseCost = (Console.ReadLine());

            PrintCourseDetails(coursename, duration, courseCost);
        }

        /// <summary>
        /// Print Course Details
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        /// <param name="birthday"></param>
        static void PrintCourseDetails(string coursename, string duration, string courseCost)
        {
            Console.WriteLine("{0} course is having duration - {1} and cose of that Course is: {2}", coursename, duration, courseCost);
        }

        /// <summary>
        /// Program Info
        /// </summary>
        static void GetProgramInfo()
        {
            Console.WriteLine("Enter the Program name: ");
            string ProgramName = Console.ReadLine();
            Console.WriteLine("Enter the Program Start Date");
            string ProgramStartDate = Console.ReadLine();
            Console.WriteLine("Enter the Program Duration");
            string ProgramDuratioin = (Console.ReadLine());

            PrintProgramDetails(ProgramName, ProgramStartDate, ProgramDuratioin);
        }

        /// <summary>
        /// Print Student Details
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        /// <param name="birthday"></param>
        static void PrintProgramDetails(string ProgramName, string ProgramStartDate, string ProgramDuratioin)
        {
            Console.WriteLine("Program {0} will be starting on {1} and duration is: {2}", ProgramName, ProgramStartDate, ProgramDuratioin);
        }

        /// <summary>
        /// Degree Info
        /// </summary>
        static void GetDegreeInfo()
        {
            Console.WriteLine("Enter the Name of Degree: ");
            string DegreeName = Console.ReadLine();
            Console.WriteLine("Enter the Duration of Degree in years");
            string DurationOfDegree = Console.ReadLine();
            Console.WriteLine("Enter the semester parrtern");
            string DegreeSemeseterPatters = (Console.ReadLine());

            PrintDegreeDetails(DegreeName, DurationOfDegree, DegreeSemeseterPatters);
        }

        /// <summary>
        /// Print Degree Details
        /// </summary>
        /// <param name="first"></param>
        /// <param name="last"></param>
        /// <param name="birthday"></param>
        static void PrintDegreeDetails(string DegreeName, string DurationOfDegree, string DegreeSemeseterPatters)
        {
            Console.WriteLine("Degree Name - {0} will {1} Years of duration and Semester pattern is: {2}", DegreeName, DurationOfDegree, DegreeSemeseterPatters);
        }

        /// <summary>
        /// Calculate Students BirthDay and return the result
        /// </summary>
        /// <param name="iBirthYear"></param>
        /// <returns></returns>
        static private int ValidateStudentsBirthday(string sBirthdate)
        {
            try
            {
                

                //Set today's date as a variable            
                DateTime todayDate = DateTime.Today;

                DateTime dateOfBirth = new DateTime();
                while (!DateTime.TryParseExact(sBirthdate, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out dateOfBirth))
                {
                    
                        Console.WriteLine("Invalid date, please retry");
                        sBirthdate = Console.ReadLine();
                        sUpdatedbirthDate = sBirthdate;
                        //In case of invalid date, again check the valid date in recursive loop

                        ValidateStudentsBirthday(sBirthdate);
                    
                }

                //Calculate user age
                var today = DateTime.Today;

                var a = (today.Year * 100 + today.Month) * 100 + today.Day;
                var b = (dateOfBirth.Year * 100 + dateOfBirth.Month) * 100 + dateOfBirth.Day;

                int userAge = (a - b) / 10000;


                
                
                return userAge;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
               
                return 0;
            }
        }


    }


}

Test Cases:


Related Solutions

C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of miles, passes the value to a method that converts the value to kilometers, and then returns the value to the Main() method where it is displayed.
C# Create a console application that asks the user for two numbers in the range 0-255...
C# Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT