Question

In: Computer Science

Create a class called Dishwash with a double called CubicFeet, a string called color, and a...

Create a class called Dishwash with a double called CubicFeet, a string called color, and a method called Washing. The Washing method should return a string to the main class with the text "Now washing dishes!" In the main class create an array of DishWasher size 3. Give each DishWasher a different color and CubicFeet. Use a foreach loop to display that info, call the Washing method, and display the text returned from the Washing method call.


c#

Solutions

Expert Solution

I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).

Images of the Code:
Note: If the below code is missing indentation please refer code Images

Typed Code:

// using System
using System;

// Creating a class named Dishwash
class Dishwash
{
// a public variable named CubicFeet
public double CubicFeet;
// a public string variable named color
public string color;
// A constructor
public Dishwash(double Feets, string color_name)
{
// initializing the values CubicFeet and color
CubicFeet=Feets;
color = color_name;
}
// a public method Washing
public string Washing()
{
// returning the text washing
return "Now washing dishes!";
}
}

// Main class
class main {
// main method
static void Main() {
// creating an array of DishWasher size 3
Dishwash[] dishes = new Dishwash[3];
// initializing the object dishes
dishes[0]=new Dishwash(4,"Red");
// initializing the object dishes
dishes[1]=new Dishwash(5,"White");
// initializing the object dishes
dishes[2]=new Dishwash(3.5,"Green");
  
// A for loop to display the info
for(int i=0;i<3;i++)
{
// printing Size of Dish
Console.WriteLine("Dish Size : " + dishes[i].CubicFeet + " CubicFeet ");
// printing Color of Dish
Console.WriteLine("Dish Color : " + dishes[i].color);
// calling the method Washing and printing the returned text
Console.WriteLine(dishes[i].Washing() + "\n");
}
}
}
//code ended here

Output:


If You Have Any Doubts. Please Ask Using Comments.

Have A Great Day!


Related Solutions

Create a class called Sphere. The class will contain the following    Instance data double radius...
Create a class called Sphere. The class will contain the following    Instance data double radius Methods Constructor with one parameter which will be used to set the radius instance data Getter and Setter for radius             Area - calculate the area of the sphere (4 * PI * radius * radius)             Volume - calculate and return the volume of the sphere (4/3 * PIE * radius * radius * radius) toString - returns a string with the...
Create a class, called Song. Song will have the following fields:  artist (a string) ...
Create a class, called Song. Song will have the following fields:  artist (a string)  title (a string)  duration (an integer, recorded in seconds)  collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration....
Create a class tuck shop with following data members: String Owner String Food_Items[100] Double Price [100]...
Create a class tuck shop with following data members: String Owner String Food_Items[100] Double Price [100] Int Quantity [100]                Note: All arrays are open ended. It is not necessary that they are completely filled. All three arrays will work in synchronization with each other i-e the item at index 0 will have its price in Price array at index 0 and quantity at index 0 of Quantity array. Methods: Two Constructors (default, four-argument) set for Owner , get for...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance);...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance); const string & getName() const; double getDistance() const; void setDistance(double); // Passes in the departure time (as minute) and returns arrival time (as minute) // For example: // 8 am will be passed in as 480 minutes (8 * 60) // 2:30 pm will be passed in as 870 minutes (14.5 * 60) virtual unsigned computeArrivalTime(unsigned minute) const = 0; }; #endif Derived Classes...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate,...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also...
(JAVA) 1.) Create a class called Rabbit that with 2 attributes: 1) speed and 2) color....
(JAVA) 1.) Create a class called Rabbit that with 2 attributes: 1) speed and 2) color. Then, create a constructor that has no parameters, setting the default speed to 0 and the color to “white”; this is called a default constructor. Next, create a second constructor that takes in two parameters. The second constructor should assign those parameters to the attributes. Then, in main, create two Rabbit objects. For the first Rabbit object, call the first constructor. For the second...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should have a public instance method, getBMI() that returns a double reflecting the person's BMI (Body Mass Index = weight (kg) / height2 (m2) ). The class should have a public toString() method that returns a String like Fred is 1.9m tall and is 87.0Kg and has a BMI of 24.099722991689752Kg/m^2 (just print the doubles without special formatting). Implement this class (if you wish you...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT