1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alex41 [277]
3 years ago
12

For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet).

Computers and Technology
1 answer:
dusya [7]3 years ago
8 0

Answer:

The solution code is written in Python:

  1. class Carpet:
  2.    def __init__(self, rect, cost):
  3.        self.size = rect  
  4.        self.costPerSqFoot = cost  
  5.    
  6.    def cost(self):
  7.        carpetCost = self.size.area() * self.costPerSqFoot  
  8.        return carpetCost

Explanation:

Presume that there is existence of Rectangle class as given in the question, Carpet class is written. The Carpet constructor is defined that take Rectangle object,<em> rect</em>, and <em>cost</em> as parameter (Line 2). To create data member of Carpet class, keyword "self" is used to precede with the name of the data members, <em>size </em>and <em>costPerSqFoot </em>(Line 3-4).<em> </em>The data members are initialized with the parameter <em>rect </em>and <em>cost</em>, respectively.

Next, cost method is defined (Line6 - 8). Within the <em>cost </em>method, the area method of Rectangle object is invoked by expression, <em>self.size.area() </em>and<em> </em>this will return the area value and multiplied with the costPerSqFoot to get the carpet cost and return it as output (Line 8).

You might be interested in
There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in in
Dafna1 [17]

Answer:

import java.util.Scanner;

public class InchConversion

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter inches: ");

 double inches = input.nextDouble();

 

 inchesToFeet(inches);

 inchesToYards(inches);

}

public static void inchesToFeet(double inches){

    double feet = inches / 12;

    System.out.println(inches + " inches = " + feet + " feet");

}

public static void inchesToYards(double inches){

    double yards = inches / 36;

    System.out.println(inches + " inches = " + yards + " yards");

}

}

Explanation:

In the inchesToFeet() method that takes one parameter, inches:

Convert the inches to feet using the conversion rate, divide inches by 12

Print the feet

In the inchesToYards() method that takes one parameter, inches:

Convert the inches to yards using the conversion rate, divide inches by 36

Print the yards

In the main:

Ask the user to enter the inches

Call the inchesToFeet() and inchesToYards() methods passing the inches as parameter for each method

7 0
2 years ago
What happens when a filter is applied to a database
IgorLugansk [536]
<span>(A) All records that don't meet the criteria are removed
</span>
6 0
3 years ago
Su now wants to modify the text box that contains her numbered list. She accesses the Format Shape pane. In what ways can Su mod
Fiesta28 [93]
I believe its E she can insert a picture in the text book
7 0
3 years ago
Read 2 more answers
How do I turn of the noise canceling feature on my beats studio wireless?
zysi [14]
You press and hold the "b" button on your left earmuff, but you have to hold it down as long as you want ANC (Automatic Noise Cancelling) to be turned off, in other words, as soon as you release the button, ANC will be turned back on. Unfortunately, this will also mute your music. 
5 0
3 years ago
Petra has an interview with an IT company. What technique can help prepare her?
SVEN [57.7K]
I would go C because that way it gets her prepared to answer any techie questions they would have for her and would make her a better option.
3 0
2 years ago
Read 2 more answers
Other questions:
  • List and the deference between MS access objects​
    8·1 answer
  • Which question best addresses the issue of risk with a new job?
    7·2 answers
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    5·1 answer
  • You will be given a string, containing both uppercase and lowercase alphabets(numbers are not allowed).
    14·1 answer
  • Find the volume of the rectangular prism.<br>1<br>6 cm<br>32<br>cm​
    14·1 answer
  • Siapa mahapatih brainly.com atau yg disebut Brainly Amerika Serikat ?​
    5·1 answer
  • Write steps to Delete data from ‘Datagridview’
    6·1 answer
  • Identify the hardware components in your own computer. If you don't have a computer, use a friend's, or one at work or in an NVC
    5·1 answer
  • Win10如何删除自己添加的环境变量?...............
    8·1 answer
  • What is Data rate?<br> What is BAUD RATE?<br> What is bandwidth?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!