Java Programming Exercises 15 Questions

Compiled By Unknown - No Comments
  1. Annual Bonus ─ Flowchart *:
  2. Assume a company pays an annual bonus to its employees. The bonus is based on the number of years the employee has been with the company. Employees working at the company for less than 5 years receive a bonus equal to 1% percent of their salary; all others receive a bonus equal to 2% of their salary. Provide a flowchart which shows how an employee’s bonus is calculated. Include reading in appropriate data and printing an output message that mimics the format of the following message, where <bonus-value> represents the numeric value for the bonus: Congratulations! Your bonus is $<bonus-value>. Don’t forget the “$” and the closing period.
  3. Annual Bonus ─ Pseudocode *:
  4. Assume a company pays an annual bonus to its employees. The bonus is based on the number of years the employee has been with the company. Employees working at the company for less than 5 years receive a bonus equal to 1% percent of their salary; all others receive a bonus equal to 2% of their salary. Write pseudocode which shows how an employee’s bonus is calculated. Include reading in appropriate data and printing an output message that mimics the format of the following message, where <bonus-value> represents the numeric value for the bonus: Congratulations! Your bonus is $<bonus-value>. Don’t forget the “$” and the closing period.
  5. Number of Stamps ─ Flowchart *:
  6. Whenever you mail a letter, you must decide how much postage to put on the envelope. You like to use this rule of thumb – use a stamp for every five sheets of paper or fraction thereof. For example, if you have 11 sheets of paper, then you use three stamps. Since you’re parsimonious, if an envelope requires more than three stamps, then you simply don’t mail the envelope. Show how the number of stamps per envelope would be calculated. Provide a solution in the form of a flowchart. In your flowchart, you must read in appropriate data and print how many stamps to use.
  7. Number of Stamps ─ Pseudocode *:
  8. Whenever you mail a letter, you must decide how much postage to put on the envelope. You like to use this rule of thumb – use a stamp for every five sheets of paper or fraction thereof. For example, if you have 11 sheets of paper, then you use three stamps. Since you’re parsimonious, if an envelope requires more than three stamps, then you simply don’t mail the envelope. Show how the number of stamps per envelope would be calculated. Provide a solution in the form of pseudocode. Your pseudocode must read in appropriate data and print how many stamps to use.
  9. Five Kingdoms ─ Pseudocode **:
  10. The following rules describe how to categorize living organisms into one of five kingdoms – Monera, Protoctista, Plantae, Fungi, Animalia. a) If the organism has no cell nucleus, then it’s in the Monera kingdom (more commonly known as bacteria). b) If the organism does not fit into the above category, and it’s single celled, then it’s in the Protoctista kingdom (molds and algae). c) If the organism does not fit into either of the above categories, and it’s photosynthetic, then it’s in the Plantae kingdom (plants). d) If the organism does not fit into any of the above categories, and it has a nervous system, then it’s in the Animalia kingdom (animals). e) Otherwise, if the organism does not fit into any of the above categories, it’s in the Fungi kingdom (fungus). Provide a pseudocode algorithm that uses this categorization scheme to determine the kingdom for a particular living organism. More specifically, read in characteristics as needed (like whether the organism has a cell nucleus, whether it is single celled, etc.) that help to determine which kingdom a particular living organism fits into and then print the organism’s kingdom. Hint: Use a series of nested “if, else” statements. Inside each else section, prompt for an additional characteristic and then start the next “if, else” statement. Here’s the first part of the solution: print “cell nucleus? (y/n): ” input cellNucleus if cellNucleus equals “n” print “Monera” else print “single celled? (y/n): ” input singleCelled if singleCelled equals “y” …
  11. Speed of Sound ─ Flowchart *:
  12. The following table provides the speed of sound waves in several materials: Material Sound Velocity iron 5950 meters/sec polystyrene 2350 meters/sec water 1531 meters/sec air 331.5 + 0.6 x T meters/sec, where T is the temperature in degrees Celsius Draw a flowchart that uses this table to calculate the speed of sound in various materials. More specifically, read in a material value and output the speed of sound in that material. For air calculations, you’ll need to read in a second value – temperature in degrees Celsius.
  13. Speed of Sound ─ Pseudocode *:
  14. The following table provides the speed of sound waves in several materials: Material Sound Velocity iron 5950 meters/sec polystyrene 2350 meters/sec water 1531 meters/sec air 331.5 + 0.6 x T meters/sec, where T is the temperature in degrees Celsius Write pseudocode that uses this table to calculate the speed of sound in various materials. More specifically, read in a material value and output the speed of sound in that material. For air calculations, you’ll need to read in a second value – temperature in degrees Celsius.
  15. Stock Market Return ─ Flowchart **:
  16. Stock market analysts sometimes characterize stock market growth using the terms bear, stagnant, bull, and boom. A bear market refers to a market with significant negative growth. A stagnant market refers to a market with little negative or positive growth. A bull market refers to a market with significant positive growth. A boom market refers to a market with very high growth. Stock market growth varies widely from year to year, and the following table presents evidence of that phenomenon. The table documents annual rate of return statistics for the S&P 500 stock market index during the 40-year period, 1951─1990. The table’s first row shows that an annual return rate of less than -10% occurred 10% of the time. The volatility of stock market growth is evidenced by the fact that “stagnant markets” (annual return rates between -10% and +10%) only occurred 30% of the time. Probability That Annual Return on Market Range of Return Investment Falls within The Range bear less than -10% 10% stagnant between -10% and +10% 30% bull between +10% and +30% 43% boom greater than +30% 17% Draw a flowchart for an algorithm that uses this table to print the type of market that exists for a given annual return on a stock market index. More specifically, read in an annual return value and print this message: The rate of return is indicative of a ____ market (which occurs ____ of the time). Replace the first blank with one of the four market categories. Replace the second blank with the appropriate value from the table’s third column.
  17. Stock Market Return ─ Pseudocode **:
  18. Stock market analysts sometimes characterize stock market growth using the terms bear, stagnant, bull, and boom. A bear market refers to a market with significant negative growth. A stagnant market refers to a market with little negative or positive growth. A bull market refers to a market with significant positive growth. A boom market refers to a market with very high growth. Stock market growth varies widely from year to year, and the following table presents evidence of that phenomenon. The table documents annual rate of return statistics for the S&P 500 stock market index during the 40-year period, 1951─1990. The table’s first row shows that an annual return rate of less than -10% occurred 10% of the time. The volatility of stock market growth is evidenced by the fact that “stagnant markets” (annual return rates between -10% and +10%) only occurred 30% of the time. Probability That Annual Return on Market Range of Return Investment Falls within The Range bear less than -10% 10% stagnant between -10% and +10% 30% bull between +10% and +30% 43% boom greater than +30% 17% Write pseudocode for an algorithm that uses this table to print the type of market that exists for a given annual return on a stock market index. More specifically, read in an annual return value and print this message: The rate of return is indicative of a ____ market (which occurs ____ of the time). Replace the first blank with one of the four market categories. Replace the second blank with the appropriate value from the table’s third column.
  19. Bank Balance ─ Pseudocode **:
  20. The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows: • The bank doubles the customer’s balance every year until the customer’s balance reaches one million. • The customer isn’t allowed to touch the money (no deposits or withdrawals) until the customer’s balance reaches one million. • If the customer dies before becoming a millionaire, the bank keeps the customer’s balance. • (Note: Customers close to $1,000,000 tend to get run over in the bank’s parking lot.) Write an algorithm (using pseudocode) that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000. (Hint: You can use “and” to form a compound condition.) Sample session: Enter starting balance: 10000 It takes 4 years to reach $100,000. It takes 7 years to reach $1,000,000.
  21. Loop Termination by User Query ─ Flowchart **:
  22. Draw a flowchart for an algorithm that calculates and prints the overall MPG (miles per gallon) for a series of miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons value. Within the loop, accumulate miles and gallons separately. The algorithm should generate a display of prompts, inputs, and final output that looks like this: Sample session: Do you want to calculate miles per gallon? (y/n): y Enter miles: 35 Enter gallons: 1 Do you want to continue? (y/n): y Enter miles: 36 Enter gallons: 1 Do you want to continue? (y/n): n Overall MPG = 35.5 Provide a graceful response if the total gallons equals zero.
  23. Loop Termination by User Query ─ Pseudocode *:
  24. Write pseudocode for an algorithm that calculates and prints the overall MPG (miles per gallon) for a series of miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons value. Within the loop, accumulate miles and gallons separately. The algorithm should generate a display of prompts, inputs, and final output that looks like this: Sample session: Do you want to calculate miles per gallon? (y/n): y Enter miles: 35 Enter gallons: 1 Do you want to continue? (y/n): y Enter miles: 36 Enter gallons: 1 Do you want to continue? (y/n): n Overall MPG = 35.5 Provide a graceful response if the total gallons equals zero.
  25. Loop Termination by Sentinel Value ─ Pseudocode **:
  26. Write a pseudocode algorithm that calculates and prints the overall MPG (miles per gallon) for a series of miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons value. Within the loop, accumulate miles and gallons separately. Use a sentinel value of -999 for the miles value to determine whether looping should terminate. The algorithm should generate a display of prompts, inputs, and final output that looks like this: Sample session: Enter miles (-999 to quit): 40 Enter gallons: 2 Enter miles (-999 to quit): -999 Overall MPG = 20 Provide a graceful response if the total gallons equals zero.
  27. Loop Termination by Counter ─ Pseudocode *:
  28. Write a pseudocode algorithm that calculates and prints the overall MPG (miles per gallon) for a series of miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons value. Within the loop, accumulate miles and gallons separately. Use a counter loop to ensure that the loop repeats three times. The algorithm should generate a display of prompts, inputs, and final output that looks like this (italicized values are user inputs): Sample session: Enter miles: 10 Enter gallons: 1 Enter miles: 20 Enter gallons: 2 Enter miles: 10 Enter gallons: 2 Overall MPG = 8 Provide a graceful response if the total gallons equals zero.
  29. Average Weight ─ Pseudocode **:
  30. A program often checks data before using it. A good prompt frequently includes a limit specification, and if the data is not reasonable, the program can indicate that by simply repeating the prompt, thereby asking for the same data again. Suppose you want to compute the average weight of a group of items. To do this, initialize cumulativeWeight to 0, count to 0, and more to ‘y’. Then enter a loop that repeats while more equals ‘y’. Just before the end of this loop include a prompt asking “more? (y/n): ” and input the user’s answer. Inside this (outer) loop, increment count and print it out to tell the user the number of the next item. Then preset the input variable to some unacceptable value. For example, set weight to 1, and enter a second (inner) loop that repeats while weight is less than or equal to 0. In the inner loop, print “Enter kg weight greater than zero: ” and then input a value for the weight. This inner loop should automatically repeat until the input is valid. After this inner loop terminates, add the (valid) input to cumulativeWeight. After an ‘n’ input for more terminates the outer loop, compute the average by setting weight to cumulativeWeight / count, and print it out. Here is a typical interactive display: Sample session: Item number 1: Enter kg weight (greater than zero): 1.23 more? (y/n): y Item number 2: Enter kg weight (greater than zero): 2.78 more? (y/n): y Item number 3: Enter kg weight (greater than zero): -0.95 Enter kg weight (greater than zero): 0.95 more? (y/n): n Average weight = 1.6533333333333333 kg Use pseudocode to write the algorithm for a program that is able to generate the above display.

Tags:

No Comment to " Java Programming Exercises 15 Questions "