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

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 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..
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...
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements and create an array. Then, write a Merge Sort function with recursion (in the main) that takes the user inputted elements in the array, sorts them, and prints them back.
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT