Concept explainers
What is the signature of each of the following method headings?
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
Concepts Of Programming Languages
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Complete the method tablespoonsToMilliliters() that has one integer parameter as a volume in tablespoons. The method returns a double as the volume converted to milliliters, given that 1 tablespoon = 14.7868 milliliters. Ex: If the input is 47, then the output is: 694.980 milliliters 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.Scanner; public class VolumeConversion { publicstaticdoubletablespoonsToMilliliters(inttablespoons) { /* Your code goes here */ } publicstaticvoidmain(String[] args) { Scannerscan=newScanner(System.in); intuserTablespoons; userTablespoons=scan.nextInt(); // Print with value rounded to 3 decimal places System.out.printf("%.3f milliliters\n", tablespoonsToMilliliters(userTablespoons)); } }arrow_forwarduse the method setData(String,String,doule,int) to set the employee’s details; and the method getDetails() that will return a descriptive statement about the employee. import java.util.*;class Department { private int groupScore; private double groupAverage; private static int overallScore; private static double overallAverage; public Department(int r1,int r2,int r3,int r4,int r5) { Department.overallScore=Department.overallScore+r1+r2+r3+r4+r5; Department.overallAverage=Department.overallScore/10.0; this.groupScore=r1+r2+r3+r4+r5; this.groupAverage=this.groupScore/5.0; } public double getGroupAvergae() { return this.groupAverage; } public void displayAverage() { System.out.println("Overall Average:"+Department.overallAverage); } }public class Main { public static void main(String args[]) { Department d1=new Department(1,2,3,4,5); d1.displayAverage(); Department d2=new Department(5,4,4,4,1);…arrow_forwardThe StringBuilder class is providedin the Java library. Provide your own implementation for the following methods(name the new class MyStringBuilder2):public MyStringBuilder2();public MyStringBuilder2(char[] chars);public MyStringBuilder2(String s);public MyStringBuilder2 insert(int offset, MyStringBuilder2 s);public MyStringBuilder2 reverse();public MyStringBuilder2 substring(int begin);public MyStringBuilder2 toUpperCase();arrow_forward
- The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior.arrow_forwardWrite a method lastNameFirst that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane".arrow_forwardWhat will be returned from the following method? public double testing ( ) { double a = 9.5 + 9.3; return a; } a) 18.8 b) 18.0 c) 18 d) 19arrow_forward
- *in java* Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2: 1: Lather and rinse. 2: Lather and rinse. Done. Hint: Declare and use a loop variable. import java.util.Scanner; public class ShampooMethod { /* Your solution goes here */ public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int userCycles; userCycles = scnr.nextInt();printShampooInstructions(userCycles);}}arrow_forwarduse the file Dining.java which is provided below and Complete the calcTip() method as described in the comments. Then add a new method called splitBill() which receives as input an integer value, representing the number of diners, and returns each person's equal share of the bill.arrow_forwardThe following Java code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior. public void spending(Scanner console,String name) { System.out.print("How much will " + name + " be spending?"); double amount = console.nextDouble(); System.out.println(); int numBills = (int) (amount / 20.0); if (numBills * 20.0 < amount) { numBills++; } System.out.println(name + " needs " + numBills + " bills"); } The code above is all I was given to work with, which is why I'm a bit confused and need help. Thank you.arrow_forward
- Write a program, named UpdatedNumbers with the following method: Write a method to check whether a number odd or even Get the integer value into the method as oNumbers(number); In “oNumbers”, check the number whether it is an odd or even number; Then, return a Boolean value from the methodarrow_forwardThis question was rejected from incompletion but it's completed. Answer the prompt with the following code as a guide for the main method: import java.awt.*; public class TestRectangle { public static void main(String[] args) { Rectangle r1 = new Rectangle(5, 4, 10, 17); Rectangle r2 = new Rectangle(10, 10, 20, 3); Rectangle r3 = new Rectangle(0, 1, 12, 15); Rectangle r4 = new Rectangle(10, 10, 20, 3); System.out.println("r1 = " + r1); System.out.println("r2 = " + r2); System.out.println("r3 = " + r3); System.out.println("r2 equals r1? " + r2.equals(r1)); System.out.println("r2 equals r2? " + r2.equals(r2)); System.out.println("r2 equals r3? " + r2.equals(r3)); System.out.println("r2 equals r4? " + r2.equals(r4)); System.out.println("r1 contains (6, 8)? = " + r1.contains(6, 8)); System.out.println("r2 contains (6, 8)? = " + r2.contains(6, 8));…arrow_forwardConsider the following method. Java. public void changeValues(int i, Card c){ i = 15; c.setSuit(“Clubs”);} Now consider the following snippet of code that calls the method defined above. int num = 12;Card fiveOfSpades = new Card(5, “Spades”);System.out.println(“Before method call:”);System.out.println(num);System.out.println(fiveOfSpades.getSuit());changeValues(num, fiveOfSpades);System.out.println(“After method call:”);System.out.println(num);System.out.println(fiveOfSpades.getSuit()); What is the output of this code?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