Java Tutorial
In java programming, this program is used to calculate the area of the plot by getting plot length and breadth as user inputs.
Defines a class 'Area' which has length and breadth instance variables and calculates area using instance method.
import java.util.Scanner; class Area { float length; float breadth; public Area(float length, float breadth){ this.length = length; this.breadth = breadth; } // calculates the area using length and breadth. public float calculateArea(){ return this.length*this.breadth; } } public class PlotArea { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("Compuets Plot Area"); System.out.println("-------------------"); System.out.print("Enter Plot Length: "); float len = sc.nextFloat(); System.out.print("Enter Plot Breadth: "); float bre = sc.nextFloat(); Area area = new Area(len, bre); float plotArea = area.calculateArea(); System.out.println("Plot Area: "+plotArea); } }Output:
D:\Java_Programs>javac PlotArea.java D:\Java_Programs>java PlotArea Compuets Plot Area ------------------- Enter Plot Length: 60 Enter Plot Breadth: 24 Plot Area: 1440.0
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page