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...
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...
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...
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.
In C++ language implement an end of the world simulation. Create 3 global variables earthquake =...
In C++ language implement an end of the world simulation. Create 3 global variables earthquake = 30%, hurricane = 35%, volcano = 35% Implement a class named World. Class World inherited Class CRandom In class World create three methods Earthquakes, Hurricanes and Volcanoes. These methods return death toll in numbers and percentage up to their global percentage. This percentage is calculated using CRandom.
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has...
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has data member called height which initialized to 3 by the constructor of the class. It has also the following function members: Void setHeight() to read, and set the height. Void getHeight() to print the value of height. void leftBottom_RTraingle(), prints shape a void leftTop_RTraingle(), prints shape b. void RightTop_RTraingle(), prints shape c. void RigtBottom_RTraingle(), prints shape d. The functions from 3 to 6 have...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object: ● Implicit constructor (default constructor) ● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle: Area = pi * (r * r) Your...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. NOTE: You are not allowed to use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT