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)
- Please 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_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_forwardI 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_forward
- Using 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_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
- 4. Javaarrow_forwardWrite a Java program that prints a special triangle containing both numbers and letters as mentioned in the following details. The idea is that we first start with printing the number 1 to build the triangle. The number of total lines in the triangle should be derived by the number of letters between the capital letter 'A' and the given upper-case input letter (both inclusive). Then, we follow the rule of printing letters and numbers in turn for the following lines. The critical point here is that we skip either the consecutive number or letter between lines. For example, in line 3 of the triangle, we skipped the letter 'B' and printed the number 3. Similarly, we skipped the value of '2 and printed the letter 'A in line 2 of the triangle instead. Input Format An upper-case letter, I. Constraints IE (A, B, C, D, E, F, G, H, I, J} Output Format Drawing a special triangle containing both numbers and capital letters. Sample Input 0 Sample Output 0 AAA 33333 ссссссс 555555555 EEEEEEEEEEE…arrow_forwardWrite a java Program that implements a calculator and it should have the 6 basic Operatoin : Addition , Substrsction , multiplication , Division , Mod , Equal , CE(to clear the textfield ) The calculator should be like the following pic but without styling Make a program that implement a Quiz that include 10 Questions ( 2 Per Stage )o the First Stage Contains a Label that contains the question and bellow it a choicesor textfield for the answer and bellow all of these a button “Next” to move to thenext Stageo The other Stages should contain as the same of the first stage in addition of abutton “Previous” to move to previous stageo The last Stage don’t has a next button , although it has “Finish attemp” whenpressing on it it should move to a final stage that include a label with the gradefrom 10arrow_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