create the logic for a program that continuously prompts the user for two numeri
ID: 3759302 • Letter: C
Question
create the logic for a program that continuously prompts the user for two numeric values that represent the dimensions of a room in feet. include two overloaded methods that compute the rooms area. one method takes two numeric parameters and calculates the area by multiplying the parameters. the other takes a single numeric paramete, which is squared to calculate area.. each method displays its calculated result. accept input and respond as follows:
-when the user enters zero for the first value, end program
-if the user enters a negative number for either value, continue to reprompt the user until the value is not negative.
-if both numbers entered are greater than zero, call the method version that accepts two parameters and pass it both values
-if the second value is zero, call the version of the method accepts just one parameter and pass it the nonzero value.
Create a hierarchy chart (that shows all modules) and pseudocode for all modules. This will require repetition for multiple records (i.e. note the use of the word “continuously”).
Explanation / Answer
/* I am giving you full and final code iin Java. Here you can find all the modules and code of modules. I have used required Method overloading. Because name of methods are same but signature is different. */
import java.util.Scanner;
public class Area{
double area=0;
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter dimensions: ");
double l = s.nextDouble();
double w=s.nextDouble();
if(l==0)
{System.exit(0);}
while(l<0 || w<0 )
{
System.out.println("Dimensions can not be negative. Enter Again ");
l = s.nextDouble();
w=s.nextDouble();
if(l==0)
{System.exit(0);}
}
if(w==0)
{
System.out.println("The area is "+CalculateArea(l));
}
if(l!=0 && w!=0)
System.out.println("The area is "+CalculateArea(l,w));
}
static double CalculateArea(double l)
{
return l*l;
}
static double CalculateArea(double l,double w)
{
return l*w;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.