In which sequence are the lines of the Cubes.java program in Section 5.2 executed, starting with the first line of main?
Introduction:
- Define the class named “Cubes”.
- Define the main method.
- Declare and assign the required variables.
- Print the volume of the cube with length of the side as “2”.
- Print the volume of the cube with length of the side as “10”.
- Define the static method named “cubeVolume”.
- Declare and assign the required double variable.
- Return the value stored in the variable “volume”.
Explanation of Solution
//define a class
public class Cubes
{
//define the main method
public static void main(String[] args)
{
//declare the required variables
double result1=cubeVolume(2);
double result2=cubeVolume(10);
//print the output statements
System.out.println("A cube with side length 2 has
volume"
+result1);
System.out.println("A cube with side length 10
has volume"
+result2);
}
//define the static method
public static double cubeVolume(double sideLength)
{
//declare the required variables
double volume=sideLength*sideLength*sideLength;
//return statement
return volume;
}
}
A cube with side length 2 has volume 8
A cube with side length 10 has volume 1000
Want to see more full solutions like this?
Chapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Modern Database Management
Starting Out with Python (3rd Edition)
Starting Out with C++: Early Objects (9th Edition)
Artificial Intelligence: A Modern Approach
Database Concepts (8th Edition)
Java How To Program (Early Objects)
- how to answer the follow question in java In between is a well-known card game. Many variations exist- we define it as follows. One deck of card is used. A game consist of one or more hands. A player starts with a certain number of chips called the stake (say 100) and must risk one or more chips on each hand, before seeing any cards, as long as the player still has chips and there are three or more card left in the desk(enough to play one hand), the game continues. For each hand player must risk the player For each hand the player must risk between one and their total number of chips. Two cards are dealt face up. Then the third card is dealt. If the third card is in between the first two cards, based on ranks of the cards, the player’s chips are increase by the amount risked. Otherwise they decreased by the amount. A implement the game. The application user is the player (GUI not require) (only three cards is required to play). If the first two cards are the same rank, that hand is…arrow_forwardPlease answer in Java 1. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design the class Point that can store and process a point in the x-y plane.-We should then perform operations on a point, such as showing the point, setting the coordinates of the point, printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. -Write a test program to test various operations on a point. The class Point should contain the following methods and data members: 1. protected members x and y2. default constructors3. constructors with parameters4. setPoint(x)5. getX()6. getY()7. toString()8. equals(x)9. makeCopy(x)10. getCopy()11. printPoint() The output should show the following: -Initialize myPoint = [5.00,4.00]-Initialize yourPoint = [0.00, 0.00]-Print both of these objects-Set yourPoint to [5.00, 45.00] and print it-Determine if the 2 points are equal or not-Change the myPoint coordinates to [6.00, 9.00]-Print this new myPoint…arrow_forwardWrite up Java source codes for compiling and execution of program below. Draw UML diagram for codes. There is a very simple solution to keeping Tic-tac-toe fresh and interesting, though, and it has been thought up by a group of mathematicians. It’s being called Ultimate Tic-tac-toe and simply embeds a Tic-tac-toe board in each of the nine squares of the original game. Now instead of just winning the main board, you also need to win each of the smaller boards first until you have a line of three. New Rule: You can only place a mark on the board determined by the position of your opponent’s last placed mark. So, if they put an X or O in the top right corner of a square, your next move must occur in the top right board. By adding that rule the game is no longer about winning a single board, it’s about tactically managing up to 9 games at once and plotting ahead. You still win by marking three squares in a row, but that now involves winning three games. The effects of the New Rule: 1:…arrow_forward
- Create java program with a declaration of int x = {1,2,3,4,5,6,7,8,9,10} that change the number 9 to 0 Note: add comments to the codearrow_forwardCreate a Java program that shows Pass by value and pass by reference.arrow_forwardDon't copy from other websites Write a program in Java to read a name in the following order, with one space between them: First-name, optional-Middle-Name, last-name, and print them in new order with a comma and space after last name and capitalizing beginning of each word regardless how it is entered: Last name, First name Meddle Initial. Examples: James Frederick Olson > Olson, James F. james frederick olson > Olson, James F. JAMES FREDERICK OLSON > Olson, James F. James Olson > Olson, James james olson > Olson, James JAMES OLSON > Olson, Jamesarrow_forward
- Write a Java program to print out an upside-down pyramid as below. The program should use loops and can make an assumption about the levels of the pyramid. For example, the following pyramid has 5 levels.arrow_forwardThis is about Java. Please help me with the code picturearrow_forwardWrite a Java program. Consider the structure of the code that is shown in the picture. Instructions: Determine if a triangle is equilateral, isosceles, or scalene. An equilateral triangle has all three sides the same length. An isosceles triangle has at least two sides the same length. (It is sometimes specified as having exactly two sides the same length, but for the purposes of this exercise we'll say at least two.) A scalene triangle has all sides of different lengths. Note For a shape to be a triangle at all, all sides have to be of length > 0, and the sum of the lengths of any two sides must be greater than or equal to the length of the third side. See Triangle Inequality. Dig Deeper The case where the sum of the lengths of two sides equals that of the third is known as a degenerate triangle - it has zero area and looks like a single line. Feel free to add your own code/tests to check for degenerate triangles.arrow_forward
- I needed some help with this java homework assignement. We use eclipse. CIS365 Hw1: Count LetterWrite a Java program (CountLetter.java). Input a sentence from keyboard. Print out how many letters "a", "e", "o" and the percentage of each letter in the whole sentence. Please enter a sentence, ended by period '.': (5 points)Sentence.... (10 points)There are 20 letters (10 points)a: 1, 5% (20 points)e: 0, 0% (20 points)o: 4, 20% (20 points)arrow_forwardUsing java, solve the following problem with JavaFX: Write program (Call the class Smiley) that paints smiley face, that is exact to the image below:arrow_forwardAssume you are working for the Kean University and given a task to build an Email Registration System. Part of your task is to generate a Kean email ID and temporary password for every new user. To implement this task, create a complete Java program consisting of the following modules: • A Main method will have a loop of your choice that will ask five users one by one to provide their first name and last name. Example for 1 input (1 iteration of the loop): 1. Enter your first name: Joanne 2. Enter your last name: Rowling • The Main method will call generateEmail() and generatePassword() methods to generate Kean email and its password • Method generateEmail() will generate a personal Kean email address based on the first name and last name. Such Kean email address consists of the first letter of the first name and the entire last name all in lower case appended with @kean.edu Example: Joanne Rowling => jrowling@kean.edu To simplify this question, we assume all usernames are unique. •…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education