EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
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
Create an application named SalesTransactiobDemo that declares several SalesTransaction objects and displays their values and their sum. Name - The salesperson name (as a string) sales Amount- The sales amount (as a double) commission- The commission (as a double) RATE- A readonly field that stores the commission rate (as a double). Define a getRate() avcessor method that returns the RATE Include 3 constructors for the class.  One constructor accepts values for the name, sales amount, and rate, and when the sales value is set, the constructor computes the commission as sales value times commission rate. The second constructor accepts a name and sales amount, but sets the commission rate to 0 The third constructor accepts a name and sets all the other fields to 0
TOPICS: Using Classes and Objects MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM.  1. Write an application that prompts for and reads the user’s first and last name (separately), then displays a string composed of the first four characters of the user’s last name, followed by the first two letters of the user’s first name, followed by a random number in the range of 10 to 99. Assume that the last name is at least four letters long. Similar algorithms are sometimes used to generate usernames for new computer accounts. Testing: If the inputs were “Michael” and “Jackson,” the output should look like “JackMi42.” Include several tests with different inputs, including your own name.
Hello I hope you're having a great day. Can you please help me do this Java program, please remember to seperated the class definition and the application (there should be two programs)! Two print methods should be public!
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
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