Question: Note: If your language of choice is Web Development, you will need to complete the exercises in both PHP and JavaScript. Using the language in
Note: If your language of choice is Web Development, you will need to complete the exercises in both PHP and JavaScript. Using the language in which you have chosen to focus: C#, Java, web development languages (PHP and JavaScript), please complete the following assessment: Assessment Requirements The program for this assessment will consist of three sections, each headed by the three-line comment below: //********************************************************* //****Assessment IT213M2 Section X //********************************************************* (where X stands for the portion of the assessment to follow)
Section 1: Enter the comment with the section title. Using a while loop structure, create a loop based on a counter variable which will cycle through 10 iterations. With each iteration of the loop, request a grade from the user and add it to a running total. After the loop has ended, print to the console the overall total and the class average. Define any appropriate variables you need.
Section 2: Enter the comment with the section title. Create a set of two nested for loops. The outer loop will iterate from 5 to 1, decrementing by 1 with each consecutive iteration. Use the letter k for its counter variable name. The inner loop will iterate from 0 to 10 by 2. Use the letter i for its counter variable. Hint: Use the += operator to increment by 2. With each iteration of the inner loop, print both loop index values such as k = 5, i = 0
Section 3: Enter the comment with the section title. Use a while loop to process user entered numbers. Inform the user to enter a positive number to be added to the total or -1 to end. With each iteration of the loop, add the user entered value to a running total. End the loop when the user enters -1 and do not add that value to the running total. Once the loop ends, print the total of the numbers entered, (excluding the sentinel value -1.) Define the appropriate variables needed. POSSIBLE EXPECTED OUTPUT
Enter grade: 88
Enter grade: 78
Enter grade: 98
Enter grade: 99
Enter grade: 67
Enter grade: 78
Enter grade: 79
Enter grade: 100
Enter grade: 87
Enter grade: 56
Total of all 10 grades is 830
Class average is 83
k = 5, i = 0 k = 5, i = 2 k = 5, i = 4 k = 5, i = 6 k = 5, i = 8 k = 5, i = 10 k = 4, i = 0 k = 4, i = 2 k = 4, i = 4 k = 4, i = 6 k = 4, i = 8 k = 4, i = 10 k = 3, i = 0 k = 3, i = 2 k = 3, i = 4 k = 3, i = 6 k = 3, i = 8 k = 3, i = 10 k = 2, i = 0 k = 2, i = 2 k = 2, i = 4 k = 2, i = 6 k = 2, i = 8 k = 2, i = 10 k = 1, i = 0 k = 1, i = 2 k = 1, i = 4 k = 1, i = 6 k = 1, i = 8 k = 1, i = 10
Enter a positive number to be added to the total or -1 to end. 3
Enter a positive number to be added to the total or -1 to end. 4
Enter a positive number to be added to the total or -1 to end. 5
Enter a positive number to be added to the total or -1 to end. 8
Enter a positive number to be added to the total or -1 to end. -1
The sum of all numbers entered is 20 Would prefer the code in Java or C#
Have the following code, but something isn't correct?
import java.util.Scanner;
public class Loops { public static void main(String[] args) { // declare scanner instance Scanner scanner = new Scanner(System.in);
//********************************************************* //****Assessment IT213M2 Section 1 //*********************************************************
System.out.println("***SECTION 1***"); // declare varibales int counter = 0; int grade; int totalGrade = 0; // iterate till the counter value is 10 while (counter != 10) { // get grade from user System.out.print("Enter grade: "); grade = scanner.nextInt(); // add grade to the total totalGrade += grade; // increment the counter value counter++; } // Print the value to the user System.out.println("Total of all " + counter + " grades is " + totalGrade); // print the average System.out.println("Class average is " + totalGrade / counter);
//********************************************************* //****Assessment IT213M2 Section 2 //********************************************************* System.out.println(" ***SECTION 2***"); // outer loop will iterate from 5 to 1, decrementing by 1 for (int k = 5; k >= 1; --k) { // inner loop will iterate from 0 to 10 by 2. for (int i = 0; i <= 10; i += 2) { // print the values of k and i System.out.println("k = " + k + ", i = " + i); } } //********************************************************* //****Assessment IT213M2 Section 3 //*********************************************************
System.out.println(" ***SECTION 3***"); // declare a variabel to hold user input and total int userInput = 0; int userTotal = 0; // iterate till the user enters -1 while (userInput != -1) { System.out.print("Enter a positive number to be added to the total or -1 to end. "); // get user input positive number userInput = scanner.nextInt(); if (userInput != -1) { // add the user entered value to a running total userTotal += userInput;
} } // print the total of the numebrs entered System.out.println("The sum of all numbers entered is " + userTotal); // close the scanner instance scanner.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
