Java Programming Lab 3

Verified

Added on  2019/10/18

|3
|855
|283
Practical Assignment
AI Summary
This Java programming lab assignment involves creating a single Java project with a class named LAB3 to solve five distinct problems. The first two problems require using the Java Math library to calculate the height of a flagpole given an angle of elevation and distance, and the speed of a hot air balloon based on changing angles of elevation. The third problem uses an if statement to calculate an employee's gross pay based on hours worked and hourly rate, accounting for overtime. The fourth problem determines if a five-digit integer is a palindrome without using loops. Finally, the fifth problem calculates a salesperson's earnings based on a base salary and commission on gross sales. The assignment emphasizes using meaningful variable names and adding comprehensive comments to document the code.
Document Page
Run Eclipse, then create a Java project and call it YOURNAME-LAB3 . Replace YOURNAME with your
real name. Add a class to it and name it LAB3.
1. For this lab you will create one project with one class that solves several problems which requires from
you to input some data and then use Java Math library to perform some calculation. These problems
should be solved inside the main method.
2. Think about the possible data types for each data in every problem.
3. Choose names for your variables that make sense, don't use names like r, i, j or any other names that has
one character only. Use good, multi-character, meaningful identifiers (variables) names.
4. Document your work by putting comments at the top of your program. The possible comments that you
need for this program are the program prolog (name of the programmer, the date when s/he finish
working on it and its purpose). In addition to that you have to write some extra comments between the
lines of the code to show why you write your code this way. Remember that comments in Java are either:
Starts with // in case the comment is one line only
Between /* and */ if the comment is taking more than one line
Problem 1: (Flagpole Height)
A person stands 150 ft away from a flagpole and measures an angle of elevation of 32? from his horizontal
line of sight to the top of the flagpole. Assume that the person’s eyes are a vertical distance of 6 ft from the
ground. Write a java program that find the height of the flagpole? Hint: Do your calculation on paper first then
write the code. You have to use the MATH class to help you solving this problem. - Think about the function
you need to use based on the given infromation -
Problem 2: (Balloon Speed)
The angle of elevation of a hot air balloon, climbing vertically, changes from 25 degrees at 10:00 am to 60
degrees at 10:02 am. The point of observation of the angle of elevation is situated 300 meters away from the
take-off point. What is the upward speed, assumed constant, of the balloon? Give the answer in meters per
second and round it to two decimal places. You have to use the MATH class to help you solving this problem
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
- Think about the function you need to use based on the given infromation -
Problem 3: (Salary Calculator)
You have to write some Java code that uses the if statement to determine the gross pay for an employee.
The company pays “straight time” for the first 40 hours worked by each employee and pays “time-and-a-half”
for all hours worked in excess of 40 hours. Your code should ask the user to input an employee name -use
ScannerName.nextLine-, the number of hours s/he worked last week and the hourly rate. Your program
should determine and display the employee’s gross pay (rounded to 2 decimal points). The following are
some examples
Enter employee Name: Smith John
Enter hours worked: 39
Enter hourly rate of the employee ($00.00): 7.5
Salary is $292.50
Enter employee Name: Smith John
Enter hours worked : 40
Enter hourly rate of the employee ($00.00): 10.00
Salary is $400.00
Enter employee Name: Smith John
Enter hours worked: 41
Enter hourly rate of the employee ($00.00): 13.00
Salary is $539.5
Document Page
Problem 4: (Palindromes)
A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of
the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads
in a five-digit integer and determines whether it’s a palindrome. [Hint: Use the division and modulus
operators to separate the number into its individual digits. dont use loop or I will consider that as cheating
from the internet.]
Problem 5: (Sales Commission Calculator)
A large company pays its salespeople on a commission basis. The salespeople each receive $200 per week
plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals
in a week receives $200 plus 9% of $5000, or a total of $650. Develop a Java program that input each
salesperson’s gross sales for last week and calculates and displays that salesperson’s earnings.
Enter sales in dollars : 5000.00
Salary is: $650.00
Enter sales in dollars : 6000.00
Salary is: $740.00
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]