Question

(Use Java ) please write comment on every line I need to understand the code Problem...

(Use Java )

please write comment on every line I need to understand the code

Problem Description:

Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5. For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle, as shown in the Figure.

(Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to 10 / 2 and its vertical distance to (0, 0) is less than or equal to 5 / 2.)

Here are sample runs of the program:

Sample 1:

Enter a point with two coordinates: 2 2

Point (2.0, 2.0) is in the rectangle

Sample 2:

Enter a point with two coordinates: 6 4

Point (6.0, 4.0) is not in the rectangle

Submit your group video presentation using Zoom. In your video cover the following:

Analysis:

(Describe the problem including input and output in your own words.)

Design:

(Describe the major steps for solving the problem.)

Coding: (Go over your code step by step)

Testing: (Describe how you test this program). In other words run your code with sample outputs.

Homework Answers

Answer #1

Hope you like the answer I explain the question in a program through comment section and please upvote me for the efforts

import java.util.Scanner;

public class Solver {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Prompt the user to enter a point (x, y)

System.out.print("Enter a point with two coordinates: ");

double x = input.nextDouble();

double y = input.nextDouble();

// Check whether the point is within the rectangle

// centered at (0, 0) with width 10 and height 5

boolean withinRectangle = (Math.pow(Math.pow(x, 2), 0.5) <= 10 / 2 ) ||

(Math.pow(Math.pow(y, 2), 0.5) <= 5.0 / 2);

// Display results

System.out.println("Point (" + x + ", " + y + ") is " +

((withinRectangle) ? "in " : "not in ") + "the rectangle");

}

}

Output :

Enter a point with two coordinates: 2 2

Point (2.0, 2.0) is in the rectangle

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please write code in C++ and include all header files not including std/bitsc: (Maximum consecutive increasingly...
Please write code in C++ and include all header files not including std/bitsc: (Maximum consecutive increasingly ordered substring) Write a program that prompts the user to enter a string and displays the maximum consecutive increasingly ordered substring. Analyze the time complexity of your program. Sample Run 1 Enter a string: abcabcdgabxy The maximum consecutive increasing ordered substring is abcdg Sample Run 2 Enter a string: abcabcdgabmnsxy The maximum consecutive increasing ordered substring is abmnsxy
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) Write a Java program that: Asks the user to enter his/her first name and ID. Prints the user's first name and ID in reverse order with a space between them recursively. Important notes: You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code....
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
Please provide commenting of code so I can understand how to solve this problem. Please provide...
Please provide commenting of code so I can understand how to solve this problem. Please provide text files. Using C++ Write a program that reads a given file, and then outputs the contents of it to another file. It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file. It should prompt the user for the input and output...
Write a complete recursive java program to compute the heights of the tick marks on a...
Write a complete recursive java program to compute the heights of the tick marks on a ruler. Assume that the length of the ruler is a power of 2 (say L=2^n, where n >=1) , and the marks are to be placed at every point between 0 and 2^n, not including the endpoints. The endpoints 0 and 2^n will have height 0. Here are the rules for computing the heights of the ticks for a ruler of length L=2^n: 1....
I need the java code for a 4-function calculator app on android studio. Please make sure...
I need the java code for a 4-function calculator app on android studio. Please make sure all the requirements shown below are followed (such as the error portion and etc). The topic of this app is to simply create a 4 function calculator which calculates math expressions (add, subtract, multiply, and divide numbers). The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed *...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display the distance a vehicle has traveled for each hour of a...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT