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
  • Write a for loop to print all elements in courseGrades, following each element with a space...

    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) Note: These activities may test code with different test values. This activity will perform two tests, both with a...

  • 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...

  • Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to...

    Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to sort." The actual question: Write a program as follows: Declare a five element array of Strings. Use a for loop and keyboard input to populate the array with the names of five friends. Sort the array in alphabetical order. Use a foreach loop to print the sorted array of friends, all on one line. Sample Output (inputs in italics) Enter the names of five...

  • Please complete in Java. Thanks in advance! Also, please note the solution in bold text. Thanks!...

    Please complete in Java. Thanks in advance! Also, please note the solution in bold text. Thanks! Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8. import java.util.Scanner; public class SumOfExcess {    public static void main (String...

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