Question

In: Computer Science

Starting Out with Java (6th Edition) chapter 8, 3PC Requirement: Each of the RoomCarpet and RoomDimension...

Starting Out with Java (6th Edition)

chapter 8, 3PC

Requirement: Each of the RoomCarpet and RoomDimension classes should have a toString method, an equals method, a copy method, and a copy constructor. The RoomCarpet class should have mutators and accessors for both of its fields.

Solutions

Expert Solution

The Code is:

import java.text.DecimalFormat;
public class Carpet {
private Dimension rmSize;
private pricesqft;
//constructor
public Carpet()
{
this.rmSize = new Dimension();
this.pricePerSqFt = 0.00;
}
public Carpet(Dimension rmSize, pricesqft)
{
this.rmSize = new Dimension(rmSize.getRmLength(),rmSize.getRmWidth());
this.pricePerSqFt = pricePerSqFt;
}
public Dimension getRmSize()
{
return new Dimension(rmSize.getRmLength(),rmSize.getRmWidth());
}
public double getPricePerSqFt()
{
return this.pricePerSqFt;
}
  
public void setRmSize(Dimension rmSize)
{
this.rmSize = new Dimension(rmSize.getRmLength(), rmSize.getRmWidth());
}
public void setPricePerSqFt(pricesqft)
{
this.pricePerSqFt = pricePerSqFt;
}
public double rmTotalCost()
{
return rmSize.getAreaRoom() * pricePerSqFt;   
}

public String toString()
{
DecimalFormat dollar = new DecimalFormat("$#,##0.00");
String str = this.rmSize.toString() + " Price per sq. ft : " +dollar.format(pricePerSqFt) + " Price to carpet Room: " + dollar.format(rmTotalCost()) + '\n';
return str;
}

public boolean equals(Carpet object2)
{
boolean status;
if ((this.equals(object2)==true)&&(this.pricePerSqFt==object2.pricePerSqFt))
status = true;
else
status = false;
return status;
}


}


Related Solutions

java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a boolean method that uses recursion to determine whether a string argument is a palindrome. the method should return true if the argument reads the same forward amd backword. Demonstrate the method in a program, use comments in the code for better understanding. there must be a demo class and method class also .. generate javadocs through eclipse compiler. And make a UML diagram with...
Chapter 6, Starting out with Programming and Logic, 4th Edition, Page 265 #6 Kinetic Energy In...
Chapter 6, Starting out with Programming and Logic, 4th Edition, Page 265 #6 Kinetic Energy In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy: KE=12mv2 The variables in the formula are as follows: KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity, in meters per second. Design a function named kineticEnergy that accepts...
Starting out with Python 4th edition Chapter 2 Programming Exercise 12 Stock Transaction Program Not sure...
Starting out with Python 4th edition Chapter 2 Programming Exercise 12 Stock Transaction Program Not sure how to do this
Database Systems: A Practical Approach to Design, Implementation, and Management, 6th Edition, Chapter 11 Database Analysis...
Database Systems: A Practical Approach to Design, Implementation, and Management, 6th Edition, Chapter 11 Database Analysis and the DreamHome Case Study. Based on Dreamhome Case Study; Title suitable for the project based on the case study? The problem statement ? Objectives? Boundary(scope)? User views? ExtraFeatures?
Text: Health Economics: Theory, Insights, and Industry Studies (6th Edition) ( chapter 13) Current activity in...
Text: Health Economics: Theory, Insights, and Industry Studies (6th Edition) ( chapter 13) Current activity in the hospital industry shows that hospitals are consolidating to form multihospital systems. Based on your reading in the text, what do empirical studies indicate concerning cost savings of multihospital systems over single hospital systems? Why are multihospital systems expected to be cost saving? Why would we continue to see multihospital systems forming even if cost savings are not as evident as expected?
According to chapter 3 Daniels, Radebaugh, Sullivan international business environment and operations 6th edition book, what...
According to chapter 3 Daniels, Radebaugh, Sullivan international business environment and operations 6th edition book, what are the political and legal environment in the Ukraine country. should write down references with page numbers from chapter 3 of suggest book, where you collect information for it?
According to chapter 3, Daniels, Radebaugh,Sullivan International business environments and operations 6th edition book, What is...
According to chapter 3, Daniels, Radebaugh,Sullivan International business environments and operations 6th edition book, What is the political and legal environment of Ukraine country? what are social and economic conditons of Ukraine country and it's income , level of corruption? write reference with page number of book where you collect information for it?. pdf file of that book is already available in this chegg application. if again you need pdf , please let me know. i ll send you. but...
Morrison-Valfre: Foundations of Mental Health Care, 6th Edition Chapter 31: Schizophrenia and Other Psychoses Study Guide...
Morrison-Valfre: Foundations of Mental Health Care, 6th Edition Chapter 31: Schizophrenia and Other Psychoses Study Guide Student Name             Date ________________________ Fill-In-The-Blank Identify the terms that most closely describe the behaviors characterized in the following statements: 1. __________________ Disorders marked by a loss of contact with reality 2. __________________ Lack of energy or motivation 3. __________________ Abnormal involuntary movement disorders caused by a drug-induced imbalance between two major neurotransmitters in the brain 4. __________________ False sensory inputs with no external stimulus...
Horngren financial and managerial accounting 6th edition Chapter 12, question 37 P12AB-37A Brad Nelson Inc. issued...
Horngren financial and managerial accounting 6th edition Chapter 12, question 37 P12AB-37A Brad Nelson Inc. issued $600,000 of 7% six year bonds payable on January 1, 2018. The market interest rate at date of issuance was 6% and the bonds pay interest semiannually. a. How much cash did the company receive upon issuance of bonds payable. b. Prepare amortization table for the bond using the effective interest method, through the first two interest payments. c. journalize the issuance of the...
Employee Benefits, 6th edition, Martocchio Chapter 3, Caso 2 2. Managing Employee Benefits: A Discriminatory Time-Off...
Employee Benefits, 6th edition, Martocchio Chapter 3, Caso 2 2. Managing Employee Benefits: A Discriminatory Time-Off Policy As Karen Jarrod looked over her notes from the human resources (HR) compliance audit that she conducted at her new company, she decided she needed to take a closer look at the company’s time-off policies. Karen joined Staffon Consulting three months ago as the Director of Human Resources for the 1,500-employee company. Her first project in her new role was to review all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT