Wednesday, September 23, 2009

Java Simple Program

Exercise 1

Extend tax1 activity so that the program can handle a number of items larger than 1. Display pre-tax total, tax amount and total in a form of store receipt. The program still doesn't have to be interactive.

Exercise 2

You need to create a bill of sale for a computer store that sells PCs, printers, monitors, Hard Disks and RAM. Use the following prices : 
PC $999.00 
Printer $199.00 
Monitor $399.00 
RAM per Mb $0.20 
HD per Gb $1.00 
Ask the user how many of each they want to purchase. Assume that sales tax is 7.5%. 
Interactive Session Example: 
(prompt ‘>’ denotes output provided by your program (to distinguish it from user provided data – it should not be printed by your program) : 
>How many PCs do you want to purchase ? 

>How many printers do you want to purchase ? 

>How many monitors do you want to purchase ? 

>How many Mb of RAM do you need ? 
64 
>How many Gb of hard disk space do you need ? 


> ***************** 
> * Bill of Sales * 
> ***************** 

>Qty. Item Unit price Total price 
>------------------------------------------------------- 
> 02 PC $999.00 $1998.00 
> 03 printer $199.00 $0597.00 
> 02 monitor $399.00 $0798.00 
> 64 RAM $004.00 $0256.00 
> 04 HD $099.00 $0396.00 
>------------------------------------------------------- 
> Total without tax $4045.00 
> Tax $0303.38 
> Total with tax $4348.38 
Note - the above represents just the form of your output. Numerical values are not necessarily correct. 
It is important that your decimal points align.

Exercise 3

Write a program that solves quadratic equation. Given coefficients a, b and c, calculate solutions x1 and x2 according to the following formula:
   
Your program needs to correctly handle the following cases:
• coefficient a equal to 0 
• discriminant equal to 0 
• discriminant less than 0 

________________________________________
Example 1:

>Enter a:
1
>Enter b:
5
>Enter c:
6

Solutions to equation 1.0*x^2 + 5.0*x + 6.0 = 0 are -2.0 and -3.0
________________________________________
Example 2:

>Enter a:
0
>Enter b:
3
>Enter c:
6

Solution to equation 3.0*x + 6.0 = 0 is -2.0
________________________________________
Example 3:

>Enter a:
1
>Enter b:
2
>Enter c:
3

Solutions to equation 1.0*x^2 + 2.0*x + 3.0 = 0 are not real 
________________________________________
Example 4:

>Enter a:
1
>Enter b:
2
>Enter c:
1

Solution to equation 1.0*x^2 + 2.0*x +1.0 = 0 is -1.0

No comments:

Post a Comment