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 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 =...
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 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()...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a program that encrypts and decrypts the user input. Note – Your input should be...
Write a program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x) given by...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or DecimalFormat Practice programming simple mathematical calculations Instructions: Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree. You are to write a simple Java program which will generate an Invoice for his stay at the Inn. Your program should...
Write a simple JAVA program to understand natural language. The user will enter the input following...
Write a simple JAVA program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Chris came to Bangkok, Thailand in 2009. The user will follow the exactly the same formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay in City for X year(s). City is in...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT