Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with all of these java programs 1. Geometrical problem: area of a triangle: Write, compile and run a Java program called AreaOfTriangle.java that

Need help with all of these java programs

1. Geometrical problem: area of a triangle: Write, compile and run a Java program called AreaOfTriangle.java that prompts the user to enter three points in Cartesian coordinates (x1, y1), ( x2, y2), ( x3, y3) of a triangle and calculates its area based on the user input values. The program then displays the calculated area. The formula for computing the area of a triangle is s = (side1 + side2 + side3)/ 2; (s is the semi-perimeter of the triangle) area = ?s( s - side1)( s - side2)( s - side3) Any side would involve finding out the distance between a pair of points. The distance between two points with coordinates (x1, y1) and (x2, y2) can be found out by the formula s = ?( x2 - x1) 2 + ( y2 - y1) 2 10x1 Sample output (The print in blue is generated by the program while running and the one in green is what the user provides as input): First Run This program reads in the x and y coordinates of the three points of a triangle and calculates the area of the triangle based on the coordinates. -------------------------------------------------- Enter the x and y coordinates of the first point: 1.0 1.0 Enter the x and y coordinates of the second point: 1.0 5.0 Enter the x and y coordinates of the third point: 5.0 1.0 The first side is: 4.0 units The second side is: 5.656854249492381 units The third side is: 4.0 units The area of the triangle is: 7.999999999999997 square units Second Run This program reads in the x and y coordinates of the three points of a triangle and calculates the area of the triangle based on the coordinates. -------------------------------------------------- Enter the x and y coordinates of the first point: 2.5 3.6 Enter the x and y coordinates of the second point: 5.75 4.96 Enter the x and y coordinates of the third point: 3.2 9.8 The first side is: 3.523081037955272 units The second side is: 5.470658095695618 units The third side is: 6.2393909959226 units The area of the triangle is: 9.599000000000004 square units 2. Sum the cubes of digits in an integer number: Write, compile and run a Java program called SumDigitCubes.java that reads an integer between 0 and 1000 and adds the cubes of all the digits in the integer. For example, if an integer is 432, the sum of the cubes all its digits is 4 3 + 33 + 23 = 64 + 27 + 8 = 95. [Hint: Use the % operator to get the digits]. 10 points First Run Enter an integer between 0 and 1000: 432 8 27 64 The sum of the digits in 432 is 99 Second Run Enter an integer between 0 and 1000: 349 729 64 27 The sum of the digits in 349 is 820 3. Generating the paystub: Write, compile and run a Java program called PaystubPrinting.java that reads the following information as user input through keyboard and prints a paystub statement: Employees name ( e. g., Robert), Number of hours worked in a week ( e. g., 10), Hourly pay rate ( e. g., 6.75), Federal tax withholding rate ( e. g., 20% for men or 15% for women), and State tax withholding rate ( e. g., 9%). Formatting Money Amounts with printf (Check the Week 4 section on eLearning to know more about printf) ? A good format specifier for outputting an amount of money stored as a double type is %.2f ? It says to include exactly two digits after the decimal point and to use the smallest field width that the value will fit into: double price = 4.56; System.out.printf("The price is $%.2f each.", price) produces the output: The price is $4.56 each. Sample Run Enter employee's name: Robert Enter number of hours worked in a week: 40 Enter hourly pay rate: 12.5 Enter federal tax withholding rate: .20 Enter state tax withholding rate: .09 ----------------------------------------------- WEEKLY PAYSTUB Employee Name: Robert Hours Worked: 40.00 Pay Rate: $12.50 Gross Pay: $500.00 Deductions: Federal Withholding (20.0%): $100.00 State Withholding (9.0%): $45.00 Total Deduction: $145.00 Net Pay: $355.00 ----------------------------------------------- Second Run Enter employee's name: Liz Enter number of hours worked in a week: 40 Enter hourly pay rate: 22 Enter federal tax withholding rate: 0.15 Enter state tax withholding rate: 0.09 ----------------------------------------------- WEEKLY PAYSTUB Employee Name: Liz Hours Worked: 40.0 Pay Rate: $22.0 Gross Pay: $880.0 Deductions: Federal Withholding (20.0%): $132.00 State Withholding (9.0%): $79.20 Total Deduction: $211.20 Net Pay: $668.80 -----------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

Students also viewed these Databases questions