Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 4P

The Social Security Administration maintains an actuarial life table that contains the probability that a person in the United States will die (http://www.ssa.gov/OACT/STATS/table4c6.html). The death probabilities from this table for 2009 are stored in the file LifeDeathProbability.txt that is included with the book’s source code. There are three values for each row the age, death probability for a male, and death probability for a female. For example, the first five lines are:

0    0.006990    0.005728

1    0.000447    0.000373

2    0.000301    0.000241

3    0.000233    0.000186

4    0.000177    0.000150

This says that a 3-year-old female has a 0 000186 chance of dying that year

Write a program that simulates how long you will live. The basic idea is to generate random numbers for each age until you “die”. For example, if you are a 1-year-old male, then if a random number is <−0.000447 then the simulation will say you live to age 1. Otherwise if the random number is > 0.000447 then go to the age 2 and generate another random number. If it is < 0.000301 then the simulation will say you will live to age 2, etc. The program should input your sex and age to determine which probabilities to use. The program should then simulate to what age you will live by starting with the death probability for the age and sex entered in the file. If the simulation reaches age 120 then stop and predict that the user will live to 120. This program is merely a simulation and will give different results each time it is run.

Blurred answer
Students have asked these similar questions
Write a program that reads student information from a text file, then creates a text file that records the course grades of the students and a final grade. Each row of the .txt file contains the Last Name, First Name, Midterm1 score, Midterm2 score, and the Final score of a student, each separated by a space. A sample of the student information is provided in StudentInfo.txt below. Assume the number of students is at least 1 and at most 20. The program performs the following tasks: • Read the file name of the .txt file from the user. • Open the .txt file and read the student information using readline() or readlines(). • Compute the average exam score of each student. • Assign a letter grade to each student based on the average exam score in the following scale: ◦ A: 90 =< x ◦ B: 80 =< x < 90 ◦ C: 70 =< x < 80 ◦ D: 60 =< x < 70 ◦ F: x < 60 • Output the first names, last names, exam scores, and letter…
Computer Science For each of the code snippet given below, identify the error and then write code after fixing the error.   Given code is the simulation of grep -v command. -v prints all lines that do not match a specific pattern. void grep_inverse(char *filename, char *str) { FILE *fp; char buf[buff_size]; fp = fopen(filename, "r"); if(!fp) {        perror(filename); } else {                                while (fgets(buf, buff_size, fp) != NULL) { if ((strstr (buf, str)) != NULL)   printf("%s", buf);                            } } fclose(fp); }
#program should be written in python with comments. Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example:codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .}Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol @, and so forth. The program should open a specified text file, read its contents, then use the dictionary to write an encrypted version of the file’s contents to a second file. Each character in the second file should contain the code for the corresponding character in the first file. Write a second program that opens an encrypted file and displays its decrypted contents on the screen.

Chapter 10 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY