Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Absolute Java (6th Edition)
Software Engineering (10th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Artificial Intelligence: A Modern Approach
- java 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 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.arrow_forward1. Write a pyrhon program that prints out a classic hangman stick figure. The program should ask the user to enter a number from 1-6 and the corresponding hangman should be printed. The value the user inputs corresponds to the number of incorrect guesses in a real hangman game and so the completeness of the hangman will correspond to the number of ‘incorrect guesses’ inputted by the user (e.g., if the user enters 1, then only the head of the hangman will be printed; full example below). Example:Enter a number from 1-6: 1O Enter a number from 1-6: 2O|Enter a number from 1-6: 3O\||Enter a number from 1-6: 4O\|/|Enter a number from 1-6: 5O\|/|/Enter a number from 1-6: 6O\|/|/ \ 2. Modify your program from problem 1 so that the user input is checked to be a validsingle digit (1-6) before printing the corresponding hangman. If the input is not valid, theninstead of a hangman the following message should be printed “Invalid input: you must enter asingle number from 1-6.” Example:Enter a…arrow_forwardWrite a program in python Suppose a right triangle is placed in a plane as shown below. The right-angle point is at (0, 0), and the other two points are at (200, 0), and (0, 100). Write a program that prompts the user to enter a point with x- and y-coordinates and determines whether the point is inside the triangle. Sample runs of the program are given below: Enter a point's x- and y-coordinates: 100.5 25.5 The point is in the triangle Enter a point's x- and y-coordinates: 100.5 50.5 The point is not in the trianglearrow_forward
- Write a program that prompts the user to enter apoint (x, y) and checks whether the point is within the rectangle centred at (1, 1)with width 10 and height 5. For example, (2, 2) is inside the rectangle and (6, 4)is outside the rectangle, as shown in Figure . (Hint: A point is in the rectangleif its horizontal distance to (0, 0) is less than or equal to 10 / 2 and its verticaldistance to (0, 0) is less than or equal to 5.0 / 2. Test your program to cover allcases.) Here are two sample runs. Enter a point with two coordinates: 2 2 ↵EnterPoint (2.0, 2.0) is in the rectanglearrow_forwardWrite a python program of the following using the modification of the second picturearrow_forwardYou have been asked to write a program to play rock-paper-scissors. Your program will ask the user to input a number 0, 1, or 2 to denote rock, paper, and scissors respectively. Your program will then randomly generate a number 0, 1, or 2 to denote the computer’s hand. The rules for the game are: •A scissor can cut paper. •A rock can knock a scissor. •A piece of paper can wrap a rock. Let the game run continuously until either the user or the computer wins 3 times, displaying the outcome of each hand. At the end of the game, display a message indicating whether the user or the computer wins Helpful Hint: import random player2= random.randint(0, 2)arrow_forward
- Display the first N magic numbers, where N is a positive number that the user provides as input. Here, a magic number is a number whose sum of its digits eventually leads to 1. For example, 1234 is a magic number because 1 + 2 + 3 + 4 = 10 and 1 + 0 = 1, while 1235 is not (1 + 2 + 3 + 5 = 11 and 1 + 1 = 2). Write a program that prints out the first N magic numbers, seven on each line. You are required to use the following function prototype: bool isMagic(int value); // Returns true if value is a magic number The outline of this function will be as follows: Step 1: Calculate the sum of digits of the value Step 2: Repeat Step 1 until we get a single-digit Step 3: If the resulting sum is equal to 1 then it is a magic number, otherwise not Here is the sample output:arrow_forwardf. A laborant in a laboratory does a number of antigen tests in one day. Write a program that simulates the number of antigen tests done in a day in a laboratory, displays the number of positives and negatives, and calculates the % of positives in one day. Your program needs to first generate a random number that will show the number of tests done in a day. One laboratory in a day cannot do more than 100 tests and less than 1 (they do at least one). Then for each of the tests, your program needs to generate a random number to show whether they are positive or negative. In order to write this program, you need to have the following three functions used by the main function: test result (void): This function generates a test result. It should randomly return either one or zero. 1 means positive test result and 0 means negative test result. float positive percentage (int,int) : This function takes the total number of positives and the total number of tests and returns the % of positives.…arrow_forwardThis example creates a program to teach a first grade child how to learn subtractions. The program randomly generates two single- digit integers number1 and number2 with number1 > number2 and displays a question such as "What is 9 – 2?" to the student. After the student types the answer, the program displays a message to indicate whether the answer is correct.arrow_forward
- computer programingarrow_forwardwrite a program that reads in an integer value between 1 and 5(inclusive) and a text word from the keyboard and prints out whethe the two represent the same number. For exemple: Enter integer value: 4 Enter word: four 4 and four are the same number. or Enter integer value: 4 Enter word: five 4 and five are not the same number. you may assume that the user will only enter integer values between 1 and 5 (inclusive). only use conditional statement like if, else, elif.arrow_forwardWe need to use the java languagearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr