class square 
{private int length;
 private int width;
 
 public square(int l, int w)
 {
  length = l;
  width = w;
 }
 
 public int getArea()
 {return length * width;
 }
 
 public int getPerimeter()
 {return (length+width)*2;
 }
}
_________________________________________
class cube extends square
{private int height;
 
 public cube(int h)
 {super(h,h);
  height = h;
 }
 
 public int getArea()
 {return super.getArea()* 6;
 }

 public int getVolume()
 {
	 return (super.getArea()* height);
 }
}
_____________________________________________
import java.awt.*;        // Container, FlowLayout
import java.awt.event.*;  // ActionEvent, ActionListener
import javax.swing.*;     // JApplet, JButton, JLabel, JTextField

public class cubemain extends JFrame implements ActionListener {

   int answer = 0;
   int right  = 0;
   int wrong = 0;
   int product;
   // graphical user interface components
   JLabel lengthLabel ,areaLabel,surfaceLabel,heightLabel;
   JTextField lengthField, areaField, surfaceField,heightField;
  
  JButton playAgain;

   // set up GUI components
   public cubemain()
   {
	  super("Cube Program");   // window title
    
     GridLayout grid1 = new GridLayout( 4, 1 );  // 8 rows 1 column

	 // get content pane and set its layout
 Container container = getContentPane();
 container.setLayout( grid1 );

      // create label and text field for number 1
      lengthLabel = new JLabel( "Length" );
      container.add( lengthLabel );
      lengthField = new JTextField( 20 );
      lengthField.setEditable( true );
      lengthField.addActionListener(this);
      container.add( lengthField );
      

      // create label and text field for number 2
      areaLabel = new JLabel( "Area is" );
      container.add( areaLabel );
      areaField = new JTextField( 20 );
      areaField.setEditable( false );
      container.add( areaField );

      // create label and text field for sum
      surfaceLabel = new JLabel( "Surface is" );
      container.add( surfaceLabel );
      surfaceField = new JTextField( 20 );
      surfaceField.setEditable( true );
      surfaceField.addActionListener(this);
      container.add( surfaceField );

      // create button user clicks to play again
      playAgain = new JButton( "Play Again" );
      playAgain.addActionListener( this );
      container.add(playAgain);

   } // end method init

   private int toInt(String s)
   {int n = 0;
    for (int x=0; x