Header

divider
Links
• Home
• Contact Me
• 
Aeries Portal
• Royal High School
• Simi Valley USD

divider

AP Statistics

• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links

divider
AP Comp-Sci
 Course Content
• Programs
• Practice Tests
• Comp-Sci Links

divider

CP Statistics
• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links


divider

Algebra
• Table of Contents
Geometry
• Table of Contents

Math Power
• Table of Contents

AP Computer Science Unit 1 Programs
Introduction to Java


Note: Do not worry about rounding decimal answers to any particular decimal place on the first few problems. Simply display the result as is and it should match the given samples for each problem, based on digits of precision for double variables.  We will learn how to specify the number of decimal places to display at a later time.

1.   Write a program to simulate a cash register purchase of one item. You will need to ask the user for the price of the item they wish to purchase. You will then calculate the tax on that purchase and the final cost (declare the tax rate as a constant value of 0.0725). The run of the program and the output should look something like the following:

Here is a sample run of this program:

What is the price of the item? 24.95
Here is your receipt:
Price: 24.95
Tax: 1.80887
Total Cost: 26.7589

Use the above as test data for your program.

2.   Write a program that uses an old scouting trick to determine the temperature by counting the number of times a cricket chirps in a minute. To find the temperature in degrees Fahrenheit (F), take the number of chirps in one minute, divide by 4 and add 10 (supposedly this really works).

Sample run of the program:

How many times did the cricket chirp? 175
The temperature in degrees Fahrenheit is: 53.75

3.   Write a program which will enable the user to determine the net pay amount of their paycheck based on the number of hours they worked. Assume that they are paid on an hourly basis and that the hourly rate is declared as a constant (12.75). You will also need to deduct taxes from their check. Assume that 25% of their pay goes to taxes and declare that percentage as a constant.

Here is a sample run of this program:

How many hours did you work this week? 35
Here is your pay stub:
Hours Worked: 35
Hourly Wage: 12.75
Gross Pay: 446.25
Taxes Deducted: 111.563
Net Pay: 334.688

4.   Write a program to calculate your percentages in a certain class, given the number of points earned and possible for both homework and tests.

Sample run of the program:

How many points have you earned on homework? 95
How many points are possible on homework? 120
How many points have you earned on tests? 175
How many points are possible on tests? 200 

Here is your grade breakdown:
Homework = 79.1667%
Tests = 87.5%
Overall = 84.375% 

5.   Write a program that accepts 3 numbers representing yards, feet and inches. It should then convert them into total inches.

Sample run of the program:

How many yards? 1
How many feet? 2
How many inches? 3 

All together, you have 63 inches.  

6.   Now write a program that accepts an integer representing total inches and then converts that into the appropriate number of yards, feet and inches.

Sample run of the program:

How many total inches? 137

3 yards
2 feet
5 inches
 

Also try the following:

84 total inches = 2 yards, 1 feet and 0 inches
32 total inches = 0 yards, 2 feet and 8 inches

7.   Now write a program that accepts a 3-digit integer and displays the place value that each digit represents. See the example below.

Enter an integer: 352

The 3 is in the hundreds place.
The 5 is in the tens place.
The 2 is in the ones place.  

8.   Write a program that will accept an amount of change less than a dollar. It will then determine and output the best change for a dollar. An example is given below.

Sample Run of the Program:

Enter the change amount: 64

Quarters: 2
Dimes: 1
Nickels: 0
Pennies: 4

9.   Write a program that will accept information for the purchase of some item (What is it called? How much does it cost? and How many do you want?). A total cost should be determined and a report should be displayed as shown in the example below. You will need to use the EasyFormat class to take care of decimal places and to make sure that the output lines up as is shown in the examples below.

Sample Run of the Program:

Item Name: thing
Item Cost: 11.80
Number of Items: 12 

     ITEM     COST     QTY     TOTAL
    thing    11.80      12    141.60

10.   Write a program that will accept an address and then display it as it would look on an envelope. This program requires the use of String variables. Recall that the Scanner Class method for reading String variables is nextLine();.

Sample Run of the Program:

Enter name: David Smith
Enter address: 1234 Royal Ave
Enter city: Simi Valley
Enter state: CA
Enter Zip Code: 93065

David Smith
1234 Royal Ave

Simi Valley, CA 93065

11. In a scientific experiment, the percent error is calculated as

Write a program to enter an actual and an expected value for a temperature in degrees Fahrenheit, and then determine the percent error. Note that you will need to multiply the above formula by 100 so that the answer is in percent form. Display the result to two decimal places.


Sample run of the program:


Actual = 30.8
Expected = 32.0

Percent Error = 3.75%

12. A certain bacteria grows according to the model

     bacteria

where I is the initial population, t is time in days, P is the population at time t. Write a program which will allow you to input the initial population of bacteria and a number of days. The program will then output the current population at the end of that number of days.


Sample run of the program:


Initial population: 50
Number of days: 5

After 5 days, the population grows from 50 to 268

13. The distance between two points, (x1,y1) and (x2, y2) is found by the formula

          

Write a program that prompts the user to enter coordinates for two points and then determines the distance between them. Round answer to one decimal place.


Sample run of the program
:

Enter x1: 3
Enter y1: -2
Enter x2: -1
Enter y2: 5

Distance = 8.1

14. Write a program that will ask for the hypotenuse and one leg of a right triangle. The program will then find the other leg. Recall again that Leg1 squared + Leg2 squared = Hyp squared. You will need to use a variation of this equation:

Sample Run of the Program:

Enter the hypotenuse: 10
Enter Leg1: 5

Leg2 = 8.7

15. THIS PROGRAM REQUIRES THE STUDENT CLASS: Write a program using the Student class that asks the user to enter a name and 3 test scores for a student. It should then display the student’s name back to the screen along with the test scores and the average score.

Sample Run of the Program (input and output values in bold)

Enter student name: Kate
Enter test score 1: 84
Enter test score 2: 88
Enter test score 3: 86

Student: Kate
Test 1: 84
Test 2: 88
Test 3: 86
Average Score: 86

16. THIS PROGRAM REQUIRES THE STUDENT CLASS: Modify program #15 so that you are able to change one of the test scores after they are displayed. It should then re-display the student’s name back to the screen along with the updated test scores, the high score and the average score.

Sample Run of the Program (input and output values in bold)

Enter student name: Kate
Enter test score 1: 84
Enter test score 2: 90
Enter test score 3: 86

Student: Kate
Test 1: 84
Test 2: 90
Test 3: 86
Average Score: 86.7

Enter a test number to modify: 2
Enter the new test score: 91

Student: Kate
Test 1: 84
Test 2: 91
Test 3: 86
Average Score: 87
.0

17. THIS PROGRAM REQUIRES THE STUDENT CLASS: For this problem, you will modify the Student class so that it can now handle 4 test scores for a student. This will require many changes within the class - make ALL necessary changes. After your modifcation, test it out using the file StudentTest2.java which is stored on the network

Sample Run of the Program (input and output values in bold)

Enter student name: Kate
Enter test score 1: 84
Enter test score 2: 88
Enter test score 3: 86
Enter test score 4: 91

Student: Kate
Test 1: 84
Test 2: 88
Test 3: 86
Test 4: 91
Average Score: 87.3



 






Home  •  About Me  •  Aeries Portal  •  Contact Me
© DanShuster.com