Question

In: Computer Science

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)

Solutions

Expert Solution

/******* RectangleDemo.java ********/

import java.util.Scanner;

public class RectangleDemo {

   public static void main(String[] args) {
       // Declaring variables
       double length, width, area;

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       // Getting the input entered by the user
       System.out.print("Enter length of rectangle :");
       length = sc.nextDouble();
       System.out.print("Enter width of rectangle :");
       width = sc.nextDouble();

       area = length * width;

       // Displaying the output
       System.out.printf("Length = %.2f\n", length);
       System.out.printf("Width = %.2f\n", width);
       System.out.printf("Area = %.2f\n", area);

   }

}

/**************************************************/

/**************************************************/

Output:

/**************************************************/


Related Solutions

Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
write a java program to evaluate the highest number input by user, cannot use math class,...
write a java program to evaluate the highest number input by user, cannot use math class, must use overloading . Must compute four computeHighNum methods. Here is what I have. import java.util.Scanner; public class Overload { public static void main(String[] args){ Scanner input = new Scanner(System.in); int number1 = input.nextInt(); int number2 = input.nextInt(); int number3 = input.nextInt();    //int maximum = maximum(number1, number2 ); System.out.printf("Highest integer is ");       // int number1 = input.nextInt(); // int number2 =...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a program to calculate the amount of money in an account: The user will input...
Write a program to calculate the amount of money in an account: The user will input initial deposit and the number of years to leave that money in the account. The interest is constant at 0.5% for the entire length of time. The output will be the balance, with interest compounded annually. (simple interest formula: interest = principal * rate) What variables will you need to complete the program? What “controls” will you need for the program? What formula will...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT