Plz answer all the questions on both pictures

ooo cricket 1:58 AM isidore.udayton.edu 17_FA CPS 150 N1 HW Assigns >Homework Assignment 1: Intro to Java Programming > CPS 150 Homewor R2.21 You are cutting off a piece of pie like this, where c is the length of the straight part (called the chord length) and h is the height of the piece. There is an approximate formula for the area: A ch 2c However, h is not so easy to measure, whereas the diameter d of a pie is usually well-known. Calculate the area where the diameter of the pie is 12 inches and the chord length of the segment is 10 inches. Generalize to an algorithm that yields the area for any diameter and chord length. R2.25 For each of the following computations in Java, determine whether the result is exact, an overflow, or a roundoff error. . a. 2.01.1 b. 1.0E61.0E6 C. 6553665536 d. 1 000 000L1 000 00OL R2.26 Write a program that prints the values . 3100010001000 3.0 * 1000 * 1000 * 1000 Explain the results. R2.27 This chapter contains a number of recommendations regarding variables and constants that make programs easier to read and maintain. Briefly summarize these .

2.21 Calculation of h:

We know that h is the altitude, therefore the angle made by the line segment h on chord c is 90 degree. We know if radius is perpendicular to a chord then it bisects the chord. So by pythagoras theorem we can calculate the length of h as:

r2 = (c/2)2 + (r-h)2

(r-h)2 = r2 – (c/2)2

r-h = $\sqrt{}$(r2-(c/2)2)

h = r – $\sqrt{}$(r2-(c/2)2)

//Program to calculate the area given the diameter and chord_length

import java.io.*;

public class CalArea {

// function to calculate value of h and then calculate the area

double calculateArea(int diameter,int chord_length)

{

double h = 0;

l = Math.sqrt(l);

double area = ((2*chord_length*h)/3) + (Math.pow(h, 3)/(2*chord_length));

return area;

// end of calculateArea

public static void main(String[] args) {

CalArea a = new CalArea();

double area =a.calculateArea(12,10);// 12 is the diameter and 10 is the chord length

System.out.println(“Area =”+area); //print the resultant area

// end of main

// end of class

Output:

R2.25 (a) 2.0-1.1 = 0.8999999999999999

We get that the result contins round-off error, as 2.0-1.1 = 0.9 but we obtain the result as 0.8999999999999999, which contains round-off error.

(b) 1.0E6 * 1.0E6 = 1.0E12

We get that the result is exact since 1.0E6 * 1.0E6 = 1.0E(6+6) = 1.0E12

(c) 65536 * 65536 = 0

We get that the result is an overflow since the max int result java can represent is 231 -1 . Since the result is greater than 231-1, so it goes back to the minimum value and continues from there.

(d) 1_000_000L * 1_000_000L = 1000000000000

We get that the result is an exact as it is multiplication of long values (specified by L), and not int multiplication and so overflow doesn’t occur.

R2.26  3*1000*1000*1000 = -1294967296 —–1

3.0*1000*1000*1000 = 3.0E9 —–2

• In 1, we see that we get negative result, it is because the result overflows as it is int multiplication and the result is greater than 231-1. So it goes back to the minimum value i.e -2147483648 and continues from there.
• In 2 , we get an exact result because it involves multiplication of double values.Hence the result doesn;t overflow since maximum number that can be represented by double is 263-1. and the result is less than the maximum number so it returns the exact result.

R2.27 Recommendations regarding variables and constants that make programs easier to read and maintain are:

• Variables declared in the programs must be initialized as this can cause errors.
• Variable declaration must have the below structure:

<type><variable_name> = <value according to the type of the variable>

• There are several types of numbers : short,int,long,float,double. Do not use comma as a decimal separator
• Do not use fractions , use decimal notation
• When a variable anme is selected, it should be picked in such a way that it explains its purpose
• Variable names should start with a letter or underscore character and remaining characters must be letters, numbers or underscores
• Spaces are not permitted in variable names
• Variable names are case-sensitive
• Reserved keywords cannot be used for variable names
• Variable should be declared before it is used, else it causes error
• When variables are declared as final, it becomes constants. Constants are usually written in capital letters to distinguish it from variables.
• Use named constants to explain the meaning of numeric constants in programs

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.