EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Expert Solution & Answer
Book Icon
Chapter 3, Problem 4PE

Explanation of Solution

a.

Program code:

NumbersDemo.java

//define the method NumbersDemo

public class NumbersDemo

{

    //define the main() method

    public static void main(String args[])

    {

        //create two integer variable

        int n1 = 10;

        int n2 = 7;

//call the static methods

displayTwiceTheNumber(n1);

displayNumberPlusFive(n1);

displayNumberSquared(n1);

        //print new line

        System.out.println();

//call the static methods

displayTwiceTheNumber(n2);

displayNumberPlusFive(n2);

displayNumberSquared(n2);

    }

//define the method displayTwiceTheNumber()

public static void displayTwiceTheNumber(int n)

{

    //multiply n by 2 and print it

    System.out.println(2 * n);

}

//define the method displayNumberPlusFive()

public static void displayNumberPlusFive(int n)

{

    //add 5 to n and dispaly it

    System...

Explanation of Solution

b.

Program code:

NumbersDemo2.java

//import the package

import java.util.Scanner;

//define the method NumbersDemo

public class NumbersDemo2

{

    //define the main() method

    public static void main(String args[])

    {

        //create the object of scanner

        Scanner in = new Scanner(System.in);

        //prompt the user to enter two numbers

        System.out.println("Enter the numbers");

        //scan for the values

        int n1 = in.nextInt();

        int n2 = in.nextInt();

        //print new line

        System.out.println();

//call the static methods

displayTwiceTheNumber(n1);

displayNumberPlusFive(n1);

displayNumberSquared(n1);

        //print new line

        System.out.println();

//call the static methods

displayTwiceTheNumber(n2);

displayNumberPlusFive(n2);

displayNumberSquared(n2);

    }

//define the method displayTwiceTheNumber()

public static void displayTwiceTheNumber(int n)

{

    //multiply n by 2 and print it

    System...

Blurred answer
Students have asked these similar questions
(use R language)Scatter plot(a). Run the R code example, and look at the help file for plot() function. Try different values for arguments:type, pch, lty, lwd, col(b). Use par(mfrow=c(3,2)) and output 6 plots with different argument settings.
1. Draw flow charts for each of the following;a) A system that reads three numbers and prints the value of the largest number.b) A system reads an employee name (NAME), overtime hours worked (OVERTIME), hours absent(ABSENT) and determines the bonus payment (PAYMENT).
Scenario You work for a small company that exports artisan chocolate. Although you measure your products in kilograms, you often get orders in both pounds and ounces. You have decided that rather than have to look up conversions all the time, you could use Python code to take inputs to make conversions between the different units of measurement. You will write three blocks of code. The first will convert kilograms to pounds and ounces. The second will convert pounds to kilograms and ounces. The third will convert ounces to kilograms and pounds. The conversions are as follows: 1 kilogram = 35.274 ounces 1 kilogram = 2.20462 pounds 1 pound = 0.453592 kilograms 1 pound = 16 ounces 1 ounce = 0.0283 kilograms 1 ounce = 0.0625 pounds For the purposes of this activity the template for a function has been provided. You have not yet covered functions in the course, but they are a way of reusing code. Like a Python script, a function can have zero or more parameters. In the code window you…
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
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning