Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import javax.swing.*; import java.text.*; public class Rectangle { private int l

ID: 3910813 • Letter: I

Question

import javax.swing.*;
import java.text.*;

public class Rectangle

{
   private int length;
   private width;
   private area;
   private perimeter;
  
  
   //constructor
   public Rectangle ()
   {
      
      
   }
   //overload the constructor
   public Rectangle (int l, int w)
   {
       setlength(1);
       setwidth(w);
   }

   //accessor methods
   public int getlength ()
   {
       return (length);
   }
   public int getwidth ()
   {
       return (width);
   }
      
   public int getperimeter (int w, int l)
   {
       int perimeter = ((12*width)+(2*length));
       return perimeter;
   }
   public int getarea(int w, int l)
   {
       int area = length * width;
       return area;
          
   }
      
   public void setlength(int l)
   {
       length = l;
   }
      
   public void setwidth (int w)
   {
       width = w;
   }
   public String toString()
   {
       return "Rectangle with length" +length + " and width " + width;
   }
}

      

import javax.swing.*;



public class Assignment
{
   public static void main( String[] args )
   {
       int length = 0;
       int width = 0;
       int input = 0;
       int perimeter = 0;
       int area = 0;


       //declaring a Rectangle object
       Rectangle rect; //rectangle object
      
       final int SENTINEL = -99;
      
       //initialize the object
       rect = new Rectangle();
      
      
  
       while ( input != SENTINEL )
       {
          input = Integer.parseInt( JOptionPane.showInputDialog("Please enter one of the following:" + " "
                                   + "1 - to set the length" + " "
                                   + "2 - to set the width" + " "
                                   + "3 - to get the length" + " "
                                   + "4 - to get the width" + " "
                                   + "5 - to get the perimeter" + " "
                                   + "6 - to get the area" + " "
                                   + "7 - to print the object as string" + " "
                                   + "0 - to quit " ) );
           switch (input)
           {  

               case 1: length = Integer.parseInt(JOptionPane.showInputDialog("Please enter the length of the Rectangles: "));
                           rect.setlength(length);
                       break;
               case 2: width = Integer.parseInt(JOptionPane.showInputDialog("Please enter the width of the Rectangle : "));
                           rect.setwidth(width);
                       break;
               case 3: JOptionPane.showMessageDialog(null, "Length: " + rect.getlength());
                       break;
               case 4: JOptionPane.showMessageDialog(null, "Width: " + rect.getwidth());
                       break;
               case 5: JOptionPane.showMessageDialog(null, "Perimeter: " + rect.getperimeter(length, width));
                       break;
               case 6: JOptionPane.showMessageDialog(null, "Area: " + rect.getarea(length,width));
                       break;
                      
               case 7: JOptionPane.showMessageDialog(null, rect);
                        break;
               case 0:
                       break;
           }

       }
   System.exit(0);

   }
}

java assignment(after compiling it, i get this error message).

java:19: error: cannot find symbol
                Rectangle rect; //rectangle object
                ^
symbol:   class Rectangle
location: class Assignment
Assignment java:24: error: cannot find symbol
                rect = new Rectangle();
                           ^
symbol:   class Rectangle
location: class Assignment

Explanation / Answer

import javax.swing.*; import java.text.*; public class Rectangle { private int length; private int width; private int area; private int perimeter; //constructor public Rectangle () { } //overload the constructor public Rectangle (int l, int w) { setlength(1); setwidth(w); } //accessor methods public int getlength () { return (length); } public int getwidth () { return (width); } public int getperimeter (int w, int l) { int perimeter = ((12*width)+(2*length)); return perimeter; } public int getarea(int w, int l) { int area = length * width; return area; } public void setlength(int l) { length = l; } public void setwidth (int w) { width = w; } public String toString() { return "Rectangle with length" +length + " and width " + width; } } import javax.swing.*; public class Assignment { public static void main( String[] args ) { int length = 0; int width = 0; int input = 0; int perimeter = 0; int area = 0; //declaring a Rectangle object Rectangle rect; //rectangle object final int SENTINEL = -99; //initialize the object rect = new Rectangle(); while ( input != SENTINEL ) { input = Integer.parseInt( JOptionPane.showInputDialog("Please enter one of the following:" + " " + "1 - to set the length" + " " + "2 - to set the width" + " " + "3 - to get the length" + " " + "4 - to get the width" + " " + "5 - to get the perimeter" + " " + "6 - to get the area" + " " + "7 - to print the object as string" + " " + "0 - to quit " ) ); switch (input) { case 1: length = Integer.parseInt(JOptionPane.showInputDialog("Please enter the length of the Rectangles: ")); rect.setlength(length); break; case 2: width = Integer.parseInt(JOptionPane.showInputDialog("Please enter the width of the Rectangle : ")); rect.setwidth(width); break; case 3: JOptionPane.showMessageDialog(null, "Length: " + rect.getlength()); break; case 4: JOptionPane.showMessageDialog(null, "Width: " + rect.getwidth()); break; case 5: JOptionPane.showMessageDialog(null, "Perimeter: " + rect.getperimeter(length, width)); break; case 6: JOptionPane.showMessageDialog(null, "Area: " + rect.getarea(length,width)); break; case 7: JOptionPane.showMessageDialog(null, rect); break; case 0: break; } } System.exit(0); } }