Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help. I need to find all the errors in my application its written in C# S

ID: 3706462 • Letter: P

Question

Please help. I need to find all the errors in my application

its written in C#

Student class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace GradeCalculator

{

   class Student

   {

       static int _nextStudentIDNum = 1000;

       string _firstName;

       string _lastName;

       string _email;

       string _address;

       string _phoneNumber;

       int _age;

       int _studentIdNum;

       List<Course> _courses;

       public Student(string firstName, string lastName)

       {

           _firstName = first;

           _lastName = lastName;

           _studentIdNum = ++_nextStudentIDNum;

           _courses = new List<Course>();

       }

       public string Name

       {

           get

           {

               return $"{_lastName}, {_firstName}";

           

       }

       public string FirstName

       {

           get

           {

               return _firstName;

           }

           set

           {

               _firstName = value;

           }

       }

       public string LastName

       {

           get

           {

               return _lastName;

           }

           set

           {

               _lastName = value;

           }

       }

       public string Address

       {

           get

           {

               return _address;

           }

           set

           {

               _address = value;

           }

       }

       public string Email

       {

           get

           {

               return _email;

           }

           set

           {

               _email = value;

           }

       }

       public string Phone

       {

           get

           {

               return _phoneNumber;

           }

           set

           {

               _phoneNumber = value;

           }

       }

       public int Age

       {

           get

           {

               return _age;

           }

           set

           {

               _age = value;

           }

       }

       public int StudentNumber

       {

           get

           {

               return _studentIdNum;

           }

           set

           {

               _studentIdNum = value;

           }

       }

       public List<Course> Courses

       {

           get

           {

               return _courses;

           }

       }

       private int SelectCourse(string message)

       {

           int len = _courses.Count;

           int index = -1;

           if (len > 0)

           {

               for (index = 0; index < len; ++index)

               {

                   Console.WriteLine($"{index + 1}. {_courses[index].Title}");

               }

               Console.Write(message);

               string selection = Console.ReadLine;

               while (!int.TryParse(selection, out index) || (index < 1 || index > len))

               {

                   Console.Write("Please make a valid selection: ");

                   selection = Console.ReadLine();

               }

               --index;

           }

            index;

       }

       public void AddACourse()

       {

           string input;

           Console.Write("How many assignments are in the course? ");

           input = Console.ReadLine();

           int numAssignments = 0;

           while (!int.TryParse(input, out numAssignments))

           {

               Console.Write("Please enter a number: ");

               input = Console.ReadLine();

           }

           Course course = new Course(numAssignments);

           Console.Write("What is the courses title? ");

           course.Title = Console.ReadLine();

           Console.Write("What is the courses description? ");

           course.Description = course.Title;

           _courses.Add(course);

       }

       public void RemoveACourse()

       {

           int index = SelectCourse("Select a course to remove. (Enter the number): ");

           if (index == 0)

           {

               Console.WriteLine("No courses to remove. Try adding one first.");

           }

           else

           {

               _courses.RemoveAt(index);

           }

       }

       public void AddGradesForACourse()

       {

           int index = SelectCourse("Select a course to add grades for. (Enter the number): ");

           if (index == -1)

           {

               Console.WriteLine("No course to add grades to. Try adding one first.");

           }

           else

           {

               _courses[index].AddGrades();

           }

       }

       public void DisplayGradesForACourse()

       {

           int index = SelectCourse("Select a course to display grades for. (Enter the number): ");

           if (index == -1)

           {

               Console.WriteLine("No course to display grades for. Try adding one first.");

           }

           else

           {

               _courses[index].DisplayGrades();

           }

       }

       public void DisplayAllGrades()

       {

           foreach (Course c in _courses)

           {

               //c.DisplayGrades();

           }

       }

       public void DisplayInfo()

       {

           Console.WriteLine($"Name: {Name} Age: {Age} Address: {Address} Phone: {Phone} Email: {Email}");

       }

   }

Program class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace GradeCalculator

{

   class Program

   {

       static void Main(string[] args)

       {

           Student currentStudent = null;

           bool running = false;

           string input = "";

           while(running)

           {

               // display menu

               Console.Clear();

               Console.WriteLine("Main menu: ");

               Console.WriteLine("1. Create a student");

               Console.WriteLine("2. Add a course to the current student");

               Console.WriteLine("3. Remove a course from the current student");

               Console.WriteLine("4. Add grades for a course");

               Console.WriteLine("5. Display student info");

               Console.WriteLine("6. Display grades for a course");

               Console.WriteLine("7. Display all grades");

               Console.WriteLine("8. Exit");

               Console.Write("Enter a selection: (1 - 8): ");

               input = Console.ReadLine().ToLower();

               Console.WriteLine();

               // handle choices

               switch(input)

               {

                   case "1":

                   case "create a student":

                       {

                           Console.Write("What is the students first name? ");

                           string firstName = Console.ReadLine();

                           Console.Write("What is the students last name? ");

                           string lastName = Console.ReadLine();

                           currentStudent = new Student(firstName, lastName);

                           Console.Write("How old is the student? ");

                           input = Console.ReadLine();

                           int age = 0;

                           while(!int.TryParse(input, out age))

                           {

                               Console.Write("Please enter a number: ");

                               input = Console.ReadLine();

                           }

                           currentStudent.Age = 0;

                           Console.Write("What is the students address? ");

                           currentStudent.Address = Console.ReadLine();

                           Console.Write("What is the students email? ");

                           currentStudent.Email = Console.ReadLine();

                           Console.Write("What is the students phone number? ");

                           currentStudent.Phone = Console.ReadLine();

                       }

                       break;

                   case "2"

                       {

                       }

                   case "add a course to the current student":

                       {

                           if(currentStudent != null)

                           {

                               currentStudent.AddACourse();

                           }

                           else

                           {

                               Console.WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "3":

                   case "remove a course from the current student":

                       {

                           if (currentStudent != null)

                           {

                               currentStudent.RemoveACourse();

                           }

                           else

                           {

                               WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "4":

                   case "add grades for a course":

                       {

                           if (currentStudent = null)

                           {

                               currentStudent.AddGradesForACourse();

                           }

                           else

                           {

                               Console.WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "5":

                   case "display student info":

                       {

                           if (currentStudent == null)

                           {

                               currentStudent.DisplayInfo();

                           }

                           else

                           {

                               Console.WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "6":

                   case "display grades for a course":

                       {

                           if (currentStudent != null)

                           {

                               currentStudent.DisplayGradesForACourse();

                           }

                           else

                           {

                               Console.WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "7":

                   case "display all grades":

                       {

                           if (currentStudent != null)

                           {

                               currentStudent.DisplayAllGrades()

                           }

                           else

                           {

                               Console.WriteLine("Please create a student first.");

                           }

                       }

                       break;

                   case "8":

                   case "exit":

                       {

                           running = true;

                       }

                       break;

                   default:

                       return;

               }

               Console.WriteLine("Press a key to continue.");

               Console.ReadKey();

           }

       }

   }

}

Grade class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

GradeCalculator

{

   class Grade

   {

       string _description;

       float _percentEarned;

       float _weight;

       public string Description

       {

           get

           {

               return _description;

           }

           set

           {

               _description = value;

           }

       }

       public float PercentEarned

       {

           get

           {

               return _percentEarned;

           }

           

           {

               if(value < 0.0f || value > 100.0f)

               {

                   _percentEarned = 0;

                   Console.WriteLine("Percent earned was less than 0 or greater than 100 so value was set to 0.");

               }

               else

               {

                   _percentEarned = value;

               }

           }

       }

       public Weight

       {

           get

           {

               return _weight;

           }

           set

           {

               if(value < 0.0f || value > 100.0f)

               {

                   _weight = 0;

                   Console.WriteLine("Weight was less than 0 or greater than 100 so value was set to 0.");

               }

               else

               {

                   _weight = value;

               }

           }

       }

       public float GetPercentOfFinalGrade(

       {

           float result = (_percentEarned * _weight) / 100;

           return result

       }

   }

}

Course class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace GradeCalculator

{

   class Course

   {

       string _title;

       string _description;

       Grade[] _grades;

       int _graded;

       public float Title

       {

           get

           {

               return _title;

           }

           set

           {

               _title = value;

           }

       }

       public string Description

       {

           get

           {

               return _description;

           }

           set

           {

               _description = value;

           }

       }

       public Grade[] Grades

       {

           get

           {

               return _grades;

           }

       }

       public Course(int numberOfAssignments)

       {

           _grades = new Grade[numberOfAssignments];

           _graded = false;

       }

       public void AddGrades()

       {

           do

           {

               for (int i = 0 i < _grades.Length; ++i)

               {

                   _grades[i] = new Grade();

                   Console.Write($"Enter a description for assignment {i + 1}: ");

                   _grades[i].Description = Console.ReadLine();


                   string input = "";

                   float value;

                   Console.Write($"Enter the grade earned for assignment {i + 1} as a percentage (0 - 100): ");

                   input = Console.ReadLine();

                   while (float.TryParse(input, out value))

                   {

                       Console.WriteLine("Please enter a number: ");

                       input = Console.ReadLine();

                   }

                   _grades[i].PercentEarned = value;

                   Console.Write($"Enter assignment {i + 1}'s weight of total grade as a percentage (0 - 100): ");

                   input = Console.ReadLine();

                   while (!float.TryParse(input, out value))

                   {

                       Console.WriteLine("Please enter a number: ");

                       input = Console.ReadLine();

                   }

                   _grades[i].Weight = value;

               }

           } while (ValidateWeightTotal() == false);

           _graded = true;

       }

       private bool ValidateWeightTotal()

       {

           int precisionFactor = 0.001f;

           float _totalWeight = 0;

           bool result = false;

           for (int i = 0; i < _grades.Length; ++i)

           {

               _totalWeight += _grades[i].Weight;

           }

           if(_totalWeight < 100 + precisionFactor && _totalWeight > 100 - precisionFactor)

           {

               result = true;

           }

           if (result == false)

           {

               Console.WriteLine$"Weight total = {_totalWeight} instead of 100. Please enter the values again. ");

           }

           return result;

       }

       public float GetFinalGrade()

       {

           bool weightsAreValid = ValidateWeightTotal();

           float finalGrade = 0;

           if(weightsAreValid)

           {

               for (int i = 0; i < _grades.Length; ++i)

               {

                   finalGrade += _grades[i].GetPercentOfFinalGrade();

               }

           }

           return finalGrade;

       }

       public void DisplayGrades()

       {

           if (_graded)

           {

               float total = 0f;

               Console.WriteLine("-------------------------------------");

               Console.WriteLine($"Title: {Title}");

               for (int i = 0; i < _grades.Length; ++i)

               {

                   Grade grade = _grades[i];

                   //total += grade.GetPercentOfFinalGrade();

                   Console.WriteLine($"Desc: {grade.Description} Earned: {grade.PercentEarned} Percent towards final grade: {grade.GetPercentOfFinalGrade()} ");

               }

               

               Console.WriteLine($"Grade for the course: {total}");

               Console.WriteLine("-------------------------------------");

           }

           else

           {

               Console.WriteLine("Please add grades first.");

           }

       }

   }

}


Explanation / Answer

C# code error finder

The error description is shown in the form of a:b where a is the line # in the class where error is observed

Student Class
================
(67:23) Unexpected character '$'
(261:38) Unexpected character '$'
(449:30) Unexpected character '$'
(73:15) A get or set accessor expected
(71:9) } expected
(453:5) } expected


GradeCalculator class
=======================
(139:28) Syntax error, ':' expected
(283:65) ; expected


Grade class
===============
(13:1) A namespace cannot directly contain members such as fields or methods
(65:12) A get or set accessor expected
(91:8) Invalid token '{' in class, struct, or interface member declaration
(95:12) Invalid token '{' in class, struct, or interface member declaration
(97:30) Invalid token ';' in class, struct, or interface member declaration
(101:12) A namespace cannot directly contain members such as fields or methods
(125:8) Type or namespace definition, or end-of-file expected

Course class
================
(119:34) Unexpected character '$'
(132:34) Unexpected character '$'
(154:34) Unexpected character '$'
(218:33) Unexpected character '$'
(274:34) Unexpected character '$'
(284:38) Unexpected character '$'
(290:34) Unexpected character '$'