Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following program segment: public Ch7_Ex3 { public static void main

ID: 3621537 • Letter: C

Question

Consider the following program segment:

public Ch7_Ex3
{
public static void main(String[] args)
{
int num;
double dec;
}

public static int one(int x, int y)
{

}

public static double two(int x, double a)
{
int first;
double z;

}
}

a. Write the definition of method one so that it returns the sum of x and y if x is greater than y; otherwise, it should return x minus 2 times y.

b. Write the definition of method two as follows:
1. Read a number and store it in z.
2. Update the value of z by adding the value of a to its previous value.
3. Assign the variable first the value returned by method one with the parameters 6 and 8.
4. Update the value of first by adding the value of x to its previous value.
5. If the value of z is more than twice the value of first, return z; otherwise return 2 times first minus z.

c. Write a java program that tests parts a and b

Explanation / Answer

please rate - thanks

some things were not clear. hope this is good

import java.util.*;
public class CH7_Ex3
{
public static void main(String[] args)
{
int num;
double dec;
dec=two(1,2.0);
System.out.println("The value is "+dec);
}

public static int one(int x, int y)
{int ans;
if(x>y)
   ans=x+y;
else
   ans= x-(2*y);
return ans;
}

public static double two(int x, double a)
{
int first;
double z;
Scanner in=new Scanner(System.in);
System.out.print("Enter a value for z: ");
z=in.nextDouble();
z+=a;
first=one(6,8);
first+=x;
if(z>first*2)
    return z;
else
    return 2*first-z;
}
}