Question

Its java class pratice  problem (Geometry: point in a rectangle?) Write a program that prompts the user...

Its java class pratice  problem (Geometry: point in a rectangle?)

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.

(Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and its vertical distance to (0, 0) is less than or equal to 5.0 / 2. Test your program to cover all cases.)

Sample Run 1

Enter a point with two coordinates: 2 2
Point (2.0, 2.0) is in the rectangle

Sample run 2

Enter a point with two coordinates: 6 4
Point (6.0, 4.0) is not in the rectangle

Sample Run 3

Enter a point with two coordinates: -5.1 -2.4
Point (-5.1, -2.4) is not in the rectangle

Sample Run 4

Enter a point with two coordinates: -4.9 2.49
Point (-4.9, 2.49) is in the rectangle

Sample Run 5

Enter a point with two coordinates: -4.99 -2.499
Point (-4.99, -2.499) is in the rectangle

Class Name: Exercise03_23

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION

Instruction:

  • Save java File by their class name i.e
    • Exercise03_23.java
  • Run Program as
    • javac Exercise03_23.java
    • java Exercise03_23
  • Kindly Comment if there is any issue.

CODE IN PLAINTEXT============================================

import java.util.Scanner;

public class Exercise03_23
{

public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
System.out.print("Enter a point with two coordinates:");
double x=sc.nextDouble();
double y=sc.nextDouble();
StringBuffer strbuf=new StringBuffer();
strbuf.append("The point");
strbuf.append("(");
strbuf.append(x);
strbuf.append(",");
strbuf.append(y);
strbuf.append(")");
if(CheckInside(x,y))
System.out.println(strbuf+ " is in the rectangle");
else
System.out.println(strbuf+ " is not in the rectangle");

}
public static boolean CheckInside(double x,double y)
{

if(x>=-5 && x<=5)
if (y>=-2.5 && y<=2.5)
return true;
return false;
}

}

Code Snapshot In IDE=============================

1- rogram to check whether the given point are within a rectanglr the user to enter a point (x, y) and checks whether the poi

- TOUPI ILI }//END main // Function to check given point within a rectangir public static boolean CheckInside (double x, doub

OUTPUT=============================

C:\Users\Asus\Documents\Java>javac Geometry.java C:\Users\Asus\Documents\Java>java Geometry ?Enter a point with two coordinat

Add a comment
Know the answer?
Add Answer to:
Its java class pratice  problem (Geometry: point in a rectangle?) Write a program that prompts the user...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a...

    NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a point with x- and y-coordinates. The class contains: - Two private data fields x and y that represent the coordinates with get methods. - A constructor that constructs a point with specified coordinates, with default point (0, 0). - A method named distance that returns the distance from this point to another point of the Point type. - A method named isNearBy(p1) that returns...

  • solve it with Java please Write a Java program that prompts the user to input length...

    solve it with Java please Write a Java program that prompts the user to input length and width of a shape. If length is equal to width, call a method to calculate the area of the shape and send only one side as parameter to this method. This meth return the area of the shape. If length is not equal to width, call a method to calculate the area of the shape and send both width and length as parameters...

  • write a java program that displays the following: Write a Java program that prompts the user...

    write a java program that displays the following: Write a Java program that prompts the user to enter an integer and determines whether 1. it is divisible by 5 and 6, whether on 2. it is divisible by 5 or 6, 3. it is divisible by 5 or 6, but not both. Here is a sample run of this program: Sample run: Enter an integer: 10 Is 10 divisible by 5 and 6? false Is 10 divisible by 5 or...

  • Design a Java program that asks the user to enter an integer number n and then...

    Design a Java program that asks the user to enter an integer number n and then generates an array of that many random points (x, y) with x- and y-coordinates in the range between 0 and 100. After this the program must ask the user to enter two diagonal points (x_1, y_1) and (x_2, y_2) of a rectangle with sides parallel to the coordinate axis (see the image below, where possible pairs of diagonal points are shown in red color)....

  • Write a program that prompts the user to enter a binary string and displays the corresponding...

    Write a program that prompts the user to enter a binary string and displays the corresponding decimal integer value. For example, binary string ‘10001’ is 17 (1*24 +0*23 +0*22 +0*2 + 1 = 17) A sample run : Enter a binary: 10001 17 Enter second integer: 110 6 Use python.

  • Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3,...

    Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the distance of two points (x1, y1) and (x2, y2) is d = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); or d = Math.pow((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1), 0.5); The formula for computing the...

  • PLEASE DO IN PSEUDOCODE; Design and implement a program (name it CheckPoint) that prompts the user...

    PLEASE DO IN PSEUDOCODE; Design and implement a program (name it CheckPoint) that prompts the user to enter the x-coordinate then y-coordinate of a point (in a Cartesian plane) as integer values. The program prints out the entered values followed by the location of the point on the plane. The possibilities for a point are: the origin point, on the x-axis, on the y-axis, in the first quadrant, in the second quadrant, in the third quadrant, or in the fourth...

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The...

    Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT