Question

In: Computer Science

Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to...

Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to populate the username in the program after entered. I can enter a name and the three scores and average them as the program needs but the name is not adding next to the "Students name: " in the program. Any help would be appreciated and please place a note for what I am doing wrong. Thank you

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoprBox08
{
class CollegeStudent
{

public static void Main(string[] args)
{
Console.Title = ("College Student ");
Console.WriteLine("Please enter your name: \nand the three scores: ");

  

string name = Console.ReadLine();
int midTerm1 = int.Parse(Console.ReadLine());
int midTerm2 = int.Parse(Console.ReadLine());
int finalExam = int.Parse(Console.ReadLine());
CollegeStudent s = new CollegeStudent(name, midTerm1, midTerm2, finalExam); //Invoking the constructor

Console.WriteLine(s); //invokes ToString()
Console.ReadKey();
}
public override string ToString()
{
string str;
str = string.Format(" Student name: {0} \nSemester grade: {1}", StudentName, SemesterGrade());
Console.WriteLine();
return str;
}
private string studentName;
private int midTerm1;
private int midTerm2;
private int finalExam;

public string StudenName
{
get { return studentName; }
set { studentName = value; }
}
public int MidTerm1
{
get { return midTerm1; }
set { midTerm1 = value; }
}
public int MidTerm2
{
get { return midTerm2; }
set { midTerm1 = value; }
}
public int FinalExam
{
get { return finalExam; }
set { finalExam = value; }
}

public object StudentName { get; private set; }

public CollegeStudent(string studentName, int midTerm1, int midTerm2, int finalExam)
{
this.studentName = studentName;
this.midTerm1 = midTerm1;
this.midTerm2 = midTerm2;
this.finalExam = finalExam;
}
public double SemesterGrade()
{
double grade;
grade = 0.3 * MidTerm1 + 0.3 * MidTerm2 + 0.4 * FinalExam;
return grade;
}

}
}

Solutions

Expert Solution

There was a spell mistake in the property StudentName. Below is the incorrect and correct property name.

Incorrect

public string StudenName
{
get { return studentName; }
set { studentName = value; }
}

Correct

public string StudentName   
{
get { return studentName; }
set { studentName = value; }
}

Also there is aaditional public object StudentName { get; private set; } ----This line is not required once you fix the above mentioned problem. You can comment the this line.

Below is the corrected code. Added comments wherever required

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoprBox08
{
    class CollegeStudent
    {

        public static void Main(string[] args)
        {
            Console.Title = ("College Student ");
            Console.WriteLine("Please enter your name: \nand the three scores: ");



            string name = Console.ReadLine();
            int midTerm1 = int.Parse(Console.ReadLine());
            int midTerm2 = int.Parse(Console.ReadLine());
            int finalExam = int.Parse(Console.ReadLine());
            CollegeStudent s = new CollegeStudent(name, midTerm1, midTerm2, finalExam); //Invoking the constructor

            Console.WriteLine(s); //invokes ToString()
            Console.ReadKey();
        }
        public override string ToString()
        {
            string str;
            str = string.Format(" Student name: {0} \nSemester grade: {1}", StudentName, SemesterGrade());
            Console.WriteLine();
            return str;
        }
        private string studentName;
        private int midTerm1;
        private int midTerm2;
        private int finalExam;

        //This lin is problem. Spelling mistake - StudenName. It shoould be StudentName
        public string StudentName       
        {
            get { return studentName; }
            set { studentName = value; }
        }
        public int MidTerm1
        {
            get { return midTerm1; }
            set { midTerm1 = value; }
        }
        public int MidTerm2
        {
            get { return midTerm2; }
            set { midTerm1 = value; }
        }
        public int FinalExam
        {
            get { return finalExam; }
            set { finalExam = value; }
        }

        //This line of code should not be there. We have corrected the above property where Spelling mistake - StudenName. It shoould be StudentName
        //Commenting below line resolved the issue. Now Name is showing in the result
        //public object StudentName { get; private set; }   

        public CollegeStudent(string studentName, int midTerm1, int midTerm2, int finalExam)
        {
            this.studentName = studentName;
            this.midTerm1 = midTerm1;
            this.midTerm2 = midTerm2;
            this.finalExam = finalExam;
        }
        public double SemesterGrade()
        {
            double grade;
            grade = 0.3 * MidTerm1 + 0.3 * MidTerm2 + 0.4 * FinalExam;
            return grade;
        }

    }
}

After correcting code as mentioned above. Below is the screenshot of output


Related Solutions

I am trying to create a makefile for the following program in Unix. The C++ program...
I am trying to create a makefile for the following program in Unix. The C++ program I am trying to run is presented here. I was wondering if you could help me create a makefile for the following C++ file in Unix and show screenshots of the process? I am doing this all in blue on putty and not in Ubuntu, so i don't have the luxury of viewing the files on my computer, or I don't know how to...
Best Forecasting Model Hi, I am trying to find the best suitable model for my project...
Best Forecasting Model Hi, I am trying to find the best suitable model for my project that I should use for forecasting the values. Following are the models that I used and their respected values. Model RMSE MAE MAPE Holt's 201.616 130.072 2.054 Holt's (Log Transform) 197.723 125.330 1.971 Damped Trent .    206.040 128.525 2.028
Hi I am having the following problem. At the moment I am trying to create a...
Hi I am having the following problem. At the moment I am trying to create a bode plot for the following function. G(s)=(Ks+3)/((s+2)(s+3)) Note: Not K(s+2)! I then want to plot multiple bode plots for various values of K. Eg. 1,2,3, etc. I am having two separate issues. 1. How do I define the TF with a constant K in the location required (a multiple of s in the numerator) 2. How do I create multiple bode plots for values...
y'=y-x^2 ; y(1)= -4 My MATLAB program won't work. I am trying to get the main...
y'=y-x^2 ; y(1)= -4 My MATLAB program won't work. I am trying to get the main program to output a plot of the three equations (1 from the main program and two called in the function). The goal is to code a Euler method and a 2nd order Taylor numerical solution for a. x0= 1.0 , step size h= 0.2, # of steps n=20 b. x0= 1.0 , step size h=0.05 , # of steps n=80 ; write a separate...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with MSTest. My program is below. I just need screen shots of the unit test code in Visual Studio 2019 with MSTest. Please and thank you. so easentially I need someone to write some unit tests with my program in MSTest visual studio 2019. Then I need the unit tests supplied as answers. using System; namespace SelectionSortAlgorithm { public class SelectionSort { public static void...
Hello, I am trying to write a C++ program that will do the following: Use the...
Hello, I am trying to write a C++ program that will do the following: Use the STL stack container in a program that reads a string, an arithmetic expression to be exact, one character at a time, and determines if the string has balanced parenthesis – that is, for each left parenthesis there is exactly one matching right parenthesis later in the string.                         Use the following strings to test your program. A+ B - C A * B / (C...
Whenever I am attempting to write a simple program on C++ I get an error message...
Whenever I am attempting to write a simple program on C++ I get an error message that reads "cout was not declared in this scope". Literally every time. This has become frustrating because I have even written my code the exact same way as some of my classmates who got theirs to compile and run with no sign of this error at all, and yet min gives this answer. I will leave an example of a code where this error...
Hi I am working on my chemistry homework about acids and bases and I am confused...
Hi I am working on my chemistry homework about acids and bases and I am confused on this question from a lab. We used grape juice and cranberry juice and we had to put HCl and NaOH in the test tube full of juice. 1. Referring back to procedure 1 of the experiment, which of the two juices is more useful as a general pH indicator and why? I think it is grape juice but I just don't know what...
In trying to apply my knowledge in the real world, I am trying to create a...
In trying to apply my knowledge in the real world, I am trying to create a realistic retirement schedule. However, I am running into difficulties using both a financial calculator as well as our equations from class in doing this. I am trying to do the following: plan a retirement schedule between the ages of 25 and 70, in which I would deposit 20% of my income each year. The income starts at 80,000 with an annual growth rate of...
1. I am trying to determine the level of measurement of my data type? I am...
1. I am trying to determine the level of measurement of my data type? I am looking for advice on Nominal, Ordinal, Interval, and Ratio 2. Does the data set have any categorical variables? I am trying to Describe the data set below in very general terms? This data consist of 8 variables: Which are GRE Scores, TOEFL Scores, University Rating, Statement of Purpose, Letter of Recommendation Strength, Undergraduate GPA, . Research Experience, and Chance of Admit. Name Type Description...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT