Question

E zyBook 21: 198: 102 home> 5.2: Arrays (int courseGrades(4), the second with a 2-element array (int courseGradesl2), See How to Use zyBooks Also note: If the submitted code tries to access an invalid array element, such as courseGrades(9j for a 4-element array, the test may generate strange results. Or the test may crash and report Program end never reached, in which case the system doesnt print the test case that caused the reported message. 1 Import java.util.Scanner; 3 public class CourseGradePrinter 4 public static void main (String [1 args) f final int NUM VALS 4; int[] courseGrades -new int[NUN VALS] int i courseGrades(1 7 courseGrades[1] 9 courseGrades[21 11 courseGrades(3] 10 10 12 13 14 Your solution goes here 16 Please do it in java thanks a lot
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) CourseGradePrinter.java

package test;

import java.util.Scanner;

public class CourseGradePrinter {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in); // scanner object for takinginput

       final int NUM_VALS = 4;
       int[] courseGrades = new int[NUM_VALS]; // creating int array of size 4
       int i;

       // intialising array
       courseGrades[0] = 7;
       courseGrades[1] = 9;
       courseGrades[2] = 11;
       courseGrades[3] = 10;

       // infinite loop
       while (true) {
           // taking input
           System.out.print("Enter index : ");
           i = sc.nextInt();
           if (i > NUM_VALS) {
               System.out.println("ERROR! invalid index..exiting");
               break;
           }
           System.out.println("Your marks : " + courseGrades[i]+"\n\n"); // priniting
                                                                   // marks
       }

   }

}

Java test/src/test/CourseGradePrinter.java Eclipse File Edit Source Refactor Navigate Sech Project Run Window Help Quick Access l:|ぱし掣Java貵Debug 焓Java EE Package.. 23 Te Type Hi JU JUnit -B r) CourseGradePrinte -Java X 曰 皂鸟| 10 final int NUM VALS-4; Src int courseGrades-new int [NUM VALS // creating nE array of size 4 int i; ︾串test 12 13 ArrayMultiSet.java Colorjava CourseGradePrinter.java CourseSection.java Driverjava Entry java ExecuteService3a.java FinalExcercise.java FlightService3.java FormatNames.java Guess.jeva 15 16 17 18 19 // intialising array courseGrades [07 courseGrades[19 cour seGrades [2] = 11; courseGrades [3]10; // infinite loop while (true) 21 // taking input System. out.print (Enter index) 1 sc.next Int () ; if (i > NUM VALS) { DHotelService3.java Instructorjava 26 27 System.out.println(ERROR! invalid index..exiting) break; 29 System. out.printin (Your marks courseGrades [n / priniting MailMerge,java // marks 31 Messages jeva Movie.java MultiDimentionalArray.java NumberQueue.java PayRoll.java Purging,java recursionjava Roman,java Problems Javadoc Declaration Search Debug ConsoX <terminated> CourseGradePrintJava Application] CProgram Files Javare binjavaw.exe ( Enter index 2 Your marks : 11 2018, 7:10:48 am Enter index 10 ERROR! invalid index. .exiting Testjava

Add a comment
Know the answer?
Add Answer to:
Please do it in java thanks a lot E zyBook 21: 198: 102 home> 5.2: Arrays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 7.2.3: Printing array elements with a for loop. Write a for loop to print all elements...

    7.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) Also note: If the submitted code tries to access an invalid...

  • in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first...

    in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first three elements of array run Times. Follow each statement with a newline. Ex: If runTime = (800,775, 790, 805, 808) print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5 element array. See 'How to Use zyBooks". Also note: If the submitted code tries to access an invalid array...

  • C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop...

    C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. (Notes) Note: These activities may test code with...

  • Write three statements to print the first three elements of array runTimes. Follow each statement with...

    Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5-element array. See "How to Use zyBooks". Also note: If the submitted code tries to access an invalid array element, such as runTimes[9] for a 5-element array, the test...

  • Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to...

    Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40), then newScores = {20, 30, 40, 10). Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int oldScores[4]). See "How to Use zyBooks". Also note: If the submitted code tries to access an invalid array element, such as newScores[9] for a 4-element...

  • Unreachable statement??????? CSIT 111 home> 313: More string operations E zyBooks catalog Print 'Censored if userinput...

    Unreachable statement??????? CSIT 111 home> 313: More string operations E zyBooks catalog Print 'Censored if userinput contains the word 'darn, else print userinput. End with newline Note: These activities may test code with different test values. This activity will perform three tests, with userinput of That darn cat', then with Dang, that was scary!", then with I'm darning your socks.. See How to Use zyBooks . Also note: If the submitted code has an out-of-range access, the system will stop...

  • Arrays and Methods Worksheet 2 (10 pts) Copy the following into a new file called ArrayMethods2.java....

    Arrays and Methods Worksheet 2 (10 pts) Copy the following into a new file called ArrayMethods2.java. Write the methods one-by-one. Compile and run your code after you write each method to make sure it was written properly. When your methods pass all of the tests, upload your file to Canvas. /** * Assignment 20.2 * @author Your Name * CIS 36A */ public class ArrayMethods2 {     /**     * Given an array of ints, return the index of the...

  • Debug and fix the Java console application that uses 2 dimensional arrays but the application does...

    Debug and fix the Java console application that uses 2 dimensional arrays but the application does not compile nor execute. Student enters only integers to select courses for registration from a menu. No data type validation of the user menu selection is checked or required. The program terminates only when the student closes it. No registration of other courses not displayed by the program . No registration more than once for the same course. No registration for more than 9...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • IN JAVA please Given a sorted array and a target value, return the index if the...

    IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT