Loading
notes intro/old submit AP Problems the dump links
 

Programming activity:

 

mistakes m0,m1,m2,g1,g2

 

You are going to create a program that is going to use the scanner class to read in a data file (which must be in the same directory as your project (not the src) with student answers on it.

Start with the code below:

  • Create a method called numWrong that will take in an argument of the questionNumber and return how many students got it wrong.
  • Create another method called printTable that will print out a table (with nice formating (use /t for tab)) of the question number and how many students got wrong. Use your previous method above and a for loop.
  • EXTRA CREDIT create a method public void int numSelected (int questionNumber, int selection) that will return how many students selected that answer for that question. So if they put in numSelected(1,1) it would return 0 (no students choose 1 for question 1. Now put that method into the table.
***************************************
question#        	#wrong  	precent
=========			=======		=======
1					2    		12%
...




import java.io.*;
import java.util.Scanner;
public class Test1Analyze
{
	Scanner scan;  
	String correctAnswers="44552123132225254334542442321141"; 
	/*
	 * The constructor below will automatically read in the file.
	 */
	public Test1Analyze() 
	{
		try
		{
			scan=new Scanner (new File("test1Answers.txt"));
		}
		catch (IOException e)
		{			
		}
	}

	/*
	 * This method will take in an argument of the questionNumber and return how many students got it wrong. 
	 */
	public int numWrong(int questionNumber)
	{
		scan.reset(); //this method will reset the scanner;
		while (scan.hasNext())
		{
			String gradeLine=scan.nextLine();
			System.out.println(gradeLine);
		}
		return 5; //this should return number wrong
	}     

	/*
	 * This method will print out a table with each question and the number that the class got wrong
	 */
	public void printTable()
	{

	}         

	public static void main(String[] args) {
		Test1Analyze t = new Test1Analyze();
		System.out.println(t.numWrong(12));

	}

}		
			
      

 

Rubric 8 points total:

  • 3 points method numWrong
    • finds the correct answer (1)
    • searchs for and counts the number wrong correctly (2)
  • 3 points method printTables
    • goes through every question finding num wrong for each (1)
    • finds percent correctly (1)
    • looks good (tabbed nicely) (1)
  • 1 point commenting
  • 1 point indentation and variable names

To read, use

while (scan.hasNext())

String line=scan.nextLine();