Circumference and Area of a Circle) Here’s a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floating-point numbers that contain decimal points, such as 3.14159. Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π. Use the techniques shown in Fig. 2.7. [Note: You may also use the predefined constant Math.PI for the value of π. This constant is more precise than the value 3.14159. Class Math is defined in package java.lang. Classes in that package are imported automatically, so you do not need to import class Math to use it.] Use the following formulas (r is the radius):
diameter = 2r
circumference = 2πr
area = πr2
Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement. The values produced by the circumference and area calculations are floating-point numbers. Such values can be output with the format specifier %f in a System.out.printf statement. You’ll learn more about floatingpoint numbers in Chapter 3.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Java How To Program (Early Objects)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++: Early Objects (9th Edition)
Computer Science: An Overview (12th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
Modern Database Management (12th Edition)
- 5. You are playing a game that has two dice - one die has 6 sides numbered 1 through 6 and the second die has 8 sides numbered 1 through 8. A turn involves rolling both die together. Write Java code to play 1,000 turns and keep track of the sum of the two dice in each roll I.e, (2 through 14). When all 1,000 turns have been completed, print a formatted table showing the value of the sum of the two dice (2 through 14) and the number of times that value occurred.arrow_forwardPlease solve it by javaarrow_forwardPlease Explain the Steps. (In Java Programming) See expected output below. Create a new Java application called "WeightedAvgDropSmallest" (without the quotation marks) according to the following guidelines. The program prompts the user for five to ten numbers all on one line, separated by spaces, calculates the weighted average of all those numbers except the lowest n numbers, where n and the weight are also given by the user, and displays all the numbers, the weight, the number of lowest numbers dropped, and the calculated average to the user. The program uses methods to: Get the numbers used to calculate the average. Get the number of lowest numbers to drop before calculating the average. Get the weight, a double greater than 0 and less than or equal to 1. Calculate the weighted average of the numbers (except the lowest n numbers) entered by the user. Print the results. 1. The first method should take no arguments and return an array list of doubles. 2. The second method…arrow_forward
- Understanding ifStatements Summary In this lab, you complete a prewritten Java program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is made of oak, add $20.00. No charge is added for pine. Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering. Instructions 1. Ensure the file named HouseSign.java is open. 2. You need to declare variables for the following, and initialize them where specified: A variable for the cost of the sign initialized to 0.00 (charge). A variable for the number of characters initialized to 8 (numChars). A variable for the color of the characters initialized to "gold" (color). A variable for the…arrow_forwardHow would I write this code using Java?arrow_forwardPlease assist with the attached java question. Thanksarrow_forward
- (PLEASE USE BASIC JAVA NOT COMPLEX I AM A BEGINNER THANKS) Canadian phone number has the following format: +1 (604) 295- 8959 Area Code= Three digits starting with 2-9Prefix= Three digits starting with 2-9Subscriber= Any four digits 0-9Write a java program, using loops, that asks the user to enter a phone number then if correct print theArea Code, Prefix, and Subscriber numbers. If not correct, print what is wrong. Sample run:Enter a number or -99 to quit: +1 (604) 277-9999The number is correct with area code: 604, prefix 277, and subscriber 9999Enter a number or -99 to quit: 1 (104) 277-0123Country code doesn’t start with + and area code doesn’t start with a 2-9 number.arrow_forwardYou are playing a game that has two dice – one die has 6 sides numbered 1 through 6 and the second die has 8 sides numbered 1 through 8. A turn involves rolling both die together. Write Java code to play 1,000 turns and keep track of the sum of the two dice in each roll i.e, (2 through 14). When all 1,000 turns have been completed, print a formatted table showing the value of the sum of the two dice (2 through 14) and the number of times that value occurred.arrow_forwardAssignment1 In this assignment you have to write a java program Assignment1 that contains all three zeros of the calculates the following third degree polynomial: 23 = -1 The solutions must be determined using the Newton-Raphson method. Work with an absolute accuracy of ɛ =0.00001. It means |x+1- X,] > ɛ Make sure your output looks like the Example output ( Like here below ). The real part and imaginary part must be rounded to three decimal places. The order of the zero points are not important. This order may be different for you. Example Output: PS C:\ Users\ Sam\Documents\Homework\PR> java Assignment1 Zero point 1 is equal to : -1.0 Zero point 2 is equal to : 0.5 - 0.866i Zero point 3 is equal to : 0.5 +0.866i Example Output for: f(z)= z³ +1arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT