Question: import java.util.Scanner; class Area { private double length; private double breadth; // Method to set dimensions void setDim(double length, double breadth) { this.length = length;

import java.util.Scanner; class Area { private double length; private double breadth; // Method to set dimensions void setDim(double length, double breadth) { this.length = length; this.breadth = breadth; } // Method to get area double getArea() { return length * breadth; } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Create the Area object Area rectangle = new Area(); // Input for length and breadth System.out.print("Enter length of rectangle: "); double length = scanner.nextDouble(); System.out.print("Enter breadth of rectangle: "); double breadth = scanner.nextDouble(); // Set dimensions and get area rectangle.setDim(length, breadth); double area = rectangle.getArea(); // Print area System.out.println("Area of the rectangle: " + area); // Remember to close the scanner scanner.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!