Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:31:26+00:00 2026-06-01T22:31:26+00:00

I need to add a private reference to a Unit object _Unit . Attached

  • 0

I need to add a private reference to a Unit object _Unit. Attached is both classes (Unit and Result).

I understand I need to have the code below, however it results in errors (listed below):

// 14. create new class
class Result : Unit

and the below creates the error that base() requires two constructors:

// 17. Create constructor for the class
public Result(string grade, Unit _Unit) : base(_Unit)

In my unit class there are two private strings _Code and _Name. Please ask if you need any other class codes put in or the assignment question.

namespace SIT232_Assignment1
{
  // 14. create new class
  class Result
  {
    // 15. Add a private reference to a Unit objectand a private string attributes.
    private string _Grade, _Unit;

    // 16. Encapsulate the above attributes with public read-only properties
    public string Grade
    {
        get { return _Grade; }            
    }

    // 17. Create constructor for the class
    public Result(string grade, Unit _Unit) 
    {            
        _Grade = grade;            
    }

    // 18. create a public read-only property of type bool
    public bool Passed (string grade)
    {
        bool result = true;
        if (_Grade == "N")
            result = false;
        return result;
    }

    // 19. Create a public static methods 
    public static bool ValidateGrade(string grade)
    {
        bool result = false;
        if (_Grade == "N" || _Grade == "P" || _Grade == "C" || _Grade == "D" || _Grade =="HD")
            result = true;
        return result;            
    }

    // 20. Define a ToString method
    public override string ToString()
    {
        return String.Format("{0}\t{1}", _Grade);
    }
}

namespace SIT232_Assignment1
{
  // 8. Create new class
  class Unit
  {
    // 9. Add private string attributes for the unit code and unit name
    private string _Code, _Name;

    // 10. Encapsulate the above attributes with public read-only properties.
    public string Code
    {
        get { return _Code; }            
    }                
    public string Name
    {
        get { return _Name; }            
    }     

    // 11. Create constructor with two string parameters
    public Unit( string code, string name)
    {
        _Code = code;
        _Name = name;
    }

    // 27. create a private list<>
    private List<Student> _EnrolledStudents = new List<Student>();

    // 28. Encapsulate the above list with read-only
    public ReadOnlyCollection<Student> EnrolledStudents
    {
        get { return _EnrolledStudents.AsReadOnly(); }
    }

    // 29. Create a method that accecpts a single parameter
    public void RecordEnrollment(Student student)
    {
        _EnrolledStudents.Add(student);
    }

    // 30. Create a method that accecpts a single parameter
    public void RemoveEnrollment(Student student)
    {
        _EnrolledStudents.Remove(student);
    }

    // 12. Define a ToString method
    public override string ToString()
    {
        return String.Format("{0} {1}", _Code, _Name);
    }
}

Furthermore, one other error I’m getting that I simply cannot full understand is the below method HAS to be static, I’ve researched that also making the attributes and properties of _Grade static solves the error showing on each individual _Grade, however it still shows on the first one?

if (_Grade == "N" || _Grade == "P" || _Grade == "C" || _Grade == "D" || _Grade =="HD")

public static bool ValidateGrade(string grade)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:31:27+00:00Added an answer on June 1, 2026 at 10:31 pm

    For your first question:

    Your class Result inherites from Unit and your constructor of Result calls the one of the base class. However, in Unit there is only one constructor defined needing two arguments (code and name), so your call to base at the Result constructor needs to have two parameters.

    But you probably don’t want to inherit from Unit but add a private reference to it. There you would have something like

    class Result {
    
      private Unit _Unit;
    
      ...
    
      public Result(..., Unit _Unit)
      {
          this._Unit = _Unit;
          ...
      }
    }
    

    Your second error: A static method can only access static fields and properties, so from a static method you can’t access your instance variables. You just want to verify that the supplied grade is in your range, so just dont refer to the instance variable_Grade`:

    public static bool ValidateGrade(string grade)
    {
      return (grade == "N" || grade == "P" ...)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add and delete class on an element having multiple classes: This
Additional information: Object reference not set to an instance of an object. I have
I need add a new user group for mediawiki. The new group has more
need to add a 2nd css stylesheet to a page. do i add a
I need to add an invite users functionality to my social networking application so
I need to add CRRedist2008_x86.msi to my deployment project as it is a requirement
I need to add css height to each page dynamically with jQuery. So far
I need to add a new column to a MS SQL 2005 database with
I need to add values received from MySQL into an array (PHP). Here is
I need to add a dependency on a specific version of GDIPlus. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.