Question

In: Computer Science

C# Language Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and...

C# Language

  • Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and negativeValue. These should be declared as public and you should not use automatic properties to declare them.
  • Your class should have a constructor that takes one integer argument. In the constructor you will code if statements to set one of the three class variables (indicators) to 1 if the number sent to the constructor is either equal to zero, negative, or positive.
  • In the class provide a method printit() used to print the results
    • Evaluate the positive, negative, and zero indicator to determine which line to print. If the indicator is set to 1 then the indicator is true.
    • You will print one of three statements;
      • The number was zero.
      • The number was positive.
      • The number was negative.
  • In the default wrapper class named assignment3 and containing Main write the code in Main that declares one integer variable: val1.
  • Use Console Write and Readline and the convert method to take the integer entry from the keyboard and pass it to the evaluateValue constructor.
  • Instantiate an evaluateValue object and pass the integer values to the constructor.
  • From Main call the printit method which will print the resulting evaluation in the class object.

Solutions

Expert Solution

C# CODE: (assignment.cs)

using System;
using System.Collections.Generic;

namespace Assignment3
{
    class evaluateValue
    {
      
       //public variable indicators for positive,negative,zero value
        public int zeroValue;
        public int positiveValue;
        public int negativeValue;

       // constructor ,based on the value of val ,setting the indicators
        public evaluateValue(int val)
        {
           // setting positiveValue indicator
           if(val > 0)
           {
               positiveValue = 1;
           }
          
           // setting negativeValue indicator
           if (val < 0)
           {
               negativeValue = 1;
           }
          
           // setting zeroValue indicator
           if (val == 0)
           {
               zeroValue = 1;
           }


        }
      
       // printing the results
        public void printit()
        {
          
           if(zeroValue == 1)
           {
               Console.WriteLine("The number was zero.");
           }
          
           if(positiveValue == 1)
           {
               Console.WriteLine("The number was positive.");
           }
          
           if(negativeValue == 1)
           {
               Console.WriteLine("The number was negative.");
           }


        }
    }
  
    class assignment3
    {
        public static void Main(string[] args)
        {
            //declare the local val1 variable
            int val1;

            //prompt the user for input of one integer
             Console.Write( " Enter an integer value: ");
             val1 = Convert.ToInt32(Console.ReadLine() );

            //instantiate a evaluateValue object here
            // and pass val1 to the constructor
            evaluateValue ob = new evaluateValue(val1);


            //call the object method printit here
            ob.printit();

        }
    }
}

SCREENSHOT FOR OUTPUT:


Related Solutions

Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and negativeValue. These...
Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and negativeValue. These should be declared as public and you should not use automatic properties to declare them. Your class should have a constructor that takes one integer argument. In the constructor you will code if statements to set one of the three class variables (indicators) to 1 if the number sent to the constructor is either equal to zero, negative, or positive. In the class provide...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class this class should contain the following private data types: - name (string) - id number (string) - email (s) - phone number (string) - number of courses (int) - a dynamic array of course objects. the user will specify how many courses are there in the array. the following are public members of the student class: - default constructor (in this constructor, prompt the...
Generic types A class or interface that declares one or more generic variables is called a...
Generic types A class or interface that declares one or more generic variables is called a generic type. In this portion of the activity, you will make a class generic. Open GenericsC.java in jGRASP then compile it. At this point you should be familiar with the two type-safety warnings given by the compiler. You should be able to understand the source of the error: the use of the raw types List and Collection. Since the List being declared (al) is...
C# programming Create a class called A with private integer field x, protected integer field y,...
C# programming Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1? Create a method...
C# programming Create a class called A with private integer field x, protected integer field y,...
C# programming Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1? Create a method...
Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”
Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list.[B] Edit your class Cycle by...
C++ Memory Management: - Create a class called DynamicArray that allocates an integer array of user...
C++ Memory Management: - Create a class called DynamicArray that allocates an integer array of user defined size on the heap - Don't not use any of the STL containers (vector, list, etc) - Create the necessary constructors and destructor, code should allocate the array using new. - Write a method print_array that prints the array’s length and the contents of the array. - Create at least 2 DynamicArray objects and print their contents. Include your DynamicArray class below along...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the...
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the secret word char * secretWord; char *guessedWord; public: //please create related constructors, getters, setters,constructor() constructor() You will need to initialize all member variables including the two dynamic variables. destructor() Please deallocate/freeup(delete) the two dynamic arrays memories. guessALetter(char letter) 1.the function will check if the letter guessed is included in the word. 2. display the guessed word with related field(s) filled if the letter guessed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT