Question

In: Computer Science

Write a program that asks the user for the lengths of the sides of a rectangle....

Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem).

This question should be in javascript and should be able to be executed in netbeans.

Solutions

Expert Solution

Answer:

Here is the Java script code as per your requirement

Raw code:

//prompting for inputs from user

var rectangleLength = parseInt(prompt("Enter length of rectangle:"));

var rectangleWidth = parseInt(prompt("Enter width of rectangle:"));

//checking if they are valid inputs

if (isNaN(rectangleWidth)|| (isNaN(rectangleLength)))

{

console.log("enter valid width and length")

}

else{

//if they are valind inputs

//calculations areaOfRectangle

var areaOfRectangle=rectangleLength*rectangleWidth

console.log("Area of rectangle is: " + areaOfRectangle);

//calculations of perimeter

var perimeterOfRectangle = 2 * (rectangleLength) + 2 * (rectangleWidth);

console.log("Perimeter of rectangle: " + perimeterOfRectangle);

//diagnol using pythgorean theorem

var diagnol = Math.sqrt(rectangleWidth*rectangleWidth + rectangleLength*rectangleLength);

console.log('Diagonal of rectangle: ' + Math.ceil(diagnol))

}

Editor:

output:

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.


Related Solutions

Write a program named Triangle.java that asks for the lengths of the three sides of a...
Write a program named Triangle.java that asks for the lengths of the three sides of a triangle and computes the perimeter if the input is valid. The input is valid if the sum of every pair of two sides is greater than the remaining side. For example, the lengths 3, 4, and 5 define a valid triangle: 3 plus 4 is greater than 5; 4 plus 5 is greater than 3, and 5 plus 3 is greater than 4. However,...
In C write a program that asks the user for the dimensions of 3 sides of...
In C write a program that asks the user for the dimensions of 3 sides of a triangle. Each side dimension must be between 1.00 and 100.00 including 1.00 and 100.00. If the side dimensions indeed can make a valid triangle then the program should use these values to determine the perimeter and the area of the valid triangle 1. Must use programmer define functions 2. Your program must have at least 4 functions, main and the following 3 functions:...
Write a program (polygon.py) that asks the user to enter the number of sides in a...
Write a program (polygon.py) that asks the user to enter the number of sides in a regular polygon. For example, an equilateral triangle is a regular 3-sided polygon, a square is a regular 4-sided polygon, and a pentagon is a regular 5-sided polygon. If a user enters a number of sides between 3 and 25, inclusive, draw the polygon and wait for the user to click on the screen to quit the program. If the user enters a number less...
Write a program that prompts for the lengths of the sides of a triangle and reports...
Write a program that prompts for the lengths of the sides of a triangle and reports the three angles. Make sure you have a good introduction stating what the program does when it is run, and a helpful prompt for the user when asking for input: i.e. Here is the generated output from a sample program: This program computes the angles of a triangle given the lengths of the sides. What is the length of side 1? <wait for user...
Write a program that accepts the lengths of three sides of a triangle as inputs. The...
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT