6. Inside class StaticMethods, create the OVERLOADED static method squareNumber shown be- low that takes as a parameter a number of type double and returns the number squared as double. Call this method from the main method of class Lab14 and print the result. Do you see what makes Java distinguish overloaded methods at invocation? The argument(s) passed to the method of course. 26 public static double squareNumber( double number) { System.out.println( "DOUBLE was called"); return number * number; } 27 E 28 29 30

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java Netbeans

6. Inside class StaticMethods, create the OVERLOADED static method squareNumber shown be-
low that takes as a parameter a number of type double and returns the number squared as
double. Call this method from the main method of class Lab14 and print the result. Do you see
what makes Java distinguish overloaded methods at invocation? The argument(s) passed to the
method of course.
26
public static double squareNumber( double number)
27 E
System.out.println( "DOUBLE was called");
return number * number;
}
28
29
30
7. Inside class StaticMethods, create the static method cubeNumber as shown below that takes
as a parameter a number of type double and returns the number squared, as double. Call this
method from the main method of class Lab14 and print the result. Please NOTE how the
method cubeNumber, calls the method squareNumber. Look ta the comments inside the
method.
public static double cubeNumber( double number)
{
return number * squareNumber( number );
31
32 D
// StaticMethods.squareNumber is also correct as shown in comment below
//return number * StaticMethods.squareNumber( number );
}
8. Inside class StaticMethods, create the static and OVERLOADED method cubeNumber that
takes as an argument an integer and returns a double. Test it from main.
9. Inside class StaticMethods., create the static and OVERLOADED method cubeNumber that
takes as an argument a String and returns a double. Test it from main.
10. Inside class StaticMethods, create the static method menu that displays a menu for the user
to select 's' or 'c'. The method returns the character entered, ONLY when the user types 's'
or 'c', otherwise prints a message and stays in a loop. Test it from main().
public static char menu()
38
39 E
String s = "";
do
{
System.out.println("type S\\s to square a number:" );
System.out.println("type C\\c to cube a number:" );
S = new
40
41
42
43
44
45
Scanner( System.in).next();
46
if ( "c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 )
System.out.println("\tplease enter a valid character" );
47
48
}
while ("c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 );
return s.charAt(0);
49
50
51
52
}
Transcribed Image Text:6. Inside class StaticMethods, create the OVERLOADED static method squareNumber shown be- low that takes as a parameter a number of type double and returns the number squared as double. Call this method from the main method of class Lab14 and print the result. Do you see what makes Java distinguish overloaded methods at invocation? The argument(s) passed to the method of course. 26 public static double squareNumber( double number) 27 E System.out.println( "DOUBLE was called"); return number * number; } 28 29 30 7. Inside class StaticMethods, create the static method cubeNumber as shown below that takes as a parameter a number of type double and returns the number squared, as double. Call this method from the main method of class Lab14 and print the result. Please NOTE how the method cubeNumber, calls the method squareNumber. Look ta the comments inside the method. public static double cubeNumber( double number) { return number * squareNumber( number ); 31 32 D // StaticMethods.squareNumber is also correct as shown in comment below //return number * StaticMethods.squareNumber( number ); } 8. Inside class StaticMethods, create the static and OVERLOADED method cubeNumber that takes as an argument an integer and returns a double. Test it from main. 9. Inside class StaticMethods., create the static and OVERLOADED method cubeNumber that takes as an argument a String and returns a double. Test it from main. 10. Inside class StaticMethods, create the static method menu that displays a menu for the user to select 's' or 'c'. The method returns the character entered, ONLY when the user types 's' or 'c', otherwise prints a message and stays in a loop. Test it from main(). public static char menu() 38 39 E String s = ""; do { System.out.println("type S\\s to square a number:" ); System.out.println("type C\\c to cube a number:" ); S = new 40 41 42 43 44 45 Scanner( System.in).next(); 46 if ( "c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 ) System.out.println("\tplease enter a valid character" ); 47 48 } while ("c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 ); return s.charAt(0); 49 50 51 52 }
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education