SC142 Final Exam for 70 Points Name: Absolutely NO talking, books, notes, comput
ID: 3903611 • Letter: S
Question
SC142 Final Exam for 70 Points Name: Absolutely NO talking, books, notes, computers, and cell phones. Create a class for an object called Rectangle, with and a String fields of units. [12 pts] a) Write the class header and declare the fields s. two private integer fields, length, width, b) Write a constructor, which takes in the length, width, and units as parameters Write an accessor tostring which returns a String representation the rectangle's dimensions in the form L X Wunits, e.g. 10 X 5 feet. c) d) Write a mutator called toscale(factor) which accepts an integer parameter and replaces the length with the product factor " length and the width with product factor width e) Write an accessor findArea which returns the rectangle's area as a String, including units. For example, A 10 X 5-feet Rectangle would return the String "50 square feet" Page 5 ofExplanation / Answer
a) write a class header and declare the fields:
public class Rectangle(){
int length;
int width;
String units ;
}
//===========================================================================//
b) write a constructor which takes in length, width and units as parameters:
public class Rectangle(){
int width;
int length;
String units;
// constructor
Rectangle(String units, int length , int width){
this.units= units
this.length=length;
this.width= width;
}
//main class
public static void main (String args[]){
// do stuff
}
}
//===========================================================================//
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.