Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 19RE
Modify the pseudocode for the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that simulates the rolling of two dice. The program should use rand to roll the first dice and should use rand again to roll the second dice. The sum of the two values should then be calculated. Note: Since each dice can show an integer value from 1 to 6, then the sum of the to values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. Below shows the 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a single-subscripted array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals reasonable (i.e. there are six ways to roll a 7, so approximately one sixth of all the rolls should be 7).
What is the probability that in a classroom of x people, at least 2 will be born on the same day of the year (ignore leap year)? Use a Monte Carlo Simulation and a frequency table to write a program that calculates this probability, where the number of people (x) in the simulated class is given by the user. The probability for a class of size 23, should be right around 50%.
PLEASE use the code outline given below to answer this question:
import mathimport random
# create and initialize frequency table:ft = []k = 0while(k < 365) : ft.append(0) k = k+1
# Allow the user to determine class size:print("Please type in how many people are in the class: ")x= int(input())
success = 0
# Simulate:c = 0while(c < 10000) : # Step 1: re-initialize birthday frequency table (it must be re-initialized for each play-through (why?): k = 0 while(k < 365) : ft[k] = 0 k = k+1 # Step 2: randomly get x birthdays and update frequency table: k = 0 while(k < x): # your code…
The ideal gas law allows the calculation of volume of a gas given the pressure(P), amount of the gas (n), and the temperature (T). The equation is:V = nRT / PSince we only have used integer arithmetic, all numbers will be integer values with no decimal points. The constant R is 8.314 and will be specified as (8314/1000). This gives the same result. Implement the idea gas law program where the user is prompted for and enters values for n, T, and P, and V is calculated and printed out. Be careful to implement an accurate version of this program. Your program should include a proper and useful prompt for input, and print the results in a meaningful manner.
Chapter 2 Solutions
Big Java Late Objects
Ch. 2.1 - Declare a variable suitable for holding the number...Ch. 2.1 - What is wrong with the following variable...Ch. 2.1 - Declare and initialize two variables, unitPrice...Ch. 2.1 - Prob. 4SCCh. 2.1 - Some drinks are sold in four-packs instead of...Ch. 2.1 - Prob. 6SCCh. 2.1 - Prob. 7SCCh. 2.1 - Prob. 8SCCh. 2.1 - How would you explain assignment using the parking...Ch. 2.2 - A bank account earns interest once per year. In...
Ch. 2.2 - In Java, how do you compute the side length of a...Ch. 2.2 - The volume of a sphere is given by V=43r3 If the...Ch. 2.2 - Prob. 13SCCh. 2.2 - Prob. 14SCCh. 2.3 - Write statements to prompt for and read the users...Ch. 2.3 - What is wrong with the following statement...Ch. 2.3 - Prob. 17SCCh. 2.3 - What is problematic about the following statement...Ch. 2.3 - What is the output of the following statement...Ch. 2.3 - Using the printf method, print the values of the...Ch. 2.4 - Prob. 21SCCh. 2.4 - Suppose the architect specifies a pattern with...Ch. 2.4 - A robot needs to tile a floor with alternating...Ch. 2.4 - For a particular car, repair and maintenance costs...Ch. 2.4 - The shape of a bottle is approximated by two...Ch. 2.5 - What is the length of the string "Java Program"?Ch. 2.5 - Consider this string variable. String str = "Java...Ch. 2.5 - Use string concatenation to turn the string...Ch. 2.5 - Prob. 29SCCh. 2.5 - Prob. 30SCCh. 2 - Write declarations for storing the following...Ch. 2 - What is the value of mystery after this sequence...Ch. 2 - What is wrong with the following sequence of...Ch. 2 - Write the following mathematical expressions in...Ch. 2 - Write the following Java expressions in...Ch. 2 - What are the values of the following expressions?...Ch. 2 - What are the values of the following expressions,...Ch. 2 - What are the values of the following expressions?...Ch. 2 - Assuming that a and b are variables of type int,...Ch. 2 - Suppose direction is an integer angle between 0...Ch. 2 - Find at least five compile-time errors in the...Ch. 2 - Find three run-time errors in the following...Ch. 2 - Consider the following code segment. double...Ch. 2 - Explain the differences between 2, 2.0, 2, 2, and...Ch. 2 - Explain what each of the following program...Ch. 2 - Write pseudocode for a program that reads a word...Ch. 2 - Write pseudocode for a program that reads a name...Ch. 2 - Write pseudocode for a program that computes the...Ch. 2 - Modify the pseudocode for the program in How To...Ch. 2 - Prob. 20RECh. 2 - You are cutting off a piece of pie like this,...Ch. 2 - The following pseudocode describes how to obtain...Ch. 2 - Suppose you are given a string str and two...Ch. 2 - Prob. 24RECh. 2 - For each of the following computations in Java,...Ch. 2 - Prob. 26RECh. 2 - This chapter contains a number of recommendations...Ch. 2 - Write a program that displays the dimensions of a...Ch. 2 - Write a program that computes and displays the...Ch. 2 - Write a program that reads a number and displays...Ch. 2 - Write a program that prompts the user for two...Ch. 2 - Enhance the output of Exercise E2.4 so that the...Ch. 2 - Write a program that prompts the user for a...Ch. 2 - Write a program that prompts the user for a radius...Ch. 2 - Write a program that asks the user for the lengths...Ch. 2 - Improve the program discussed in How To 2.1 to...Ch. 2 - Write a program that helps a person decide whether...Ch. 2 - Write a program that asks the user to input The...Ch. 2 - File names and extensions. Write a program that...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Printing a grid. Write a program that prints the...Ch. 2 - Write a program that reads in an integer and...Ch. 2 - Write a program that reads two times in military...Ch. 2 - Writing large letters. A large letter H can be...Ch. 2 - Write a program that transforms numbers 1, 2, 3, ,...Ch. 2 - Write a program that prints a Christmas tree:...Ch. 2 - Easter Sunday is the first Sunday after the first...Ch. 2 - In this project, you will perform calculations...Ch. 2 - The following pseudocode describes how a bookstore...Ch. 2 - The following pseudocode describes how to turn a...Ch. 2 - The following pseudocode describes how to extract...Ch. 2 - Giving change. Implement a program that directs a...Ch. 2 - An online bank wants you to create a program that...Ch. 2 - A video club wants to reward its best members with...Ch. 2 - Consider the following circuit. Write a program...Ch. 2 - The dew point temperature Td can be calculated...Ch. 2 - The pipe clip temperature sensors shown here are...Ch. 2 - Prob. 12PPCh. 2 - Consider the following tuning circuit connected to...Ch. 2 - According to the Coulomb force law, the electric...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
(a) Suppose that a body is dropped (0=0) from a distance r0R from the earths center, so its acceleration is d/d...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
(De Morgans Laws) In this chapter, we discussed the logical operators , , | |, |, ^ and !. De Morgans laws can ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Give a short fragment of Java code that uses the progression classes from Section 2.2.3 to find the eighth valu...
Data Structures and Algorithms in Java
Distinguish among data definition commands, data manipulation commands, and data control commands.
Modern Database Management (12th Edition)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th Edition)
What are the variables that receive pieces of data in a module called?
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (This is for devc++ but I use mindmap from Cengage. I know it a little different. If you can't use Cengage, I suggest devc++ version 5.11) One way to determine how healthy a person is, is by measuring the body fat of the person. The formulas to determine the body fat for female and male are as follows: Body fat formula for women: A1 = (body weight X 0.732) + 8.987 A2 = wrist measurement (at fullest point) / 3.140 A3 = waist measurement (at navel) X 0.157 A4 = hip measurement (at fullest point) X 0.249 A5 = forearm measurement (at fullest point) X 0.434 B = A1 + A2 - A3 - A4 + A5 Body fat = body weight - B Body fat percentage = body fat X 100 / body weight Body fat formula for men: A1 = (body weight X 1.082) + 94.42 A2 = waist measurement X 4.15 B = A1 - A2 Body fat = body weight - B Body fat percentage = body fat X 100 / body weight Instructions Write a program to calculate the body fat of a person. Prompt the user to input: Their gender ('m' or 'M' for male, 'f' or 'F' for…arrow_forwardPython For this lab, you will use a tuple to represent a student record. A student record consists of the student’s name, year, and GPA. For example, (“John”, “Senior”, 3.7) is a record for John who is a senior with a 3.7 GPA. You will write a program that prompts the user for the number of records to enter. Then it reads input from the user for each record. Remember that each record consists of a student’s name, year, and GPA. It then prints the record of each student as shown below. Functions: You will write the following functions: read_records(n) Read n number of records and return a list of records. print_records(records) Takes in a list of records and print each one. main() Prompts the user for the number of records to read, get a list of records from the user, and print the records. Optional: print the average GPA of the students. Sample run: How many students record to enter: 2 Enter student's name: John Enter student's year: junior Enter…arrow_forwardUse Python & Don't use any python Library. You can use Random.randint() only. 3. Suppose you have been hired to develop a musical chair game. In this game there will be 7 participants and all of them will be moving clockwise around a set of 7 chairs organized in a circular manner while music will be played in the background. You will control the music using random numbers between 0-3.lf the generated random number is 1, you will stop the music and if the number of participants who are still in the game is n, the participants at position (n/2) will be eliminated. Each time a participant is eliminated, a chair will be removed and you have to print the player names who are still in the game. The game will end when there will be only one participant left. At the end of the game, display the name of the winner. [Hint: You will need to invoke a built-in method to generate a random number between 0 (inclusive) to 3 (inclusive)]arrow_forward
- (This is a version of Programming Project 2.1 from Chapter 2.) The Babylonianalgorithm to compute the square root of a positive number n is as follows:1. Make a guess at the answer (you can pick n/2 as your initial guess).2. Compute r = n / guess.3. Set guess = (guess +r) / 2.4. Go back to step 2 until the last two guess values are within 1% of each other. Write a program that inputs a double for n, iterates through the Babylonian algo-rithm until the guess is within 1% of the previous guess and outputs the answer as a double to two decimal places. Your answer should be accurate even for largevalues of n.arrow_forwardWelcome to the era of Aladdin and the great magic lamp. This is 1st of January and Aladdin will be in jail for one year. He was recently caught for helping forty thieves. Now he has nothing to do. But he knows that Jasmine is waiting for him. At some point he got an idea to give Jasmine a magical program that can find intervals of months from a year. This allows her to easily determine how long it will take for Aladdin to get out. Then Aladdin rubs the magic lamp and The Genie appears. Then he asked The Genie to make such a magical program. Unfortunately the Genie doesn't know programming and he wants your help to create that magical program. Genie will give you N as the day of the year and you have to print in which month that day is. Input Format Input will contain one line with a single integer N, day of the year. Constraints 1 <= N <= 365 Output Format Print a single line containing the name of month. Be careful about the newline ('\n') at the end. Sample Input 0 1 Sample…arrow_forwardhi! i am a newbie in python. please help me on this problem. also, please send a screenshot for a proof that the codes works. thanks~arrow_forward
- In pythonarrow_forwardWrite a python program that computes the zakat, obligatory charity, on camels. The program asks the user to input the number of camels, and then the zakat is calculated based on the following table: Rule for computing the zakat of 121 camels or more: You need to find the combinations of 40 camels and 50 camels that will minimize the number of “left over” camels not being “counted” in the zakat. For example, for 130 camels, we have (2*40) + (1*50)=130, with no left overs, and hence, the zakat consists of 2 bint Laboun and 1 Hiqqah. When we have 145 camels, we have the following scenarios: 1. (140) + (250) = 140 with 5 camels left over, 2. (240) + (150) = 130 with 15 camels left over, 3. (340) + (050) = 120 with 25 camels left over. Therefore, in this case the zakat is 1 bint Laboun and 2 Hiqqah, following the first scenario. Important Notes: Make sure that the input value is a positive integer. If not, the program must print the following message: Wrong input. Number should be an…arrow_forwardThe body mass index, BMI, is a measure used to determine if a person is overweight or not. We can calculate BMI from the weight of the person (in pounds) and the height (in inches) of the person.The formula for calculating BMI is:BMI = (weightInPounds * 703) divided by (heightInInches squared)In this problem, you will develop a Java program as a BMI calculator, that reads the user’s weight in pounds and height in inches, then calculates and displays the user’s body mass index BMI. Also, display the following information {from the US Department of Health} so the user can evaluate his/her BMI:BMI values:Underweight: less than 18.5Normal: between 18.5 and 24.9Overweight: between 25 and 29.9Obese: 30 or greaterarrow_forward
- Write a program that will figure out the required change for a purchase. Start by asking the user for the price of the product and the amount paid. (We are expecting that the user will give a larger value for the amount paid.) Read in each of these values as a double. Report back to the user the number of each denomination of change due. You are not just telling the user the amount of money he gets back. Hint: Working with integers is much easier. The modulo operator is your friend for this assignment. Also, note that pennies can be tricky due to the poor real number to binary conversions. (Remember that 1.00 could actually be stored as 0.9999999999997.) Do not include five-dollar bills, ten-dollar bills, etc. Only show coins and one-dollar bill amounts. Be sure to test multiple values. There is a test case below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output Example (User input is marked with >>>.…arrow_forwardWrite an improved version of the futval . py program from Chapter 2.Your program will prompt the user for the amount of the investment, theannualized interest rate, and the number of years of the investment. Theprogram will then output a nicely formatted table that tracks the value ofthe investment year by year. Your output might look something like this: Year Value----------------0 $2000 . 001 $2200 . 002 $2420 . 003 $2662 . 004 $2928 . 205 $3221 . 026 $3542 . 127 $3897 . 43arrow_forwardWilma Peterson is paid by the hour. She would like a program that calculates and displays her weekly gross pay. For this exercise, you do not need to worry about overtime pay, as Wilma never works more than 40 hours in a week. Desk-check your solution’s algorithm using $10 as the hourly pay and 35 as the number of hours worked; then desk-check it using $15 and 25.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY