Question

I need help in this please, in the c# language. Objects As Parameters The goal for...

I need help in this please, in the c# language.

Objects As Parameters

The goal for this exercise is to define the Television object, which you will be using in several, subsequent exercises.

For all the methods that you implement (in this course (not just this exercise, but in this course, as you go forwards)), you should remember that since method is public, anyone, anywhere can call the method. Even people whom you never thought would call this method. Therefore, you need to make sure that all the parameters to this method are ‘safe’ before using them. In particular, you need to check that the any object references are valid, and not equal to the special null value. If any object reference parameters are null, you can simply return early.

What you need to do for this exercise:

  1. Implement the Television class. Each Television has a brand name (a string), a price (use decimal), and a size (measured diagonally in inches). Give the class a constructor, and getter/setter methods for each of the three data attributes.
    1. Note that price is actually a decimal, not a double, value.
    2. When a Television object is created using the default (‘no-argument’) constructor, the price and size should be zero, and the brand should be the empty string (“”), NOT the value null.
    3. Remember to validate the input to the setter methods. If you’re given a negative value for price or size, reject the new value and keep the current value, instead. Similarly, if the SetBrand method is given a null value, it should reject this null value and keep the current value, instead.
    4. You also need to implement a Print method, which should print out a message in the following format:
      Brand:Sony
      Price:1000.17
      Size:10.5
    5. The class definition is already partially provided for you in the starter solution.
  2. In preparation for future exercises, you should make sure that you can create a Television object, give it some values, and then pass that object to the method. A great place to put this code is the RunExercise method of the Television_Definition class.

Other than implementing this class so that it works with future exercises, there are no particular requirements for this exercise. The only reason this might be listed as "Hand-In" is to make it clear that you need to do this work.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

solution

//output

//copyable code

using System;

class Television

{

private string brand_Name;

private decimal televison_price;

private double televison_size;

//set/get brand name

public string televisonBrandName

{

get { return brand_Name; }

set

{

if (value != null)

{

brand_Name = value;

}

}

}

//set/get televison_price

public decimal Price

{

get { return televison_price; }

set

{

if (value >= 0)

{

televison_price = value;

}

}

}

//set/get televison_size

public double Size

{

get { return televison_size; }

set

{

if (value >= 0)

{

televison_size = value;

}

}

}

//default constructor

public Television()

{

brand_Name = "";

televison_price = 0;

televison_size = 0;

}

public Television(string brand,decimal pri,double siz)

            {

            brand_Name=brand;

            televison_price=pri;

            televison_size=siz;

            }

//display()

public void display()

{

Console.WriteLine($" Brand Name :{brand_Name} {Environment.NewLine} Price : {televison_price} {Environment.NewLine} Size : {televison_size}");

}

static void Main()

{

//creating object

Television television1 = new Television();

//user to enter brand name

Console.WriteLine("Enter the television Brand Name:");

//reading brand

television1.brand_Name = Console.ReadLine();

//enter televison_price

Console.WriteLine("Enter the televison price : ");

//reading televison_price

television1.televison_price = decimal.Parse(Console.ReadLine());

//enter televison_size

Console.WriteLine("Enter Size of television : ");

television1.televison_size = double.Parse(Console.ReadLine());

//calling display()

television1.display();

Console.ReadKey();

}

}

Add a comment
Know the answer?
Add Answer to:
I need help in this please, in the c# language. Objects As Parameters The goal for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help me with this in C# language. Constructors The goal for this exercise is to...

    please help me with this in C# language. Constructors The goal for this exercise is to understand what constructors are, how to define them, and how to call them, including ‘default’ constructors, and including the use of overloading to provide multiple constructors. One of the advantages of having a clear separation between the public interface of an object and private internal implementation of an object is that once you've got the data in the object you can then ask the...

  • Please help me with this in C# language. Returning an array from a function The goal...

    Please help me with this in C# language. Returning an array from a function The goal for this exercise is to make sure that you return an array from a method (as a return value). Also: to give you more practice creating and using methods/functions. What you need to do for this exercise: In the starter project, add code to the Returning_An_Array class, so that the RunExercise method does the following: Declare an integer array variable, but DO NOT ALLOCATE...

  • I Need Help with this using Java Programming : Class name fname lname Class variable total...

    I Need Help with this using Java Programming : Class name fname lname Class variable total Number Constructor (no arguments) Constructor (takes two arguments, fname and lname) One getter method to return the fname and lname One setter method for fname and lname Inside Main: Create three objects with the following names Jill Doe John James Jack Smith When creating the first object (Should not be an anonymous object) use the argument-less constructor Then use the setter method to assign...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • i was able to make sense on the others but this two i need help Name:...

    i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue                            Access modifier: public Parameters:...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • I need to implement a stack array but the top of the stack has to be...

    I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array.    //Array implementation of stacks.    import java.util.Arrays;       public class ArrayStack implements Stack {        //Declare a class constant called DEFAULT_STACK_SIZE with the value 10.           private static final int DEFAULT_STACK_SIZE = 10;           /* Declare two instance variables:            1. An integer called...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length,...

    WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT