Question

In: Computer Science

Write a program in java that uses methods to input data for calculation, calculate, and display...

Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.

Solutions

Expert Solution

import java.util.Scanner;

public class Rectangle {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int lenth=getInput("Enter length",sc);
       int width=getInput("Enter width",sc);
       int area=getArea(lenth,width);
       displayArea(area);
   }

   //prints the area
   private static void displayArea(int aArea) {
       System.out.println("Area : "+aArea);
   }

   //calcualtes the area
   private static int getArea(int aLenth, int aWidth) {
       return aLenth * aWidth;
   }

   // read input and return
   private static int getInput(String aString, Scanner sc) {
       System.out.println(aString);
       return sc.nextInt();
   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
Write a program to use Math methods to calculate and display the followings: Prompts the user...
Write a program to use Math methods to calculate and display the followings: Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
Write a Java program that uses printf, and takes user input to find the name of...
Write a Java program that uses printf, and takes user input to find the name of the File. FileCompare (20) Write a program that compares to files line by line, and counts the number of lines that are different. You can use file1.txt and file2.txt when testing your program, but you must ask for the file names in the input. main Interactively requests the names of the two files, after creating the Scanner for the keyboard. Creates a Scanner for...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
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)
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
Write a spell checking program (java) which uses a dictionary of words (input by the user...
Write a spell checking program (java) which uses a dictionary of words (input by the user as a string) to find misspelled words in a second string, the test string. Your program should prompt the user for the input string and the dictionary string. A valid dictionary string contains an alphabetized list of words. Functional requirements: For each word in the input string, your program should search the dictionary string for the given word. If the word is not in...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT