Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 3, Problem 5PE

Explanation of Solution

a.

Program code:

Percentages.java

//import the requird packages

import java.io.*;

//define a class Percentages

class Percentages

{

//define a method computePercent()

public static void computePercent(double num1,double num2)

{

//print the percentage values

System.out.println(num1+" is "+((num1/num2)*100)+" percent of "+num2+".");

}

//define the main method

public static void main (String[] args)

{

//declare two double values

double num1=2.0,num2=5...

Explanation of Solution

b.

Program code:

Percentage2.java

//import the requird packages

import java.util.Scanner;

import java.io.*;

//define a class Percentages

class Percentage2

{

//define a method computePercent()

public static void computePercent(double num1,double num2)

{

//print the percentage values

System.out.println(num1+" is "+((num1/num2)*100)+" percent of "+num2+".");

}

//define the main method

public static void main (String[] args)

{

        //declare two double variables

        double num1,num2;

        //create the object of Scanner

        Scanner sc=new Scanner(System.in);

        //prompt the user to enter the values

        System.out.println("Enter two numbers:");

        //scan for the values

num1=sc...

Blurred answer
Students have asked these similar questions
Modify the Percentages application whose main() method holds two double variables. Assign values to the variables. Pass both variables to a method named computePercent() that displays the two values and the value of the first number as a percentage of the second one. For example, if the numbers are 2.0 and 5.0, the method should display a statement similar to “2.0 is 40.0 percent of 5.0.” Then call the method a second time, passing the values in reverse order. For testing use the values 2.0 and 5.0. An example of the program is shown below: 2.0 is 40.0 percent of 5.0 5.0 is 250.0 percent of 2.0
Modify the Percentages application whose main() method holds two double variables. Assign values to the variables. Pass both variables to a method named computePercent() that displays the two values and the value of the first number as a percentage of the second one. For example, if the numbers are 2.0 and 5.0, the method should display a statement similar to “2.0 is 40.0 percent of 5.0.” Then call the method a second time, passing the values in reverse order. For testing use the values 2.0 and 5.0.   An example of the program is shown below: 2.0 is 40.0 percent of 5.0 5.0 is 250.0 percent of 2.0
Create an application named Percentages whose main() method holds two double variables. Assign values to the variables. Pass both variables to a method named computePercent() that displays the two values and the value of the first number as a percentage of the second one. For example, if the numbers are 2.0 and 5.0, the method should display a statement similar to “2.0 is 40 percent of 5.0.” Then call the method a second time, passing the values in reverse order.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage