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)
- Don'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_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_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
- Write a Java program that takes input from the user for the lengths of three sides, s1, s2, ands3, and decides if the sides of the given lengths can form a triangle. If they can, furtherdetermine if the triangle is right, acute, or obtuse.arrow_forwardWrite up Java source codes for compiling and execution of program below. 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: Your opponent can force you…arrow_forwardwrite a Java program:The following is an old word puzzle: “Name a common word besides tremendous, stupendous, and horrendous that ends in ‘dous’”. IF you think about it for a while you may be able to solve it. But we are programmers and we don’t like to think. Also we can do something much better than just check to see if a word ends in dous. Create a Java program that will read the attached words.txt file. Ask the user for a string. Based on that string, output every word that ends in such a string. If there are no results say so. Try to ensure that the program does not have any errors based on the input from the user.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