Question

In: Computer Science

please debug this code by fixing all the mistakes. thank you. // Creates a HomeworkAssignment class...

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;
    }
}

Solutions

Expert Solution

// 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;
}
}


Related Solutions

please debug this by fixing all the mistakes in C# // Creates a BoatLicense class //...
please debug this by fixing all the mistakes in C# // Creates a BoatLicense class // And instantiates three BoatLicense objects // The price of a licence is $25 if the boat motor is 50 HP or under // and $38 if the HP is over 50 // Boat licenses are issued with numbers starting with 200801 using System; public class DebugSeven4 {    public static void Main()    {       const int STARTINGNUM = 200801;       BoatLicense[] license =...
please debug this by fixing all the mistakes in C#: // Creates a Breakfast class //...
please debug this by fixing all the mistakes in C#: // Creates a Breakfast class // and instantiates an object // Displays Breakfast special information using System; public class DebugSeven2 {    Breakfast special = new Breakfast("French toast", 4.99);    //Display the info about breakfast    Console.WriteLine(Breakfast.info);    // then display today's special    Console.WriteLine("Today we are having {0} for {1}",       special.Name, special.Price.ToString("C2")); } class Breakfast {    // info is class field    public static string info =...
Into to PythonInstructions: • In this lab you are to debug the code found at...
Into to PythonInstructions: • In this lab you are to debug the code found at the end of these instructions: Find and correct all problems found in the code. Create comments in the code explaining what you found and how you corrected it • The purpose of this program is to calculate car insurance rates using the following rules: The base rate of insurance is $50 a month, Males pay a 25% premium over the base rate, Drivers in Michigan...
In C++ Please comment in all-new lines of code, thank you DO NOT USE ANSWERS THAT...
In C++ Please comment in all-new lines of code, thank you DO NOT USE ANSWERS THAT ALREADY BEEN POSTED, please use code from the assignment Copy-paste will be reported Write a program to compare those two searching algorithms and also compare two sorting algorithms. You need to modify those codes in the book/slides to have some counters to count the number of comparisons and number of swaps. In the main function, you should have an ordered array of 120 integers...
I am given this starter code and I am suppose to debug it and all of...
I am given this starter code and I am suppose to debug it and all of that and it will not work after I change ">" to "<=" and then i'm not sure after that what else I have to do. Could someone help me solve this? // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 {    public static void main(String args[])    {      ...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T,...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T, size> extends Throwable { private final T[] S = null ; public StackException(String s) { } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); int top = 0; return S[top]; } private boolean isEmpty() { return false; } public T pop() throws StackException { T item; if (isEmpty()) throw new StackException("Stack underflow."); int top = 0; item = S[top];...
You cna hand write this if you want, Please code this in C Thank you PROBLEM...
You cna hand write this if you want, Please code this in C Thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output...
Please debug the code and answer the questions: #include <stdio.h> typedef struct node { int value;...
Please debug the code and answer the questions: #include <stdio.h> typedef struct node { int value; struct node *next; } node; int ll_has_cycle(node *first) { node * head = first; while (head->next) { head = head->next; if (head == first) return 1; } return 0; } void test_ll_has_cycle(void) { int i,j; node nodes[5]; for(i=0; i < sizeof(nodes)/sizeof(node); i++) { nodes[i].next = NULL; nodes[i].value = i; } nodes[0].next = &nodes[1]; nodes[1].next = &nodes[2]; nodes[2].next = &nodes[1]; printf("Checking first list for cycles....
Can you please show both in RStudio code? Thank You Airports: The temperature is recorded at...
Can you please show both in RStudio code? Thank You Airports: The temperature is recorded at 60 airports in a region. The average temperature is 68 degrees Fahrenheit with a standard deviation of 5 degrees. The last known average temperature from all airports is 67 degrees Fahrenheit.   Is the recorded temperature at the 60 airports different from the average temperature at all airports? Answer by determining statistical significance using the test statistic, degrees of freedom, and p-value. Answer substantive significance...
Thank you all. my other code is working fine. It was my IDE issue. This is...
Thank you all. my other code is working fine. It was my IDE issue. This is the new code i am writing for the below question. please help as you always do: a=int(input('Input a: ')); b=int(input('Input b: ')); c=int(input('Input c: ')); r=int(input('Input r: ')); s=int(input('Input s: ')); t=int(input('Input t: ')); x=2; min_rst = min(r,s,t); while(1): if((x-a)%r==0): if((x-b)%s==0): if((x-c)%t==0): break; x=x+1; print('The required number is: ',x); Questions: Write a Python program called crt.py that finds the value of x that satisfies...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT