Question: 1. (5 points) Method Overloading: Given the following methods, write down the printed output of the method calls. Try first by eye, then verify


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);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
