First Assignment

advertisement
Assignment 1 : Submission date 12th of November 2012
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 a program Calculations.java that takes three argument line integers and prints, the sum, the
multiplication, and average of these three numbers.
Question 2
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 3
During a special sale at a store, a 10% discount is taken on purchases over $10.00. Write a program
Discount.java that asks for the amount of purchases, and then calculates the discounted price. The
purchase amount will be input in cents (as an integer):
Enter amount of purchases:
2000
Discounted price: 1800
Use integer arithmetic throughout the program.
Question 4:
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 5
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.
Download