0% found this document useful (0 votes)
115 views

Assignment 1 DataTypes

The programming assignment document outlines 6 programming problems: 1) A program to calculate dozens and leftover apples given a number of apples 2) A program to output a Pythagorean triple given two numbers using a formula 3) A program to calculate equivalent resistance for resistors in series and parallel given two resistances 4) A program to calculate total change value in dollars and cents given numbers of quarters, dimes, nickels, and cents 5) A program to print a single line of text 6) A program to output a pattern of stars

Uploaded by

Amira ELbaroudi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Assignment 1 DataTypes

The programming assignment document outlines 6 programming problems: 1) A program to calculate dozens and leftover apples given a number of apples 2) A program to output a Pythagorean triple given two numbers using a formula 3) A program to calculate equivalent resistance for resistors in series and parallel given two resistances 4) A program to calculate total change value in dollars and cents given numbers of quarters, dimes, nickels, and cents 5) A program to print a single line of text 6) A program to output a pattern of stars

Uploaded by

Amira ELbaroudi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Assignment #1

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

Write a single write statement that prints:

6- Stars

Page 2

Write a program that output the following: ***** ****** * * * * * * * * * ***** ****** ****** * * * * * * ****** ****** * ***** * ******

The Code Masry Project www.codemasry.com

Page 3

You might also like