In: Computer Science
please debug this code by fixing all the mistakes.
thank you.
// Creates a HomeworkAssignment class
// instantiates two objects
// and prompts the user for infromation about two courses
using System;
public class DebugSeven1
{
public static void Main()
{
HomeworkAssignment
course1;
HomeworkAssignment
course2;
string
entryString;
int exercises;
// Get info for first
class
Console.Write("What
class do you have homework for? ");
entryString =
Console.ReadLine(); // Fixed .ReadLine
course1.ClassName =
entryString;
Console.Write("How many
exercises must you complete? ");
entryString =
Console.ReadLine(); // ReadLine
exercises =
Convert.ToInt32(entryString); // ToInt32
course1.numberOfExercises() = exercises;
// Get info for
another class
Console.Write("What
class do you have homework for? ");
entryString =
Console.ReadLine();
course1.ClassName =
entryString; // entryString
Console.Write("How many
exercises must you complete? ");
entryString =
Console.ReadLine(); // ReadLine
exercises =
Convert.ToInt32(entryString); // ToInt32
course1.NumberOfExercises = exercises;
Console.WriteLine("You have {0} minutes of homework for {1}",
course1.TimeToComplete, course1.ClassName);
Console.WriteLine("and
{0} more minutes for {1}",
course2.TimeToComplete, course2.ClassName);
}
}
class HomeworkAssignment
{
private string className;
private int numberOfExercises; // change to
int
private int timeToComplete;
// 10 minutes to complete each exercise
private const int TIME_PER_EXERCISE = 10;
public string ClassName
{
get
{
return ClassName;
}
set
{
className = value;
}
}
public int NumberOfExercises
{
get
{
return numberOfExercises;
}
set
{
NumberOfExercises = numberOfExercises;
CalcCompletionTime();
}
}
public double TimeToComplete
{
get
{
return TimeToComplete; // TimeToComplete
}
}
private void CalcCompletionTime()
{
timeToComplete =
numberOfExercises + TIME_PER_EXERCISE;
}
}
// Creates a HomeworkAssignment class
// instantiates two objects
// and prompts the user for infromation about two courses
using System;
public class DebugSeven1
{
public static void Main()
{
//before setting values to Class objects you have to
//create object using below.
HomeworkAssignment course1 = new HomeworkAssignment();
HomeworkAssignment course2 = new HomeworkAssignment();
string entryString;
int exercises;
// Get info for first class
Console.Write("What class do you have homework for? ");
entryString = Console.ReadLine(); // Fixed .ReadLine
course1.ClassName = entryString;
Console.Write("How many exercises must you complete? ");
entryString = Console.ReadLine(); // ReadLine
exercises = Convert.ToInt32(entryString); // ToInt32
//numberOfExercies() is not defined you have to
//use NumberOfExercises
course1.NumberOfExercises = exercises;
// Get info for another class
Console.Write("What class do you have homework for? ");
entryString = Console.ReadLine();
course2.ClassName = entryString; // entryString
Console.Write("How many exercises must you complete? ");
entryString = Console.ReadLine(); // ReadLine
exercises = Convert.ToInt32(entryString); // ToInt32
course2.NumberOfExercises = exercises;
Console.WriteLine("You have {0} minutes of homework for
{1}",
course1.TimeToComplete, course1.ClassName);
Console.WriteLine("and {0} more minutes for {1}",
course2.TimeToComplete, course2.ClassName);
}
}
public class HomeworkAssignment
{
private string className;
private int numberOfExercises; // change to int
private int timeToComplete;
// 10 minutes to complete each exercise
private const int TIME_PER_EXERCISE = 10;
//Constructor
public HomeworkAssignment()
{
className = "";
numberOfExercises = 0;
timeToComplete = 0;
}
//setters and getters.
public string ClassName
{
get
{
return this.className;
}
set
{
this.className = value;
}
}
public int NumberOfExercises
{
get
{
return this.numberOfExercises;
}
set
{
this.numberOfExercises = value;
CalcCompletionTime();
}
}
public int TimeToComplete
{
get
{
return this.timeToComplete;
}
}
private void CalcCompletionTime()
{
this.timeToComplete = this.numberOfExercises *
TIME_PER_EXERCISE;
}
}