So this is something im supposed to understand. Everything is written out, but whenever I try to code it myself I get errors and stuff. Of course I've asked my teacher and TAs for help, but they dont like giving out answers straight up, and I end up confused again. Could I get some help? (I was also informed that there was a typo by my TA, and he's not really clearing it up.)
4 2 6 m * C Q M @YoobeanDed X Lab5 X CPSC 1060 lab5 Fall 2020.pdf X + X - - C D @ File | C:/Users/texti/Downloads/CPSC%201060%20lab5%20Fall%202020.pdf When you write a Java program that contains methods, you can define your methods either above or below the main method. Methods should be located withing the same class, but outside the main program. Whether you opt for defining them above or below main, define all your methods at the same place to be consistent. Part 2. 1. In this lab you will create a class MethodDemo.java. Above your main method define a method called mysteryMethod1. Your method will accept two formal parameters: a double and a String. Your method will return a String. In the body of your method you will concatenate your String argument with the double value using a plus operator to create a new string. This new string will then be returned to main. You will need to declare a variable of double type in main to store the return value of this method call. This variable will be then printed. 2. Now overload this method to accept an integer and a String. Concatenate your String and integer and return them to main to be printed. This time place the method call directly into a System.out.printin statement to be printed without storing the result in a variable. 3. Now create a void method mysteryMethod2 that accepts two integers. In the body of the method calculate the sum of the two integers and print it. Call this method from main. 4. Now overload this method to accept two doubles. Calculate the sum of the two doubles and print it. Call this method from main. 5. Compile and run your program and this time use output redirection. If you remember from one of the previous chapters, output redirection prints program output into a file instead of printing it to the screen (screen is the standard output device). To redirect your output into a file, use > (right angle bracket operator), instead of the left angle bracket that is used with input redirection. Example shown below redirects output from a Screenshot saved The screenshot was added to your program into a file named output. txt: OneDrive. OneDrive java SomeProgram > output.txt Type here to search O EI M N 2:23 PM 9/28/20204 2 6 m * C Q M Homework Help X @YoobeanDed X Quiz: Lesson 10 - X Post Attendee - Z X CPSC 1060 lab5 F X G how to screen re X + X - - C D @ File | C:/Users/texti/Downloads/CPSC%201060%20lab5%20Fall%202020.pdf 4. Now overload this method to accept two doubles. Calculate the sum of the two doubles and print it. Call this method from main. 5. Compile and run your program and this time use output redirection. If you remember from one of the previous chapters, output redirection prints program output into a file instead of printing it to the screen (screen is the standard output device). To redirect your output into a file, use > (right angle bracket operator), instead of the left angle bracket that is used with input redirection. Example shown below redirects output from a program into a file named output.txt: java SomeProgram > output.txt Mark Tolchinsky C After running your program and redirecting output into a file, open that file to make sure your output is correct. 6. To view the contents of the file without opening it in an editor, you can use the "caf" command on the Linux command line. This command concatenates (hence the abbreviation cat), or appends the contents of the file to the output device (screen). You 2 cannot edit your files while using the cat command, but you can quickly preview the content. This will also work with any source code or text files. Example is shown below. cat output.txt Type here to search O EI M N G 2:54 PM 9/28/2020 ES4 2 6 m * C Q M @YoobeanDed X Lab5 X CPSC 1060 lab5 Fall 2020.pdf X + X - - C D @ File | C:/Users/texti/Downloads/CPSC%201060%20lab5%20Fall%202020.pdf Introduction In this lab you will write void and value-returning methods and use method overloading. You will also learn another useful Linux command (cat) and use output redirection. Lab Objectives By the end of the lab, you should: Define void and value-returning methods; . Overload methods; . Call overloaded, void, and value returning methods from main; Use output redirection; Preview file contents using cat command. Part 1. Methods that return a value are called value-returning methods. They require a return statement as the last statement in the method, so they can return the value of calculation back to the main program that called them. When you call a value-returning method from the main, the method call in main will be replaced by the value returned from the method. The return value needs to be stored in a variable of the same type as the return value type. Void methods do not return a value and do not need a return statement. Since they do not return a value, you can call these methods in the main program without having to store the return value in a variable. These methods are commonly used to print messages, menus, set values of global variables, etc. We will encounter more void methods in the future when we talk about classes. Method overloading is a powerful feature of Java programming language (and some other languages) that allows us to change the method signature. If you remember from the lectures, method signature includes method name and the list of formal parameters. Overloading has several rules: 1. Return value types (if any) of the overloaded methods are the same. 2. Method names of the overloaded methods are the same. 3. The list of incoming parameters are different, and can have any number of formal parameters of any types. Type here to search O M 2:23 PM 9/28/2020 EA