First Resit programming a ssignment

advertisement
Assignment : Submission date 2nd of May 2014
Programming coursework
IS50001B (FY05) Foundations of Problem Solving and Programming
This assignment contains 5 questions. You should do all of them. for every
exercise you should write a short paragraph explaining the main steps of your
program. A working program with a good explanation will be awarded a good
mark.
Question 1
Write the program, Income.java, that asks the user the number user the number of worked hours, the
pay rate (hourly rate) and the tax rate. The program then calculates the pay amount and tax amount.
The program should print the following:
i.e. workedhours= 40, payRate= 10 pounds and taxRate = 0.10
Worked hours = 40
Pay Amount = £ 400
Tax Rate = £ 40
Question 2:
Assume there is 200 miles between two consecutive petrol stations. You are to write a program to
help drivers nearer to first station to decide, if they need petrol or wait till they get to the next station.
The program asks for:



The capacity of the petrol tank, in litres
The indication of the petrol gauge in percent (full= 100, three quarters full = 75, and so on)
The miles per litre of the car.
The program then writes out "Get Petrol!" or "Safe to Proceed" depending on if the car can cross the
200 miles with the gas remaining in the tank.
Tank capacity:
12
Gauge reading:
50
Miles per litre:
30
Get Petrol!
Question 3
The following algorithm yields the season (Spring, Summer, Fall, or Winter) for a given month of
the day.
IF month is 1,2, or 3, season = "Winter
Else if month is 4, 5, or 6, season = "Spring"
Else if month is 7,8, 9, season = "Summer"
Else if month is 10,11, or 12, season = "Fall"
If month is divisible by 3 and day >= 21
If season is "Winter", season = "Spring"
Else if season is "Spring", season = "Summer"
Else if season is "Summer", season = "Fall"
Else season = "Winter"
Write a program that prompts the user for a month and day and then prints the season, as determined
by this algorithm.
Question 4:
Rolling 6 sided dice can teach us about probability. Allow the user to choose a number of rolls for 2
six sided dice. Add the dice together and keep track of how many of each of the sums are rolled.
Print out a frequency distribution table.
For Example: if the user enters 15 as the number of pairs to roll the output should be as follows:
Roll Sum
2
3
4
5
6
7
8
9
10
11
12
Frequency
0
1
1
2
2
3
1
3
1
1
0
Question 5
Write a program that tries to guess the number thought of by the user. The number is between 0 and
1000. If the computer’s guess is too high, the user should enter ‘l’. If the computer’s guess is too
low, the user should enter ‘h’. If the computer’s guess is correct it prints out how many guesses it
took the computer. Your program has to be able to check if the user is trying to cheat.
Download