Question

In: Computer Science

Write in JAVA eclipse program (comment in every line): class for calculating an area of a...

Write in JAVA eclipse program (comment in every line):

class for calculating an area of a room. The program MUST ask for the length and the width of the room.

Make sure you write the methods to get the width and length and print the area.

Solutions

Expert Solution

Please find below code in java and don't forget to give a Like.

Please refer below screenshot for code and output.

Code:

import java.util.Scanner;//importing scanner to take input from user
public class Main
{
   public static void main(String[] args) {
   double area;//taking all varibles datatype as double
   double length,width;
   //calling length method that takes input
   //method returns lenght value from user and store in length variable
   length=length();
   //calling width function and storing in width variable
   width=width();
   //calculating area by multiplying both
   area=length*width;
   //calling print method to print the area
   print(area);
   }
   //creating a length method of type double since it returns double value
   public static double length(){
   //creating a input varible and will be using it to take input
   Scanner input=new Scanner(System.in);
   System.out.print("Enter the length of the room: ");
   //this this take the input from user and store it in lenght varible
   double length=input.nextDouble();
   //returning length to main
   return length;
   }
   //this is same as above length method
   public static double width(){
   Scanner input=new Scanner(System.in);
   System.out.print("Enter the width of the room: ");
   double width=input.nextDouble();
   return width;
   }
   //method print will take double value as argument and print the area
   public static void print(double area){
   //this statement prints the output
   System.out.println("Area of the room: "+area);
   }
}

Output and screenshot:


Related Solutions

Write a JAVA program in eclipse (write comment in every line) that asks the user to...
Write a JAVA program in eclipse (write comment in every line) that asks the user to enter two numbers and an operator (+, -, *, / or %), obtain them from the user and prints their sum, product, difference, quotient or remainder depending on the operator. You need to use OOP techniques (objects, classes, methods….). This program must be place in a loop that runs 3 times.
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark for a family/group Ticket rates are listed below kids (Age 12 and under)=$ 12.50 Regular( Age between12 -55) =$ 18.25 Seniors (55 and above) = $15.00 Tax =7% Your program should ask the user to enter the total number of members in their group. User needs to enter the ages for all members. Write appropriate error messages for invalid entries. An array should be...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart!!!! If the user enters a negative value for the sales amount, the program will keep asking the user to enter...
Create JAVA PROGRAM, and write comment for codes also. 2) Every extra 3500 calories means gaining...
Create JAVA PROGRAM, and write comment for codes also. 2) Every extra 3500 calories means gaining a pound. Falling short by 3500 means losing a pound. Get the base amount of calories the person needs in a day (BMR). Then have the user enter in calorie totals for each day and display their weight every week. They might eat more than once in a day.
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse IDE) The qualifications given are: Residence: The home must be your primary residence. Down payment: They must have a credit score of at least 563. The Java Program needs to do the following. This can all be done in the main() method. Create a boolean variable to store the Residence requirement. Prompt the user to "Enter 1 if the Home will be the primary...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT