Assignment 1 DataTypes
Assignment 1 DataTypes
1- Dozens of Apples
Write a java program that for a given number of apples, tells the user how many dozens of apples(s) he has and how many extra apples are left over. For example: if the number of apples = 40, the output should be: 3 dozens and 4 apples
2- Pythagorean Theorem
The Pythagorean Theorem states that the sum of the squares of the two sides of the right angle triangle is equal to the square of the hypotenuse. For example: 3, 4 and 5 are sides of the right angle triangle as they form a Pythagorean Triple (52 = 42 + 32) Given 2 numbers, m and n where m >= n, a Pythagorean Triple can be generated by the following formulae:
Write a java program that prints the values of the Pythagorean Triple generated by the formulae above, given m and n. Hint: To calculate the square root and the power, use the class Math which contains the methods Math.sqrt(x) and Math.pow(x,n)
3- Resistance (simplify)
Page 1
The equivalent resistance of resistors connected in series is calculated by adding the resistances of individual resistors. Req = R1 + R2 The formula for resistors connected in parallel is a little more complex. Given two resistors with resistances R1 and R2 connected in parallel the equivalent resistance is given by the inverse of the sum of the inverses:
Write a program that given 2 resistances (R1,R2) outputs the equivalent resistance (Req) when they are connected in series and when they are connected in parallel.
4- Count Change
Write a Java program CountChange to count change. Given the number of quarter, dimes, nickels and cents the program should output the total as a single value in dollars and cents. Hint: One dollar corresponds to 100 cents One quarter corresponds to 25 cents One dime corresponds to 10 cents One nickel corresponds to 5 cents
For example if we have: 3 quarters, 2 dimes, 1 nickel and 6 cents, the total is 1.06 dollars.
5- Strings
6- Stars
Page 2
Write a program that output the following: ***** ****** * * * * * * * * * ***** ****** ****** * * * * * * ****** ****** * ***** * ******
Page 3