1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sloan [31]
3 years ago
12

a. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In t

urn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. Save the application as NumbersDemo.java. b. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. Save the file as NumbersDem02.java.
Computers and Technology
2 answers:
Ilia_Sergeevich [38]3 years ago
5 0

Answer:

PART ONE:

public class NumbersDemo {

   public static void main(String[] args) {

   int num1= 1;

   int num2= 2;

   //Calling method displayTwiceTheNumber()

   displayTwiceTheNumber(num1);

   displayTwiceTheNumber(num2);

   //Calling method displayNumberPlusFive()

   displayNumberPlusFive(num1);

   displayNumberPlusFive(num2);

   //Calling method displayNumberSquared()

   displayNumberSquared(num1);

   displayNumberSquared(num2);

   }

   public static void displayTwiceTheNumber(int num1){

       System.out.println(num1*2);

   }

   public static void displayNumberPlusFive(int num1){

       System.out.println(num1+5);

   }

   public static void displayNumberSquared(int num1){

       System.out.println(num1*num1);

   }

}

PART TWO

import java.util.Scanner;

public class NumbersDem02 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter Values for num1 and num2");

   int num1= in.nextInt();

   int num2= in.nextInt();

   //Calling method displayTwiceTheNumber()

   displayTwiceTheNumber(num1);

   displayTwiceTheNumber(num2);

   //Calling method displayNumberPlusFive()

   displayNumberPlusFive(num1);

   displayNumberPlusFive(num2);

   //Calling method displayNumberSquared()

   displayNumberSquared(num1);

   displayNumberSquared(num2);

   }

   public static void displayTwiceTheNumber(int num1){

       System.out.println(num1*2);

   }

   public static void displayNumberPlusFive(int num1){

       System.out.println(num1+5);

   }

   public static void displayNumberSquared(int num1){

       System.out.println(num1*num1);

   }

}

Explanation:

Three methods are created to do exactly as required by the question

In part two, the scanner class is used to receive the values from the user

aliya0001 [1]3 years ago
3 0
<h2>Answer:</h2>

<h2>(a) </h2>

//Header declaration of class NumbersDemo

public class NumbersDemo {

   //Main method

   public static void main(String[] args) {

       //Declare and initialize the two integer variable

       int fnumber = 23;

       int snumber = 34;

       

       //Call the method displayTwiceTheNumber() using each of the variables above, in turn, as argument

       displayTwiceTheNumber(fnumber);

       displayTwiceTheNumber(snumber);

       

       //Call the method displayNumberPlusFive() using each of the variables above, in turn, as argument

       displayNumberPlusFive(fnumber);

       displayNumberPlusFive(snumber);

       

       //Call the method displayNumberSquared() using each of the variables above, in turn, as argument

       displayNumberSquared(fnumber);

       displayNumberSquared(snumber);

       

   }        // End of main method

   // Declare the method displayTwiceTheNumber() which receives an integer number as argument

   // Its return type is void since it only displays twice the number

   // i.e 2 *  number

   private static void displayTwiceTheNumber(int number) {

       System.out.println("twice of " + number + " : " + 2 * number);

   }

   //Declare the method displayNumberPlusFive() which receives an integer

   // number as argument

   //Its return type is void since it only displays the result when 5 is added

   // to the number i.e number + 5

   private static void displayNumberPlusFive(int number) {

       System.out.println(number + " plus five(5) : " + (number + 5));

   }

   //Declare the method displayTwiceTheNumber which receives an integer

   // number as argument

   //Its return type is void since it only displays the square of the number

   // i.e number * number

   private static void displayNumberSquared(int number) {

       System.out.println(number + " squared : " + (number*number));

   }

   

}      // End of class declaration

<h2>(b)</h2><h2 />

//import the Scanner class

import java.util.Scanner;

//Header declaration of class NumbersDemo 02

public class NumbersDemo02 {

   //Main method

   public static void main(String[] args) {

       

       //create an object of the Scanner class to allow for user's input

       Scanner input = new Scanner(System.in);

       

       //prompt user to enter first number;

       System.out.println("Please enter first number");

       

       //Declare and initialize an integer variable to hold the first number

       int fnumber = input.nextInt();

       

       //prompt user to enter second number;

       System.out.println("Please enter second number");

       

       //Declare and initialize an integer variable to hold the first number

       int snumber = input.nextInt();

       

       //Call the method displayTwiceTheNumber() using each of the

       // variables above, in turn, as argument

       displayTwiceTheNumber(fnumber);

       displayTwiceTheNumber(snumber);

       

       // Call the method displayNumberPlusFive() using each of the variables

       // above, in turn, as argument

       displayNumberPlusFive(fnumber);

       displayNumberPlusFive(snumber);

       

       // Call the method displayNumberSquared() using each of the variables

       // above, in turn, as argument

       displayNumberSquared(fnumber);

       displayNumberSquared(snumber);

       

   }

   //Declare the method displayTwiceTheNumber() which receives an

   // integer number as argument

   //Its return type is void since it only displays twice the number

   // i.e 2 * number

   private static void displayTwiceTheNumber(int number) {

       System.out.println("twice of " + number + " : " + 2 * number);

   }

   //Declare the method displayNumberPlusFive() which receives an integer    

   // number as argument

   //Its return type is void since it only displays the result when 5 is added

   // to the number i.e number + 5

   private static void displayNumberPlusFive(int number) {

       System.out.println(number + " plus five(5) : " + (number + 5));

   }

   //Declare the method displayTwiceTheNumber which receives an integer

   // number as argument

   //Its return type is void since it only displays the square of the number

   // i.e number * number

   private static void displayNumberSquared(int number) {

       System.out.println(number + " squared : " + (number*number));

   }

   

}    // End of class declaration

<h2>Sample Output to (a):</h2>

twice of 23 : 46

twice of 34 : 68

23 plus five(5) : 28

34 plus five(5) : 39

23 squared : 529

34 squared : 1156

<h2>Sample Output to (b):</h2>

>> Please enter first number

12

>> Please enter second number

23

twice of 12 : 24

twice of 23 : 46

12 plus five(5) : 17

23 plus five(5) : 28

12 squared : 144

23 squared : 529

<h2>Explanation:</h2>

The above codes have been written in Java and it contains comments explaining every part of the code. Please go through the comments for explanation.

You might be interested in
Question # 2 Multiple Choice The _____ method returns an integer between the two provided numbers. It can take the value of eith
nlexa [21]

Answer:

randint

Explanation:

7 0
3 years ago
Read 2 more answers
Need help asapppppppppp
TEA [102]

Answer:

artistic

Explanation:

because being it is considered a art

7 0
3 years ago
Read 2 more answers
Which of the following is a windows that allows you to temporarily store text
musickatia [10]
There are no answer choices listed so I don't have anything to choose from so i'm just going to go with what I know/think. Just from reading the question I think it may be the "notepad." If it is not the notepad then it may be the clipboard.

Sorry if this doesn't help you very much, but there were no answer choices. 
7 0
3 years ago
You have a shared folder named Reports. Members of the Managers group have been given Write access to the shared folder. Mark Ma
Anna71 [15]

Answer:

Following are the solution to the given question:

Explanation:

The common folder called Report has also been shared. Writing access to a shared folder was given to management group members. Mark is a member of a group of managers. We can access the files within your reporting directory, but you really should not access the Confidential.xls file. We want to add Mark Mangum to our ACL files using Deny permissions on Confidential.xls.

5 0
3 years ago
Choose the types of education and iss professional is most likely to have
shutvik [7]

Answer:

A and D

Explanation:

Just took it on edgenuity

8 0
3 years ago
Other questions:
  • The memory allocated for a float value is ____ bytes.
    9·1 answer
  • Which is a description of phishing?
    7·1 answer
  • ( Game Design) The companies who get video games out to consumers are called:
    12·1 answer
  • Wap to input any multi digits number and display the sum of odd digits and even digits​
    5·1 answer
  • Complete this assignment in Python 3.x. Make sure you have downloaded the software, and it is installed correctly.
    10·1 answer
  • What output is produced by
    10·1 answer
  • What is the two’s compliment of -95,-122,-111,-57
    9·1 answer
  • Clara works behind a computer all day. She gets a lot of headaches, and her eyes have been hurting her lately. Her doctor diagno
    15·1 answer
  • What is an example of work performed by an integration platform as a service (ipaas)?
    14·2 answers
  • In _________, the process requests permission to access and modify variables shared with others. a) entry section b) critical se
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!