• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need some quick java help

importdistributors

Senior member
I made this code, but I cant get it to work, any ideas what I need to do?
Is the organization and order wrong?


package rmesye2_hw3;
public class rmesye2_hw3 {

public class rectangle{
double length;
double height;
String color;

//constructor of a default rectangle
rectangle(){
width = 1;
height = 1;
color = "white";
}

//constructor to create a new rectangle of specified height and width
rectangle(double newwidth, double newheight){
width = newwidth;
height = newheight;
color = "white";
}

//method to mutate color
void setcolor(String c){
color = c;
}

//method to mutate height
void setheight(double h){
height = h;
}

//method to mutate width
void setwidth(double w){
width = w;
}

//method that returns area
double getArea(){
return width * height;
}

//method that returns perimeter
double getPerimeter(){
return (2*width) + (2*height);
}
}


public static void main(String[] args) {
rectangle r1 = new rectangle(4, 40);
rectangle r2 = new rectangle(3.5, 35.9);

r1.setcolor(red);
r2.setcolor(red);

system.out.println("Rectangle 1 is " + r1.width +" wide, and " + r1.height + " high.");
system.out.println("Rectangle 1 area: " + r1.getArea);
system.out.println("Rectangle 1 perimeter: " + r1.getperimeter);
system.tou.println(" ");
system.out.println ("Rectangle 2 is " + r2.width +" wide, and " + r2.height + " high.");
system.out.println("Rectangle 2 area: " + r2.getArea);
system.out.println("Rectangle 2 perimeter: " + r2.getperimeter);
}
 
I sent you a PM - your objects and class names need to be capitalized - also your method calls that have no arguments need to have () at the end.
 
Back
Top