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

Create an application named Percentages whose main() method holds two double var

ID: 644619 • Letter: C

Question

Create an application named Percentages whose main() method holds two double variables. Assign values to the variables. Pass both variales to a method named computePercent() that displays the two values and the value of the first number as a percentage of the second one. Then call the method a second time, passing the values inreverse order. Save as Percentages.java

I'm prety much done, I just need this modified to NOT prompt the user for any information. Thank you

public class Percentages {

   public static void main(String[] args) {
       String inputNumber;
       double number1;
       double number2;
      
       inputNumber = JOptionPane.showInputDialog(null,"Plese enter the first number");
       number1 = Double.parseDouble(inputNumber);
       inputNumber = JOptionPane.showInputDialog(null,"Plese enter the second number");
       number2 = Double.parseDouble(inputNumber);
      
       computePercent(number1,number2);
       computePercent(number2,number1);

   }

   public static void computePercent(double num1, double num2)
   {
       JOptionPane.showMessageDialog(null,num1 + " is " + num1/num2*100 + "% of " + num2);

   }

}

Thank you

Explanation / Answer

public class Percentages {

public static void computePercent (int a,int b)

{

System.out.println(a+" is "+(a*100/b)+"% of "+b);   

}

  

public static void main(String []args)

{

int a=2;

int b=5;

computePercent(a,b);

computePercent(b,a);

}

}

Part(b)

import java.util.*;

public class Percentages {

public static void computePercent (int a,int b)

{

System.out.println(a+" is "+(a*100/b)+"% of "+b);

}

  

public static void main(String []args)

{

Scanner s= new Scanner(System.in);

int a=s.nextInt();

int b=s.nextInt();

computePercent(a,b);

computePercent(b,a);

}

}

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