Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Credit Hours

dickersonka
dickersonka 


Java Homework 7 General description for homework 7: In this homework, your program will define and populate values into a ragged array, and then use a loop to process this array to obtain the sum. At last, output the obtained result to the screen. Here is the detail description for homework 7: Use console input Scanner class and console output method with format: System.out.printf() . No GUI is needed in this homework. In the main method, then follow the STEPS below: 1. Declare a two-dimensional array that hold int type values, with its first dimension set to be 3. This array is to hold the number of credit hours for each student in three classes. However, the number of students in these three classes may vary. 2. Use the Scanner class to ask for one integer input, representing the number of students in the first class. Repeat this process for the other two classes. When this step is finished, you have three local variables representing the number of students in three classes, respectively. The values of these three local variables depend on the user input, and usually they are not the same. 3. Use the three local variables from the step above, and use the keyword new to define the second dimension for the two-dimensional array, so that each array element in the first dimension holds the exact number of elements for each class. You need to use three separate new statements to achieve this. Refer to file “RaggedArrayDemo.java” in folder chap7 as an example for implementing step 2 and 3. 4. invoke method getInput, and pass the two-dimensional array as the only formal parameter, and this method should have no return value. Inside this method, use an embedded loop to ask for input of each student’s credit hours in these three classes. An input variable of Scanner class type should be used. Refer to file “RaggedArrayDemo.java” and “PassTwoDimensionalArray.java” on how to traverse two-dim array with embedded loop. 5. invoke method calcTotal, and pass the two-dimensional array as the only formal parameter, and this method should return the sum of the all credits in three classes. Inside this method, use an embedded loop to calculate the total credit hours of all students in three classes. In the main method, use a local variable to receive the return value. Refer to file“RaggedArrayDemo.java” and “PassTwoDimensionalArray.java” on how to traverse two-dimension array with embedded loop. 6. Output the total sum to the console. Implementation requirement: • In class you should have three methods. One is the main method, and the other two methods are getInput and calcTotal. Do not put more classes or more methods in the homework, o/w, you are in the wrong track. • Inside the main method, you invoke method getInput and calcTotal. • The signature and return type of method getInput and calcTotal have already been defined in step 4 and 5 above, and you cannot change the signature or the return type of these two methods. • The return value of method calcTotal is being used in main method for output purpose. • Add suitable comments in the source code. • Please read the above implementation details carefully BEFORE start coding. • After finishing coding, you need to debug your program and test it multiple times with different input parameters provided for each test run. Attachments Tags Clarifications

Answers

Java - Credit Hours - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Credit Hours assignment including source and comments Attachments
CreditHours.java (1 K) Download Preview
students in first class: "); int numStudents1 = input.nextInt(); //prompt for num students in class 2 System.out.printf("Enter num students in second class: "); int numStudents2 = input.nextInt(); //prompt for num students in class 3 System.out.printf("Enter num students in third class: ");

CreditHours_output.png (6 K) Download Preview

Screenshots
Screenshot
Purchase Answer