Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA You will use only 3 loops. 1. Do loop 2. While loop 3 For Each loop Modify Prog 5 to produce the same

In JAVA

You will use only 3 loops.

1. Do loop

2. While loop

3 For Each loop

Modify Prog 5 to produce the same output, but only use 3 loops in the entire program. Do not ask for number of grades to enter, keep entering grades for a category until a negative number is entered.

Code to modify:

import java.util.Scanner;

public class HW6Practice {

public static void main(String[] args) {

// TODO Auto-generated method stub

int grade2;

int grade3;

int grade4;

int grade5;

int grade1;

int progWork; //Final Grades for each section.

int homeWork;

int labs;

int quiz;

int reading;

int exam1;

int exam2;

int exam3;

int finalExam;

int total;

double programPercent = .15; // Grading percentages

double homeworkPercent = .10;

double labsPercent = .05;

double quizPercent = .10;

double readingPercent = .10;

double exam1Percent = .05;

double exam2Percent = .10;

double exam3Percent = .15;

double finalexamPercent = .20;

Scanner scan = new Scanner(System.in); //Scanner to enter grades

//Programming grades enter.

System.out.println("Insert 5 programming grades separated by one space!");

System.out.println("");

grade1 = scan.nextInt();

grade2 = scan.nextInt();

grade3 = scan.nextInt();

grade4 = scan.nextInt();

grade5 = scan.nextInt();

progWork = (grade1 + grade2 + grade3 + grade4 + grade5);

progWork = (progWork / 5);

System.out.print("Progamming avergae is: ");

System.out.println(progWork);

System.out.println("");

progWork = (int) (progWork * programPercent);

System.out.println("Programming work is " + progWork +" of your final grade.");

System.out.println("");

System.out.println("Insert 5 homework grades seperated by a space!");//HW Grades

System.out.println("");

grade1 = scan.nextInt();

grade2 = scan.nextInt();

grade3 = scan.nextInt();

grade4 = scan.nextInt();

grade5 = scan.nextInt();

homeWork = (grade1 + grade2 + grade3 + grade4 + grade5);

homeWork = (homeWork / 5);

System.out.print("Homework average is: ");

System.out.println(homeWork);

System.out.println("");

homeWork = (int) (homeWork * homeworkPercent);

System.out.println("Homework is " + homeWork + " of your final grade.");

System.out.println("");

System.out.println("Insert 5 Lab grades separated by a space!");// Lab Grades

System.out.println("");

grade1 = scan.nextInt();

grade2 = scan.nextInt();

grade3 = scan.nextInt();

grade4 = scan.nextInt();

grade5 = scan.nextInt();

labs = (grade1 + grade2 + grade3 + grade4 + grade5);

labs = (labs / 5);

System.out.print("Labs average is: ");

System.out.println(labs);

System.out.println("");

labs = (int) (labs * labsPercent);

System.out.print("Lab is " + labs + " of your final grade.");

System.out.println(labs);

System.out.println("");

System.out.println("Insert 5 Quiz grades separated by a space!"); // Quiz grades

System.out.println("");

grade1 = scan.nextInt();

grade2 = scan.nextInt();

grade3 = scan.nextInt();

grade4 = scan.nextInt();

grade5 = scan.nextInt();

quiz = (grade1 + grade2 + grade3 + grade4 + grade5);

quiz = (quiz / 5);

System.out.print("Quiz average is: ");

System.out.println(quiz);

System.out.println("");

quiz = (int) (quiz * quizPercent);

System.out.println("Quizzes are " + quiz + " of your final grade.");

System.out.println("");

System.out.println("Insert 5 reading grades separated by a space!"); //reading grades

System.out.println("");

grade1 = scan.nextInt();

grade2 = scan.nextInt();

grade3 = scan.nextInt();

grade4 = scan.nextInt();

grade5 = scan.nextInt();

reading = (grade1 + grade2 + grade3 + grade4 + grade5);

System.out.print("Reading average is: ");

System.out.println(homeWork);

System.out.println("");

reading = (int) (reading * readingPercent);

System.out.println("Reading is " + reading + " of your final grade.");

System.out.println("");

//Exams

System.out.println("Insert first exam grade.");

exam1 = scan.nextInt();

exam1 = (int) (exam1 * exam1Percent);

System.out.println("Exam 1 weighs " + exam1);

System.out.println("");

System.out.println("Insert second exam grade.");

exam2 = (int) scan.nextDouble();

exam2 = (int) (exam2 * exam2Percent);

System.out.println("Exam 2 weighs " + exam2);

System.out.println("");

System.out.println("Insert third exam grade.");

exam3 = (int) scan.nextDouble();

exam3 = (int) (exam3 * exam3Percent);

System.out.println("Exam 3 weighs " + exam3);

System.out.println("");

System.out.println("Insert final exam grade.");

finalExam = (int) scan.nextDouble();

finalExam = (int) (finalExam * finalexamPercent);

System.out.println("Third Final Wieght : " + finalExam);

System.out.println("");

//Final Grade

total = (homeWork + progWork + labs + quiz + reading +

exam1 + exam2 + exam3 + finalExam);

total = ((total/140) * 100);

total = total/ 10;

switch (total) {

case 10:

case 9:

System.out.println("A");

break;

case 8:

System.out.println("B");

break;

case 7:

System.out.println("C");

break;

case 6:

System.out.println("D");

break;

default:

System.out.println("F");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions