Homework 2

2A

Write a program that constructs two rectangles: one with area 42 and a second with perimeter 42. Print the widths and heights of both rectangles then print the rectangles by calling by calling System.out.println(box) - assuming box is the name of a Rectangle. Call the program Homework2A. Make the x,y coordinates (0,0)

Get the width and the height from the rectangles using methods. You will get no credit if you simply say: System.out.println(6);

For the draft, construct any rectangle and print it using System.out.println(box).

2A draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010622184791876166342262521
2A final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010622184791876166342262521&level=2

2B

Write a program HolleTester that switches the letters "e" and "o" in the String word. Use the replace method repeatedly. Demonstrate that the string "Hello, World!" turns into "Holle, Werld!"

For the draft, declare the String word so the program compiles. And print the string

2B draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010618015172823362856334217
2B final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010618015172823362856334217&level=2

 

2C

The intersection method computes the intersection of two rectangles—that is, the rectangle that would be formed by two overlapping rectangles if they were drawn, as shown at below.

intersection


You call this method as follows:

     Rectangle r3 = r1.intersection(r2);

Write a program called IntersectionTester. Then do the following

For the draft, construct the first rectangle and print it.

2C draft: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010713432951307741447129324
2C final: http://cs12.cs.sjsu.edu:8080/netbrat/files?repo=ext&problem=13010713432951307741447129324&level=2