I’m using Dr. Java and the language is java …i’m a beginner
* just a basic rectangle
Problem:
Create a program that constructs a Rectangle object (java.awt.Rectangle). The object should have a getWidth(5) and a getHeight(8)
compute and System.out.println() the area of the Rectangle object. Then compute the perimeter and print it as well.
what i have so far
//finding the area
int Width = 5;
int Height = 8;
Rectangle bob = new Rectangle(0,0,5,8);
double area = bob.getWidth()*bob.getHeight();
System.out.println("area = " + area);
// Find the perimeter
double perimeter = 2*(bob.getHeight()) + 2*(bob.getWidth());
System.out.println("get the perimeter = " + perimeter);`
You are on the right track, but you need to read up a little on how
System.out.println(...)works.While you do have a variable named
area, you do not reference it in yourprintlnstatement. What you have in yourprintlnstatement is one string that happens to have two continuous series of characters that spell “area”, but neither one is a reference to the variable name.Is quite different. There is one string,
"area = "and a concatenation operator which joins the string to the variablearea(which will be automatically converted to aStringtype. It is a fine point of “moving” the terminating quotation mark of the string, but the meaning is quite different.one string, with a few funny characters
one string, a concatenation operator, and a second name which will be “converted” to a string.