Question

Csharp. C# Create a method that accepts 3 parameters length width & height but if any...

Csharp. C#

Create a method that accepts 3 parameters length width & height but if any of the three are not passed to the method default values are assigned. Invoke the method passing it 1, 2, 3 and no parameters. To show that it can handle each option.

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

using System;
public class Test
{
public static void Main()
{
    Console.WriteLine("Enter length,width and height :");
    int length = Convert.ToInt32(Console.ReadLine());
    int width = Convert.ToInt32(Console.ReadLine());
    int height = Convert.ToInt32(Console.ReadLine());
      
    Console.WriteLine("volume = "+method(length,width,height)); // sending inputted parameters
Console.WriteLine("volume = "+method(1)); // sending one parameter
Console.WriteLine("volume = "+method(1,2));// sending two parameters
Console.WriteLine("volume = "+method(1,2,3));// sending three parameters
  
}
public static int method(int length=1,int width=2,int height=3)// default parameters
{
return length*width*height;
}
}

Output:

Enter length,width and height :
4
5
6
volume = 120
volume = 6
volume = 6
volume = 6

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
Csharp. C# Create a method that accepts 3 parameters length width & height but if any...
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
  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • 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...

  • FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width,...

    FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...

  • 4. Write a static method named ConcatStrings that is passed any number of parameters of   type...

    4. Write a static method named ConcatStrings that is passed any number of parameters of   type String, and returns a single string that is the concatenation of the strings passed.   (4 pts.)   5. Write a static method named ConcatObjects that is passed any number of parameters of   type Object, and returns a single string that is the concatenation of the result of the call to   toString() for each of the objects. (4 pts.)   6. Write a class named Triplet that...

  • Create 3 user-defined methods called add(). 1 accepts a single integer array parameter; this method should...

    Create 3 user-defined methods called add(). 1 accepts a single integer array parameter; this method should loop the array adding the values and return the summation (use 4, 1, 4, 6, 10, 15, 32, 79, 18 as the values in the array) 1 accepts 2 integer parameters; this method should add them and return the value 1 accepts 3 integer parameters; this method should add them all and return the value In main, define the parameters above (you may use...

  • Create the class Rectangle. The class will have two int properties, length and width. Create the...

    Create the class Rectangle. The class will have two int properties, length and width. Create the method printFigure. The method will print a character representation of the rectangle, using an asterisk, *, for each length/width position of the rectangle. Think of the length of the rectangle as the number of rows and the width as the number of columns. Use nested loops to create your solution. If the length was 5 and the width 8, then the printed figure would...

  • This is code for c++. Any help would be great. #include <iostream> using namespace std; /*...

    This is code for c++. Any help would be great. #include <iostream> using namespace std; /* 1. Create a method that prints your name */ /* 2. Create an overloaded method that takes an integer and prints it out multiplied * by itself * Print out the argument inside the method and then call the method from main * and print it out * What was the typed of passing used inhere ? */ /* 3. Create an overloaded method...

  • This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets...

    This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...

  • 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...

  • (3) Methods That Return a Value (10 points) Write a method dominant that accepts three integers...

    (3) Methods That Return a Value (10 points) Write a method dominant that accepts three integers as parameters and returns true if any one of the three integers is larger than the sum of the other two integers. The integers might be passed in any order, so the largest value could be any of the three. If no value is larger than the sum of the other two, your method should return false. For example, the call of dominant (4,...

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