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)
- Examine the following method header; then write an example call to the method. private void ResetValue(ref int value)arrow_forwarduse only C# programming Write a method call CubeIt(int x, ref int cube) that takes two arguments and does not return a value. The method will cube the first argument and assign it to the second argument.In your main, call this method twice and print the value of the parameters after each method call. Write a method with the following header: static void CalculateTuitionFee(int numberOfCourses, double costPerCourse, ref double fees). This method will calculate and assign the required fees amount to the third argument. [Fees = number of courses * cost per course + 15.25].From your program Main() method, call the CalculateTuitionFee () method four times supplying different arguments each time and display the value of the third argument after each method call. Write a method that takes four parameter of type int. The method will assign the sum of the first two arguments to the third and the difference of the first two to the fourth. This method should be coded so that the calling…arrow_forward21. Consider the following method: public static void sketch(int x1, int y1, int x2, int y2, int n) ( if (n <= 0) O else ( } drawLine(x1, y1, x2, y2); Assume that the screen looks like a Cartesian coordinate system with the origin at the center, and that drawLine connects (x1,y1) to (x2,y2). Assume also that x1, y1, x2, and y2 are never too large or too small to cause errors. Which picture best represents the sketch drawn by the method call int xm (x1 + x2 + y1 - y2) / 2; int ym (y1 + y2 + x2-x1) / 2; sketch(x1, y1, xm, ym, n - 1); sketch (xm, ym, x2, y2, n - 1); sketch(a, 0, -a, 0, 2) where a is a positive integer? (A) <-a y -a y a X (B) (D) -a y + -a -a aarrow_forward
- 1. For each statement, circle the response that best completes it. For the first nine statements, consider this Java method and the array shown to its right. array public static int linkSum(int'a, int startLoc, int sunlimit) ( startLoc; int sun 0, 1 while (1>0 & sun sunlimit) { aun- sum + a[i]; 1 = a[i]; } return dum; (i) The expression linkSum (junk, 3, 12) evaluates to a. 13 b. 22 c. 10 d. 1 (ii) The call linkSum (junk, b. 4 a. 1 c. 5 (iii) The call linkSum (junk, Array IndexOutOfBoundsException a. 1 c. 5 0 1 2 3 4 5 6 7 Junk 1 0141711131-1101 211 startLoc d. 6 ,20) results in an infinite loop. e. none of above ,15) results in an being thrown. d. 6 e. none of above b. 2 (iv) In the method above (applied to any array), we can be sure that at the moment that the loop terminates. a. a[i] startLoc || sun >= sunlimit d. 1 = sumlinit c. 1 <0 & sum e. none of the above (v) In the method above, each of int and static is a(n) a reserved word b. variable c. expression (vi) In the method…arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and returns the result.Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 code: public class LabProgram { public static int convert(double d){ /* Type your code here */ } public static void main(String[] args) { System.out.println(convert(19.9)); System.out.println(convert(3.1)); }}arrow_forwardPlease ASaP. Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7: 42 seconds import java.util.Scanner; public class PopcornTimer {public static void printPopcornTime(int bagOunces) { /* Your solution goes here */ } public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int userOunces; userOunces = scnr.nextInt();printPopcornTime(userOunces);}} .arrow_forward
- write a c++ program Write a class Date that represents a date consisting of a year, month, and day. A Date classshould have the following methods:# Date(int year, int month, int day)Constructs a new Date object to represent the given date.# void add(int &days)Moves this Date object forward by the given number of days. hint:* you should decideon the basis of month and year that given month ends 30,31,28,29 days.# void add(int &month , int &days) Moves this Date object forward by the given number of months and days. Monthsshould be within 1 to 12 and days in 1 to 31. For Example Date 2003/12/31andadd(1,29) =>Date will be 2004/02/29# void add(Date & other)Moves this Date object forward by the given Date.# void addWeeks(int &weeks)Moves this Date object forward by the given number of seven-day weeks.# int daysTo(Date & other)Returns the number of days that this Date must be adjusted to make it equal to the givenother Date.# void subtract(int &days)Moves this…arrow_forwardpublic static int cube(int num { return num num num; } What is the correct statement to pass value 8 to this method and assigns its return value to a variable named result? O cube(8) = int result; int result = cube(8) O int result = O int result = int cube(8);arrow_forwardUsing the jave code below write a method that takes the base pay and hours worked as parameters and prints the total pay or an error. Write a main method that calls this method for each of these employees. CODES: import java.util.Scanner; public class Salary { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter your basepay per hour: "); int basePay = scan.nextInt(); int salary = 0; if (basePay >= 80) { System.out.println("Enter your working hours: "); int hour = scan.nextInt(); if(hour <= 40) { salary = hour * basePay; System.out.println("Salary: " + salary); } else if (hour > 40 && hour <= 60) { salary += 40 * basePay + (hour - 40) * basePay * 1.5; System.out.println("Salary: " + salary); } else{…arrow_forward
- Look at the header of the method below, and then implement a sample call to it in your code.private static void ShowValue ()arrow_forward1. Write a program that takes three numbers (a,b,c) from the user as input and finds the median of the three. The program has a method called median that takes 3 numbers as the parameter and returns the median. Use if-then-else statements to find the median. You can assume the three numbers are not the same. Sample Example: Enter 3 numbers 10 13 The median is 10 public class Median{ public static void main(String[] args){ Scanner input = new int a = int b = int c =arrow_forwardAnalyze the following code. public class Test { public static void main(String[] args){ System.out.printlin( m(2) ); public static int m( int num ) { return num; } public static void m( int num ) { System.out.printin( num ); } The program has a compile error because the second m method is def method. The program runs and prints 2 once.arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage