0% found this document useful (0 votes)
5 views

Lab 1

Uploaded by

busharshaqoor922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab 1

Uploaded by

busharshaqoor922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Visual Programming using Java Lab

Lab No. 1

Object Oriented Programming Design

Lab Subjects:

Java Example, which contains:


 Some of Object Oriented Features:
A. Classes and Objects.
B. Attributes and Methods.
C. Inheritance.

 Some of the JOptionPane class's methods and constants:


A. The showInputDialog Method.
B. The showMessageDialog Method.
C. The JOptionPane Constants: ERROR_MESSAGE,
INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE,
PLAIN_MESSAGE.
Using the NetBeans IDE, create the following four classes (Shape, Circle,
Rectangle, mainClass):

 Shape class:
public class Shape
{
protected String Color;

public Shape(String C)
{ Color = C; }
}

 Rectangle class:
public class Rectangle extends Shape
{
private double Height ;
private double Width;

public Rectangle(String C, double H, double W)


{
super(C);
Height = H;
Width = W;
}
public double Area ( )
{ return Height * Width; }
public String getColor ( )
{ return Color; }

}
 mainClass class:

import javax.swing.JOptionPane;

public class mainClass


{
public static void main( String args[] )
{
String C;
String StringH, StringW;
double H, W;

C = JOptionPane.showInputDialog ("Enter Color:");


StringH = JOptionPane.showInputDialog ("Enter Height:");
StringW = JOptionPane.showInputDialog ("Enter Width:");

H = Double.parseDouble(StringH);
W = Double.parseDouble(StringW);

Rectangle Rect = new Rectangle (C,H,W);

JOptionPane.showMessageDialog (null, "Color = " + Rect.getColor(),


"Rectangle", JOptionPane.INFORMATION_MESSAGE );
JOptionPane.showMessageDialog (null, "Area = " + Rect.Area(),
"Rectangle", JOptionPane.INFORMATION_MESSAGE );
}
}
Output:

You might also like