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);
}
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);
}