100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CodeHS Unit 4 || QUESTIONS WITH 100% VERIFIED ANSWERS!!

Rating
-
Sold
-
Pages
26
Grade
A+
Uploaded on
19-05-2025
Written in
2024/2025

4.1.6 Using the Rectangle Class correct answers RectangleT: public class RectangleTester extends ConsoleProgram { public void run() { // Create a rectangle with width 5 and height 12 Rectangle room = new Rectangle(5,12); // Then print it out Sln(room); } } R: public class Rectangle { private int width; private int height; public Rectangle(int rectWidth, int rectHeight) { width = rectWidth; height = rectHeight; } public int getArea() { return width * height; } public int getHeight() { return height; } public int getWidth() { return width; } public String toString() { return "Rectangle with width: " + width + " and height: " + height; } } 4.1.7 Calling A Method correct answers RectangleT:

Show more Read less
Institution
CodeHS
Course
CodeHS










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CodeHS
Course
CodeHS

Document information

Uploaded on
May 19, 2025
Number of pages
26
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CodeHS Unit 4 || QUESTIONS WITH 100% VERIFIED
ANSWERS!!
4.1.6 Using the Rectangle Class correct answers RectangleTester.java:
public class RectangleTester extends ConsoleProgram
{
public void run()
{
// Create a rectangle with width 5 and height 12
Rectangle room = new Rectangle(5,12);
// Then print it out
System.out.println(room);
}
}

Rectangle.java:
public class Rectangle
{
private int width;
private int height;

public Rectangle(int rectWidth, int rectHeight)
{
width = rectWidth;
height = rectHeight;
}

public int getArea()
{
return width * height;
}

public int getHeight()
{
return height;
}

public int getWidth()
{
return width;
}

public String toString()
{
return "Rectangle with width: " + width + " and height: " + height;
}
}

4.1.7 Calling A Method correct answers RectangleTester.java:

,public class RectangleTester extends ConsoleProgram
{
public void run()
{
/*
* Rectangle is the name of the class. Every Rectangle
* has a width and a height. But the specific instances
* have their own dimensions.
*/
Rectangle r1 = new Rectangle(7, 14);
System.out.println(r1.getHeight());
System.out.println(r1.getWidth());
System.out.println(r1.getArea());
}
}

Rectangle.java:
public class Rectangle
{
private int width;
private int height;

public Rectangle(int rectWidth, int rectHeight)
{
width = rectWidth;
height = rectHeight;
}

public int getArea()
{
return width * height;
}

public int getHeight()
{
return height;
}

public int getWidth()
{
return width;
}

public String toString()
{
return "Rectangle with width: " + width + " and height: " + height;
}
}

4.1.8 Using the Point Class correct answers PointTester.java:

, public class PointTester extends ConsoleProgram
{
public void run()
{
Point p = new Point(10, 5);
System.out.println(p);
p.move(3, 4);

System.out.println(p);

// Make a new point here at position (2, 4)
Point a = new Point(2, 4);

// Then print it out
System.out.println(a);
}
}

Point.java:
public class Point
{
private int x;
private int y;

public Point(int xCoord, int yCoord)
{
x = xCoord;
y = yCoord;
}

public void move(int dx, int dy)
{
x += dx;
y += dy;
}

public String toString()
{
return x + ", " + y;
}
}

4.1.9 Using the Student Class correct answers StudentTester.java:
public class StudentTester extends ConsoleProgram
{
public void run()
{
Student alan = new Student("Alan", "Turing", 11);
Student ada = new Student("Ada", "Lovelace", 12);
Student luke = new Student("Luke", "Drelick", 12);

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ProPerfomer (self)
View profile
Follow You need to be logged in order to follow users or courses
Sold
431
Member since
2 year
Number of followers
322
Documents
8502
Last sold
1 week ago
Global Scholars’ Resource Hub

Welcome to your ultimate exam success hub! We provide top-quality, up-to-date, and approved exam materials—study guides, practice tests, and notes for a variety of subjects. Whether you’re preparing for school, college, or professional exams, our resources are designed to help you study smarter and score higher. Thousands have passed with our materials—now it’s your turn!Need more resources or something specific? Contact me anytime, and I’ll be happy to help you find exactly what you need. Your success is our mission!" ✅ Covers multiple subjects and exam types ✅ Includes real practice questions, answers, and study tips ✅ Ideal for students, test takers, and last-minute review Your Exam Success Starts Here – Grab Your Bundle Before It’s Gone!

Read more Read less
3.9

83 reviews

5
36
4
25
3
9
2
1
1
12

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions