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

First Five Machine Problems

The document contains 20 machine problems in Java involving iterative statements, conversions between units, and selection/decision statements. The problems cover calculating products by repeated addition, Fibonacci sequences, sums of series, unit conversions for time, weight, distance and more. They also include problems that calculate values based on conditional logic like discounts, grades, fines based on thresholds.

Uploaded by

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

First Five Machine Problems

The document contains 20 machine problems in Java involving iterative statements, conversions between units, and selection/decision statements. The problems cover calculating products by repeated addition, Fibonacci sequences, sums of series, unit conversions for time, weight, distance and more. They also include problems that calculate values based on conditional logic like discounts, grades, fines based on thresholds.

Uploaded by

Gerald Gavina
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

First Five Machine Problems (Iterative Statements) 1.

Write a program that will compute the product of two positive integers(firstno and secondno) by adding them repeatedly. This means adding firstno to itself secondno times. 2. Modify exercise number 1 and allow positive and negative numbers as inputs to be multiplied. Hint: Take absolute values first then use condition statements. 3. Write a program that gets the Fibonacci of a number read from the user. The Fibonacci number sequence begins with 1. 1 then each succeeding number in the sequence is the sum of the previous ones. For example, an input of 5 will produce 1,1,2,3,5 and an input of 8 will produce 1,1,2,3,5,8,13,21 and an input of 2 will produce 1,1. 4. Write a program that will derive the sum of series of a number for example an input of 5 will produce (1+2+3+4+5=15). 5. Write a program that will derive the sum of the square of series of a number. For example, an input of 5 will produce 55(1^2+ 2^2+3^2+4^2+5^2 =55).

Machine Problems in Java (Set 1) 1-18 Problem #1: Write a program that reads three total purchases of soap bars from different groceries plus the number of pieces for every purchase. Compute and display the cost per piece of soap bars in the groceries. Problem #2: Write program to convert a measurement in centimeter to feet and inches. The number of centimeters should be read as input. There are 2.54 centimeters in each inch and 12 inches in each foot. Problem #3: Write a program to accept the total salary of a laborer and the number of days that the laborer has worked for the total salary. Compute and display his average earning a day. Problem #4: Write a program to read two purchases of gasoline from different gas station and the number of liters for each purchase. Compute and display the cost per liter of gasoline in the station. Problem #5: Write a program that will read a weight in pounds and convert it to grams. Print both the original weight and the converted value. There are 454 grams in a pound Problem #6: Write a program that will convert the read-in time in seconds to number of hours, minutes and seconds. Ex. 4523 seconds is equal to 1hour, 15 minutes and 23 seconds. Problem #7: Write a program that will derive the number of years, months and days from an input in days. Ex. 410 days is equal to 1 year, 1 month and 14 days. Problem #8: Write a program that will get the double, square and half of a number supplied. Problem #9: Write a program that reads the total number of pieces of oranges, eggs, apples, watermelons and bagels they purchased. Calculate the total bill and subtotals for each item using the following prices. a. Oranges: 10 for 2.99 b. Eggs: 12 for 1.69

c. Apples: 3 for 1.00 d. Watermelons: 4.39 for each e. Bagels: 6 for 3.50 Problem #10: Write a program that will read two integers. Get their halves, quarter, double and square. Problem #11: Write a program that reads three total purchases of soap bars from different groceries plus the number of pieces for every purchase. Compute and display the cost per piece of soap bars in the groceries. Problem #12: Using the conversion below, create an application that will ask for a pint value and will display its equivalence in gill, quarts and gallon. 1 pint = 4 gills = 1/2 quarts = 1/8 gallon Problem #13: Write a program that will get a radius of circle and will compute the diameter, circumference and area of the circle. Diameter=radius * 2 Circumference=PI * diamerter Area= PI * r^2 Problem #14: Write a program that will get a diameter of sphere and print out the value of four properties of the sphere given a diameter. Properties of the Sphere: a. radius=diameter/2 b. surface area = 4 x PI X r^2 c. Circumference= PI * d d. Volume = ((4 * PI)/3) x r ^ 3 Problem #15: Convert a distance from miles to kilometers. There are 5,280 feet per mile, 12 inches per foot, 2.54 centimeters per inch and 100,000 centimeters per kilometer. Problem #16: Write a program that will read the base and height value of the triangle and will compute its area. Problem #17: Write a program that prompts the user to input the length and width of a rectangle and prints the rectangles area and perimeter. Problem #18: Write a program that inputs a number of hours and output the equivalent number of weeks, days and hours. Ex. 197 hours is equal to 1 week, 1 day and 5 hours.

Java PROBLEMS: (Selection or Decision)

1. Any customer whose total purchase is at least P1000.00 will be given a 5% discount. Write a Java program that reads in the customers purchase and output the amount to be paid. 2. Write a Java program that reads in an integer and output a message telling whether the number is Positive, Negative, or Zero.

3. Write a Java program that reads in an integer and output a message telling whether the number is Even or Odd. 4. Write a Java program that reads in an integer and output a message telling whether the number is Divisible by 5. 5. Write a Java program that reads in two integers and output the message telling whether the sum and product of the two numbers are Positive, Negative, or Zero. 6. Assume that the cost for sending a letter from the Philippines to New York is P25.00 for the first 10 grams or less, plus P6.50 for each additional gram, plus a tax of 3%. Write a Java program that reads in the weight of a letter (in grams) and then calculate the cost. 7. ABC Bank imposes a service charge on its clientele based on the following table: Balance at end of month P0-P999 P1000-P1999 P2000-P2999 P3000-P4999 P5000 or more P3.25 P2.25 P1.25 P0.00 Service Charge P4.25

Write a Java program that reads in customers account number, name, and ending balance, and then output the service charge and the net amount.

8. Write a program that reads in a students average grade in Computer and then output his grade standing based on the following scheme: Average Grade Below 75 At least 75 but below 85 At least 85 but below 95 At least 95 Grade standing Failed Satisfactory Very Satisfactory Excellent

9. In a certain city if you get a speeding ticket, your fine is based on the amount by which you exceeded the speed limit. Amount over limit (miles per hour) 1-10 mph 1-20 mph 21-30 mph 31-40 mph above 41 mph $80 Fine $5 $10 $20 $40

Given the speed limit and the speed arrested at, print the fine.

10. In 1998, Bureau of Internal Revenue proposed an overhaul of the Income Tax Law. They proposed the following schedule: Income P0 to P5000 P50001 to P10000 P10001 to P25000 P25001 to P50000 Over P50000 Tax Rate P0 P100 + 3% of income over P5000 P200 + 6% of income over P10000 P300 + 9% of income over P25000 P500 + 15% of income over P50000

Write a Java program that would input the users income and then output his tax.

You might also like