In: Computer Science
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int lenth=getInput("Enter
length",sc);
int width=getInput("Enter
width",sc);
int
area=getArea(lenth,width);
displayArea(area);
}
//prints the area
private static void displayArea(int aArea) {
System.out.println("Area :
"+aArea);
}
//calcualtes the area
private static int getArea(int aLenth, int aWidth)
{
return aLenth * aWidth;
}
// read input and return
private static int getInput(String aString, Scanner
sc) {
System.out.println(aString);
return sc.nextInt();
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me