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

Write each of these methods in the Unit6Quiz.java class. When you are finished,

ID: 3689956 • Letter: W

Question

Write each of these methods in the Unit6Quiz.java class.
When you are finished, compress the Unit6Quiz NetBeans folder and submit to the dropbox.
Follow the steps provided in the instructions file of the dropbox.

Exercises to be completed:

1. Create a method named getOperands. This method does not return a value. In this
method, prompt the user twice. At the first prompt, ask them to enter a double
variable. Name it operand1. At the second prompt, ask them to enter another double
variable. Name it operand2. Use suitable data validation to ensure the variables
receive a double value. Another data validation is that operand1 and operand 2 use a
positive value of at least 2.00 and less than 40.00. Another data validation is that
operand1 is less than or equal to the value in operand2. Keep prompting the user, if
necessary, until all data validations are passed. (3 points)

2. Now that data validations have been enforced, from getOperands, pass both double
variables to a method named calcPercentage. This method does not return a value. It
should display the first received value (i.e. operand1's value) as a percentage of the
second received value (i.e. operand2's value). For example, if the method receives
numbers of 2.0 and 5.0, the method should output the following to the command line:
"The value of 2.0 is X percent of 5.0." where X is the percentage. (2.5 point)

3. Use method overloading by creating three methods, each named buildName. The first
version of buildName should accept two String values named nameFirst and nameLast.
These are assigned by you in the main method; no user input is needed. The method
should return a String of the name parts in reverse order, separated by a comma and
space. For example, if the first version of buildName receives "Santa" and "Claus",
it should return the following value:
"The full name reversed is: Claus, Santa" (2 points)

4. The second version of buildName should accept a String value named nameFirst, a
character value named nameMI, and a String value named nameLast. These are assigned
by you in the main method; no user input is needed. The method should return a String
of the name parts in reverse order, separated by a comma and space. Append a period
for the middle initial. For example, if the second version of buildName receives
"Santa", "Q", and "Claus", it should return the following value:
"The full name reversed is: Claus, Santa Q." (2 points)

5. The third version of buildName should accept a String value named nameFirst, a
character value named nameMI, a String value named nameLast, and an integer
representing an age. These are assigned by you in the main method; no user input is
needed. The method should return a String of the name and age parts in reverse order,
separated by a comma and space. Append a period for the middle initial and include
the age. For example, if the third version of buildName receives "Santa", "Q", "Claus",
and 42, it should return the following value:
"The full name reversed and age are: Claus, Santa Q. (42 years old)" (2 points)

6. Call each of the methods above from the main method. The pseudocode
for the main method will be as given below. (.5 points)

Get the operands and ensure data validations are passed
Calculate the percentage of the operands
Output the reversed full name and age, depending on the values being provided

Explanation / Answer

Unit6Quiz.java

import java.io.*;
class Unit6Quiz
{
   public static void main(String args[])
   {
       getOperands();
       System.out.println(buildName("Jhon","Oliver"));
       System.out.println(buildName("Jhon",'S',"Oliver"));
       System.out.println(buildName("Jhon",'S',"Oliver",45));
   }

   public static void getOperands()
   {
       try
       {
           InputStreamReader ir=new InputStreamReader(System.in);
           BufferedReader br=new BufferedReader(ir);
           System.out.println("Enter a double value");
           double operand1=Double.parseDouble(br.readLine());
           System.out.println("Enter another double value");
           double operand2=Double.parseDouble(br.readLine());

           if(operand1>2.0 && operand1<40.0 && operand2 > 2.0 && operand2<40.0 && operand1<=operand2)
           {
               calcPercentage(operand1,operand2);
               return;
           }  
           getOperands();
       }
       catch(Exception ex)
       {
           System.out.println("Enter valid double variables");
           getOperands();
       }
      
   }

   public static void calcPercentage(double x,double y)
   {
       double p=(x/y)*100;
       System.out.println("The value of "+x+" is "+p+" percent of "+y+".");
   }

   public static String buildName(String nameFirst,String nameLast)
   {
       String s="The full name reversed is: "+nameLast+", "+nameFirst;
       return s;
   }

   public static String buildName(String nameFirst,char nameMI,String nameLast)
   {
       String s="The full name reversed is: "+nameLast+", "+nameFirst+" "+nameMI+".";
       return s;
   }

   public static String buildName(String nameFirst,char nameMI,String nameLast,int age)
   {
       String s="The full name reversed and age are: "+nameLast+", "+nameFirst+" "+nameMI+". ("+age+"years old )";
       return s;
   }

}

Output:

Enter a double value

2.3

Enter another double value

4.3

The value of 2.3 is 53.48837209302325 percent of 4.3.

The full name reversed is: Oliver, Jhon

The full name reversed is: Oliver, Jhon S.

The full name reversed and age are: Oliver, Jhon S. (45years old )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote