Related questions
In Java
Design and implement a
- Method isValid(...) returns true if the sum of the width and height is greater than 30
boolean isValid(double width, double height){}
- Method area(...) returns the area of the rectangle if it is a valid rectangle
double area(double width, double height){}
- Method perimeter(...) returns the perimeter of the rectangle if it is a valid rectangle
double perimeter(double width, double height){}
Always remember that in Java and C#, the methods must be public and static
The main method should prompt the user to enter the width and height of a rectangle ( double values )
and uses the methods to print out a message followed by the area and perimeter if the rectangle is
valid. Otherwise, it prints out only the message " This is an invalid rectangle ."
Note: that method isValid(...)is used to validate the input before attempting to compute the area
and perimeter.
Design the main method in the test program such that it allows the user to re-run the program
with different inputs (using a sentinel loop structure).
In Java
Remember, the class name should be Lab10B.
The user input is indicated in bold.
Sample output:
Enter width: 4.0
Enter height: 5.0
This is an invalid rectangle
Do you want to enter another width and height (Y/N)? : Y
Enter width: 20.0
Enter height: 15.0
This is a valid rectangle
The area is: 300.0
The perimeter is: 70.0
Do you want to enter another width and height (Y/N)? : N
Program Ends
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Define a method maxNumber() to complete the following program. MethodmaxNumber() is to find the largest of the three numbersarrow_forwardTASK 4. Intro to methods. Review Methods, Implement the following code, make sure it runs without errors. 3 import java.util.Scanner; 4 5 public class ReportSum4 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); 60 7 8 // Prompt the user to enter the first integer System.out.println("Enter the value for 'a' and press Enter: "); int a = sc.nextInt(); // Prompt the user to enter the second integer System.out.println("Enter the value for 'b' and press Enter: "); int b = sc.nextInt(); 10 11 12 13 14 15 // Display the result System.out.printf( "Provided Integers: %4d and %4d, the total is %5d\n", a, b, sum(a, b)); } 16 17 18 19 public static int sum(int num1, int num2){ return num1 + num2; 200 21 } 23 } 22 Our client just contacted us and said that he's planning from time to time provide us three integers instead of two. They still expect us to produce a report with totals (sums of their 2 or 3 integers)arrow_forwardWhy I’m getting this error please tell me don’t fix the error only tell mearrow_forward
- Run out like the expected’s picturearrow_forwardType the program's output import java.util.Scanner; public class NumberSearch { public static void findNumber(int number, int lowVal, int highVal, String indentAmt) { int midVal; midVal = (highVal + lowVal) / 2; System.out.print(indentAmt); System.out.print(midVal); if (number == midVal) { System.out.println(" a"); } else { if (number < midVal) { System.out.println(" b"); findNumber(number, lowVal, midVal, indentAmt + " "); } else { System.out.println(" c"); findNumber(number, midVal + 1, highVal, indentAmt + " "); } } System.out.println(indentAmt + "d"); } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int number; number = scnr.nextInt(); findNumber(number, 0, 8, ""); } } Input 5arrow_forwardCorrect Code for Java: Enter an integer>> 11 Enter another integer>> 23 The sum is 34 The difference is -12 The product is 253 import java.util.Scanner; public class DebugTwo2 { public static void main(String args[]) { int a, b; Scanner input = new Scanner(System.in); System.out.print("Enter an integer>> "); a = nextInt (); System.out.print("Enter b = nextInt (); System.out.println("The System.out.println("The System.out.println("The } } another integer>> "); sum is " + (a + b)); difference is " + (a - b)); product is + (a*b));arrow_forward
- Need some help with this java problemarrow_forwardExplain it properlyarrow_forwardimport java.util.Scanner;/** This program calculates the geometric and harmonic progression for a number entered by the user.*/public class Progression{ public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println("This program will calculate " + "the geometric and harmonic " + "progression for the number " + "you enter."); System.out.print("Enter an integer that is " + "greater than or equal to 1: "); int input = keyboard.nextInt(); // Match the method calls with the methods you write int geomAnswer = geometricRecursive(input); double harmAnswer = harmonicRecursive(input); System.out.println("Using recursion:"); System.out.println("The geometric progression of " + input + " is " + geomAnswer); System.out.println("The harmonic progression of " +...arrow_forward
- using java language Your program will identify if the shape is a square or a rectangle. Input the length and width of the shape, and display if it’s a rectangle or square, with its area and perimeter. Use the following methods in your program. inputLength() – returns the input length; inputWidth() – returns the input width; analyze(length,width) – based on the parameters length and width, returns a Boolean value if the shape is square or not compute(length,width) – based on the parameters length and width, display the area and the perimeter of the shape.arrow_forwardJava true or false: The method public boolean simpleMethod() { return true; } is a valid mutator?arrow_forwardType the program's output import java.util.Scanner; public class NumberSearch { public static void findNumber(int number, int lowVal, int highVal, String indentAmt) { int midVal; midVal = (highVal + lowVal) / 2; System.out.print(indentAmt); System.out.print(midVal); if (number == midVal) { System.out.println(" a"); } else { if (number < midVal) { System.out.println(" b"); findNumber(number, lowVal, midVal, indentAmt + " "); } else { System.out.println(" c"); findNumber(number, midVal + 1, highVal, indentAmt + " "); } } System.out.println(indentAmt + "d"); } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int number; number = scnr.nextInt(); findNumber(number, 0, 16, ""); } } Input 0arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education