Java program Thank you Define and test a method called printRectangleArea that t
ID: 3776960 • Letter: J
Question
Java program Thank you
Define and test a method called printRectangleArea that takes two parameters that are the length and width of a rectangle (area=length*width). The method calculates and prints the area of the rectangle. For example the method call printRectangleArea(10.0, 3.0) prints Area: 30.0 Test this method by calling it from the main method. Include the code and 2 test cases. public class Exercise7 {public static void main(String[] arg) {Scanner keyboard = new Scanner(System.in); SYJSteJIUeut.BlUn tin ("Please type the length: "); double length = keyboard.nextDouble(); System.out.println ("Please type the width: ") ? double width = keyboard.nextDouble(); printRectangleArea(length, width);}//Define method here.}Explanation / Answer
Exercise7.java
import java.util.Scanner;
public class Exercise7 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Please type the length: ");
double length = keyboard.nextDouble();
System.out.print("Please type the width: ");
double width = keyboard.nextDouble();
printRectangleArea(length, width);
}
public static void printRectangleArea(double length, double width){
double area = length * width;
System.out.println("Area: "+area);
}
}
Output:
Please type the length: 10
Please type the width: 3
Area: 30.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.