The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Hello I need help with my Java CSS 161 program anyone who writes a program for all the portions of the assignment below will get full points thank u!!!
a) Write method called raggedCount that takes an integer n as argument and returns a ragged array of n rows of lengths 1, 2, 3, 4, ... , n and the whole array has the integers 1, 2, 3, 4, ... , (+1) 2 in row order. For example, raggedCount(4) should return the array: 1 2 3 4 5 6 7 8 9 10
b) Write a method called arrayConcat that takes as argument two arrays a1 and a2 and returns an array that is the concatenation of the two arrays with the items of a2 following those of a1.
c) In the main method, write tests and print the results for all of the methods above. Feel free to implement helper printer methods to print your arrays (or simply implement those loops in main - you are welcome to use the Arrays.toString method).
3. Argument Passing In this part of the lab we will explore argument passing.
In Java we can pass information that methods need in order to do their jobs via arguments. However, arguments of primitive type or immutable class type have a different behavior than that of mutable class type.
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: 3 • 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..