logo

Object Oriented Programming using Java

   

Added on  2023-04-10

14 Pages585 Words389 Views
 | 
 | 
 | 
Running head: OBJECT ORIENTED PROGRAMMING USING JAVA
Object oriented Programming using java
Name of the Student
Name of the University
Authors note
Object Oriented Programming using Java_1

1ORIENTED PROGRAMMING USING JAVA
Answer 1
package src;
import java.util.Scanner;
public class Rectangle {
//static //static width;
static double length;
static double width;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
Object Oriented Programming using Java_2

2ORIENTED PROGRAMMING USING JAVA
return width;
}
public void setWidth(double width) {
this.width = width;
}
//double dle;
public static void calcareaperim(double l,double w)
{
double area=l*w;
double perim=2*(l+w);
System.out.println(" The Perimeter of the Rectangle is "+perim);
System.out.println("The Area of the rectangle is " +area);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle r=new Rectangle();
Object Oriented Programming using Java_3

3ORIENTED PROGRAMMING USING JAVA
//double length=1;
//double width=1;
//double dle;
Scanner scn=new Scanner(System.in);
System.out.println("Enter the Length of the Rectangle");
double Len=(scn.nextDouble());
System.out.println("Enter the width of the
Rectangle");
double wid=scn.nextDouble();
r.setLength(Len);
r.setWidth(wid);
{
calcareaperim(Len, wid);
}
}
Object Oriented Programming using Java_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents