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.
Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used.   1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW};   2. Save the file as Color.java.   3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN};   4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color.  public class Car {  private int year;  private Model model;  private Color color;   5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows:  public Car(int yr, Model m, Color c) {  year = yr;  model = m;  color = c;  }   6. Add a display()…
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