Question: Using JAVA a) Write a void method (call it argumentExampleOne) that takes an integer argument, modifies its value to be twice as much as originally,

Using JAVA a) Write a void method (call it argumentExampleOne) that takes an integer argument, modifies its value to be twice as much as originally, and prints it. In your main, create an int variable int myNum = 10, then call argumentExampleOne(myNum), then print the variable myNum below that. What do you observe? Write a few words about what is happening as a block comment above this method in your code.

b) Write a void method (call it argumentExampleTwo) that takes a Scanner object as argument, and first prints the next two strings from it. Then in the same method (below the prints), reassigns the Scanner object (i.e. you should create a new Scanner associated with the same file as it was done in main and reassign the argument variable). Finally, below the reassignment, it should print the next word. In main create a Scanner object associated with the file "scannerExample.txt" (file provided - see Canvas), call your method with this Scanner as argument, then below your call print the next thing from your Scanner object. What do you observe? Write a few sentences about what is happening as a block comment in your code.

c) A more involved Scanner exercise - we have a file where each line contains the name of a student (as a single string) followed by his/her quiz grades for the quarter (doubles). The data is all space separated and is in a file called quizGrades.txt (file provided - see Canvas). Our goal is to generate an output file called "output.txt" that contains the average quiz grade for each student on each line, for example: alice: 8.4 bob: 3.7 ... To accomplish this goal, we will declare the Scanner and PrintWriter objects in main, but not use them there...instead (for the sake of modularity and a learning exercise) we will pass them to methods that will divide the labor: public static double quizAverage(Scanner s) - this method takes a Scanner object. You may assume this Scanner is ready to read data of type double. This method should read all the doubles, find and return their average. public static void classGrades(Scanner s, PrintWriter p) - this method should take a Scanner object and a PrintWriter object as arguments. The purpose of this method is to write the names of students (from the Scanner s) along with the average quiz grade for that student on each line of the file associated with the PrintWriter p. This method should call the quizAverage method in order to get the average grade for each student. In a block comment, explain the behavior of the Scanner object as it was passed along from method to method. Also, if your output file is blank, maybe you forgot to do something important at the end of your main...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!