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...
Trending nowThis is a popular solution!
Chapter 3 Solutions
EBK JAVA PROGRAMMING
- TOPICS: Using Classes and Objects MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM. 2. Write an application that reads the (x,y) coordinates for two points. This should prompt for and read each of the four values individually. Compute the distance between the two points using the following formula: Distance=(?2−?1)2+(?2−?1)2‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾√Distance=(x2−x1)2+(y2−y1)2 Testing: Include test exhibits for the following inputs: (1, 2) and (1, 2) are distance 0 (4, 0) and (2, 0) are distance 2 (0, 0) and (3, 4) are distance 5 (0, 0) and (1, 1) are distance 1.414... (i.e., the square root of 2)arrow_forward- Declare and create the following two Recipe objects then invoke the printRecipe method to print their info to the console: 1) Recipe name: Beef-Stuffed Peppers Preparation time: 55 minutes Servings: 4 Ingredients: 1 tablespoon olive oil 1 pound lean ground beef 1% cups water 1 (6 ounce) can tomato paste 4 green bell peppers, tops and seeds removed 2) Lemonade Preparation time: 15 minutes Servings: 10 Ingredients: Sugar Water Lemon juice Icearrow_forwardCreate an application named Tables that computes the price of a table and chairs and whose Main() method calls the following methods: A method to accept the number of chairs to go with the table as input from the keyboard. This method returns the number of chairs to the Main() method. A method to accept as input and return the type of wood: p for pine, m for maple, and o or oak (use a loop to ensure only one of these letters is entered). A method that accepts the number of chairs and wood type, and calculates the total cost of the desk based on the prices below. This method returns the total cost to the Main() method. Pine tables are $250. Maple tables are $300. All other wood types are $350. There will be an additional cost of $50 per chair. A minimum of 2 chair must be ordered (use a loop to ensure a value of 2 or more is entered.) A final method to display all the details and the final price. The image below shows a sample run of the program.arrow_forward
- This assigment wants me to: Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompts the user for the length, width, and height of a rectangular room. Pass these three values to a method that does the following: Calculates the wall area for a room Passes the calculated wall area to another method that calculates and returns the number of gallons of paint needed Displays the number of gallons needed Computes the price based on a paint price of $32 per gallon, assuming that the painter can buy any fraction of a gallon of paint at the same price as a whole gallon Returns the price to the main() method The main() method displays the final price. For example: You will need 2.0 gallons The price to paint the room is $64.0 here is my code and this is all i have so far help please ! import java.util.Scanner; public class PaintCalculator { public static void main (String args[]) { int AreaPerGalllon =…arrow_forwardUSE JAVA IDE Create a class that has three methods. One method is to input three numbers. The second method will return the largest number between the three numbers. The third method will return the smallest number between the three numbers. Since the largest and smallest number are both returned values, display these values in the main method.arrow_forwardVariables name: Choose meaningful and descriptive names. No x, y … etc. Use lowercase. If the name consists of several words, concatenate all in one, uselowercase for the first word, and capitalize the first letter of each subsequent word inthe name. For example, the variables radius and area, and the method computeArea.3. File type: only JAVA file is allowed. Name it as Assignment2. Java5. Please add the appropriate comments for each step you add. In the top of the program, addyour name, time of starting writing the code and title of the assignment. Extra informationwould be greatarrow_forward
- Hello.. hope you are in good health.. please code for me in JAVA and follow the instructions as it is A tech company is responsible for creating usernames and passwords for members of à certain organization. The SystemUser class below contains methods that the company will use to generate usernames and passwords. In this problem, you will focus on the createPassword method. This method will take in two words of equal length and then create a password by "weaving" the characters together as in the following example.blue and fish would combine to create the password bfliusehUse the code below to answer the questions that follow.public class SystemUser {/** @param two words of equal length, word1 and word2. * @return a password for that user that combines the two words by "weaving" together the* letters in each. * @return an empty String and print out error message if two words do not have equal length. / public String createPassword(String word1, String word2) { / to be implemented in…arrow_forwarda - Create a FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to running, the minutes to 0, and the date to January 1 of the current year. Save the file as FitnessTracker.java. Create an application that demonstrates each method works correctly, and save it as TestFitnessTracker.java. b - Create an additional overloaded constructor for the FitnessTracker class you created in Exercise 3a. This constructor receives parameters for each of the data fields and assigns them appropriately. Add any needed statements to the TestFitnessTracker application to ensure that the overloaded constructor works correctly, save it, and then test it. c - Modify the FitnessTracker class so that the default constructor calls the three-parameter constructor. Save the class as FitnessTracker2.java. Create an…arrow_forwardModify 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.0arrow_forward
- ● Create a class named Decimals. Write a static method named printDecimalDigits that takes a double as a parameter and does not return anything. ● ● ● The method should print out "Digits after decimal point: ", followed by all the digits after the decimal point on one line (do not include the decimal point). Additional rule: Your code must not contain any loops. Create a test class named DecimalsTest that contains the main method and use the sample usage below to check your code. Method Call Decimals.print DecimalDigits (37.2) Decimals.print DecimalDigits (1000) Method Output Digits after decimal point: 2 Digits after decimal point: 0 Decimals.printDecimalDigits (18.3927493038) Digits after decimal point: 3927493038arrow_forwardCreate 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.arrow_forwardONLY IN JAVA. Create a Java program that you can play the game "More or Less, Less is More."Rules of the game:The two-dimensional field of the game must be m x n in size (game field). The buttons that make up the game field each have a number assigned to them.beginning of the game:The target value is shown above the game field. The numbers on the buttons of the game field are set to a random digit between 0 and 9.• Below the game field, you may read the current sum of the numbers displayed on the buttons.• Above the playing field in the upper right corner is a display of the remaining movements.Playing: The player chooses their first move by clicking any button (button A) on the playing area.1. The player has the option to select a second button (button B) that is situated in the same row or column as the first button they chose (A).2. When button (A) is clicked, value is changed in accordance with the following formula: (AoperationB)mod10 equals A.3. The basic game's operation will be…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT