Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mary Katherine Report Card Helper Issue: Mary Katherine is a nun at St. Ann’s Ac

ID: 3621486 • Letter: M

Question

Mary Katherine Report Card Helper

Issue:

Mary Katherine is a nun at St. Ann’s Academy for Troubled Youth. She is in need of a program that will help her produce a report card for her students. She teaches 4th grade for the academy and each of her students will get a score in Creative Writing, Reading, Math, and Art. She would like to be prompted for the maximum points allowed for the term, the points the student earned and then see the percentage for that grade on the final report card.

Specifications:

Name your file

Use a message box or scanner to prompt Mary Katherine for her input.

1. Ask for the term once (example Fall 2007)

2. Ask for each subject’s maximum points once

3. Ask for the student’s name or option to exit the program (exit strategy of your

choice)

4. Ask for the student’s score for each subject

5. Call the method to calculate the percent based on score and max score.

6. Call the method to print a report card including the term, student’s name, and

percent earned for each subject.

7. Repeat steps 3-6

You must have two methods in this program in addition to the main method.

The first method

will be used to take the student’s score and divide it by the

Maximum score for that subject to get the percentage. You will only have one

method to do this. An example of a call to this method from the main method

might look like:

o

mathPercent = calculatePercent(mathScore, mathMaxScore);

Notice

o

artPercent = calculatePercent(artScore, artMaxScore);

The second method will be passed the student’s name, term, and all the subject percentages to print the report card. A call to this method from the main method might look like:

o

printReportCard(studentName, term, mathPercent, artPercent, readingPercent, writingPercent);

Program Help:

Do not assume the user will make sure they are entering a score equal to or less than the maximum. You will need to check for that.

the lette

Explanation / Answer

import java.util.Scanner;
import java.io.*;

public class ReportCard
{
public static void main(String[] args) throws IOException
{
// keyboard input
Scanner kb = new Scanner(System.in);

//1. Ask for the term once (example Fall 2007)
System.out.print("Enter the term: ");
String term = kb.nextLine().trim();

//2. Ask for each subject’s maximum points once
System.out.print("Enter the maximum points for math: ");
double mathMax = kb.nextDouble();

System.out.print("Enter the maximum points for art: ");
double artMax = kb.nextDouble();

System.out.print("Enter the maximum points for reading: ");
double readingMax = kb.nextDouble();

System.out.print("Enter the maximum points for writing: ");
double writingMax = kb.nextDouble();



while(true)
{
kb.nextLine();

//3. Ask for the student’s name or option to exit the program (exit strategy of your choice)
System.out.print("Enter student name (or "exit" to exit): ");

String name = kb.nextLine();
if(name.equalsIgnoreCase("exit"))
{
break;
}

//4. Ask for the student’s score for each subject
System.out.print("Enter "+name+"'s math score: ");
double mathScore = kb.nextDouble();

// check for invalid scores
if(mathScore > mathMax || mathScore < 0)
{
System.out.println("Invalid score.");
continue;
}

System.out.print("Enter "+name+"'s art score: ");
double artScore = kb.nextDouble();

// check for invalid scores
if(artScore > artMax || artScore < 0)
{
System.out.println("Invalid score.");
continue;
}

System.out.print("Enter "+name+"'s reading score: ");
double readingScore = kb.nextDouble();

// check for invalid scores
if(readingScore > readingMax || readingScore < 0)
{
System.out.println("Invalid score.");
continue;
}

System.out.print("Enter "+name+"'s writing score: ");
double writingScore = kb.nextDouble();

// check for invalid scores
if(writingScore > writingMax || writingScore < 0)
{
System.out.println("Invalid score.");
continue;
}

//5. Call the method to calculate the percent based on score and max score.
double mathPercent = calculatePercent(mathScore, mathMax);
double artPercent = calculatePercent(artScore, artMax);
double readingPercent = calculatePercent(readingScore, readingMax);
double writingPercent = calculatePercent(writingScore, writingMax);

//6. Call the method to print a report card including the term, student’s name, and percent earned for each subject.
printReportCard(name, term, mathPercent, artPercent, readingPercent, writingPercent);

//7. Repeat steps 3-6
}
}


private static double calculatePercent(double score, double max)
{
return score/max*100;
}

// print report card to Name.dat
private static void printReportCard(String studentName, String term, double mathPercent, double artPercent, double readingPercent, double writingPercent) throws IOException
{
// open file output stream
PrintWriter fileout = new PrintWriter(new File(studentName+".txt"));

fileout.println("Report card for "+studentName+" for term "+term);
fileout.println("Math: "+mathPercent);
fileout.println("Art: "+artPercent);
fileout.println("Reading: "+readingPercent);
fileout.println("Writing: "+writingPercent);

// save file
fileout.close();
}
}