1. (5 points) Method Overloading: Given the following methods, write down the printed output of the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. (5 points) Method Overloading: Given the following methods, write down the printed output of the method calls. Try first by eye, then verify your results via eclipse. public static void doSomething(String x) { } System.out.println("A"); public static void doSomething(int x) { } System.out.println("B"); public static void doSomething(double x) { } System.out.println("C"); public static void doSomething(String x, int y) } System.out.println("D"); public static void doSomething(int x, String y) System.out.println("E"); { } public static void doSomething (double x, int y) System.out.println("F"); } Method calls public static void main(String[] args) { doSomething (5); doSomething (5.2, 9); doSomething (3, "Hello"); doSomething("Able", 8); doSomething("Alfred"); doSomething(3.6); doSomething("World"); } { 2. (15 points) Write a class called Repeat that contains 2 methods, main and printLine 1) The printLine method will do the following: a. receives 3 parameters: the first character, the second character and the number of times to print the characters. b. using a loop, the program prints a line of text consisting of the first character concatenated with the second character repeated the number of times entered by the user. 2) The main method will do the following: a. asks the user for a character. b. using a Scanner gets the character C. asks the user for a second character d. using a Scanner gets the second character e. asks the user how many times to print f. using a Scanner gets the number of times to print g. calls the method printLine Sample Run: Enter a character ? Enter a second character * Enter the number of times to repeat 5 ?*?*?*?*?* Enter a character ! Enter a second character @ Enter the number of times to repeat 8 !@!@!@!@!@!@!@!@ Submission Copy and paste your code Screen shot the console with ANY TWO Sample Run Hint: remember how to read a character using a Scanner: System.out.println("Enter a character"); String line = reader.nextLine(); char char1line.charAt(0); The two statements can be combined into one statement: char char1 reader.nextLine().charAt(0); 1. (5 points) Method Overloading: Given the following methods, write down the printed output of the method calls. Try first by eye, then verify your results via eclipse. public static void doSomething(String x) { } System.out.println("A"); public static void doSomething(int x) { } System.out.println("B"); public static void doSomething(double x) { } System.out.println("C"); public static void doSomething(String x, int y) } System.out.println("D"); public static void doSomething(int x, String y) System.out.println("E"); { } public static void doSomething (double x, int y) System.out.println("F"); } Method calls public static void main(String[] args) { doSomething (5); doSomething (5.2, 9); doSomething (3, "Hello"); doSomething("Able", 8); doSomething("Alfred"); doSomething(3.6); doSomething("World"); } { 2. (15 points) Write a class called Repeat that contains 2 methods, main and printLine 1) The printLine method will do the following: a. receives 3 parameters: the first character, the second character and the number of times to print the characters. b. using a loop, the program prints a line of text consisting of the first character concatenated with the second character repeated the number of times entered by the user. 2) The main method will do the following: a. asks the user for a character. b. using a Scanner gets the character C. asks the user for a second character d. using a Scanner gets the second character e. asks the user how many times to print f. using a Scanner gets the number of times to print g. calls the method printLine Sample Run: Enter a character ? Enter a second character * Enter the number of times to repeat 5 ?*?*?*?*?* Enter a character ! Enter a second character @ Enter the number of times to repeat 8 !@!@!@!@!@!@!@!@ Submission Copy and paste your code Screen shot the console with ANY TWO Sample Run Hint: remember how to read a character using a Scanner: System.out.println("Enter a character"); String line = reader.nextLine(); char char1line.charAt(0); The two statements can be combined into one statement: char char1 reader.nextLine().charAt(0);
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Two tutoring services offer crash courses in preparation for the CPA exam. To check on the effectiveness of these services, 15 students were chosen. Five students were randomly assigned to service A,...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Describe some practical examples of the single-resource sequencing problem.
-
Consider the scatterplot in Figure 7.16. a. Which point is an outlier? Ignoring the outlier, estimate or compute the correlation coefficient for the remaining points. b. Now include the outlier. How...
-
Dan and Ellie share partnership profits and losses at 70% and 30%, respectively. The partners agree to admit Fran into the partnership for a 50% interest in capital and earnings. Capital accounts...
-
The rod has a circular cross section with a moment of inertia \(I\). If a vertical force \(\mathbf{P}\) is applied at \(A\), determine the vertical displacement at this point. Only consider the...
-
Zippy Inc. manufactures a fuel additive, Surge, which has a stable selling price of $44 per drum. The company has been producing and selling 80,000 drums per month. In connection with your...
-
13. Answer the following questions pertaining to the example program given. a. (16 pt.) After the program is executed, list the values contained in each of the registers and memory addresses shown....
-
Zero-coupon bonds (also called strip bonds or zeros for short) have a unique role to play in bond markets, because they only have one future cash flow. This means that you can check the price of any...
-
You are studying ethical theories. If the ethical theories were full-proof or shall we say, always resulted in an effective decision everyone could live with, ethical decision-making...
-
In response to a growing awareness of gluten allergies, Wildhorse Bakery tried using gluten-free flour in its three most popular cookies. After several attempts and a lot of inedible cookies, the...
-
A cohabitation agreement occurs when two people who are not married to each other and live together, commonly in an intimate relationship engage in a private contract. This contract would establish...
-
Warnerwoods Company uses a perpetual inventory system. It entered into the following purchases and sales transactions for March. Date March 1 March 5 Activities Beginning inventory Purchase March 9...
-
What must be included in the name of all corporations - as required by all states?
-
Read the case study Curled Metal Engineered Products Division and answer the following question: What should a customer be willing to pay for one of Curled Metal Incs (CMI) new cushion pads? What...
-
Marc Company assembles products from a group of interconnecting parts. The company produces some of the parts and buys some from outside vendors. The vendor for Part X has just increased its price by...
-
A two-story shear building is shown in Fig. 7.14 in which the floors are assumed to be rigid. Using Rayleigh's method, compute the first natural frequency of the building for \(m_{1}=2 m, m_{2}=m,...
-
What is the role of Choleski decomposition in deriving a standard eigenvalue problem?
-
How do you find the inverse of an upper triangular matrix?
Study smarter with the SolutionInn App