eightmoons

Main.java

Mar 26th, 2020
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.Random;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.  
  10.     public static String getRandomAnswers(){
  11.         Random random = new Random();
  12.         StringBuilder answers = new StringBuilder();
  13.         do{
  14.             int rand = random.nextInt(100);
  15.             if (rand % 2 == 0) {
  16.                 answers.append("F");
  17.             }
  18.             else if (rand % 4 == 3) {
  19.                 answers.append(" ");
  20.             }
  21.             else {
  22.                 answers.append("T");
  23.             }
  24.         }while(answers.length() != 20);
  25.         return answers.toString();
  26.     }
  27.  
  28.     public static void main(String []args) throws IOException {
  29.         int stdCounter = 1;
  30.         StringBuilder longString = new StringBuilder();
  31.         longString.append("TFFTFFTTTTFFTFTFTFTT\n");
  32.         do {
  33.             longString.append(String.format("STUDENT00%s %s\n", stdCounter, getRandomAnswers()));
  34.             stdCounter++;
  35.         }while (stdCounter <= 15);
  36.         FileWriter wr = new FileWriter("students.txt");
  37.         wr.write(longString.toString());
  38.         wr.close();
  39.  
  40.         File studentAnswers = new File("students.txt");
  41.         Scanner answerScanner = new Scanner(studentAnswers);
  42.         char[] correctAnswer = {};
  43.         while (answerScanner.hasNextLine()) {
  44.             if (correctAnswer.length == 0) {
  45.                 correctAnswer = answerScanner.nextLine().toCharArray();
  46.             }
  47.             else {
  48.                 String[] data = answerScanner.nextLine().split(" ", 2);
  49.                 String studentId = data[0];
  50.                 String answers = data[1];
  51.                 double points = 0;
  52.                 char[] x = answers.toCharArray();
  53.                 for (int i = 0; i<x.length; i++) {
  54.                     char ans = x[i];
  55.                     if (ans == ' ') {
  56.                         points += 0f;
  57.                     }
  58.                     else if (ans == correctAnswer[i]) {
  59.                         points += 2f;
  60.                     }
  61.                     else if (ans != correctAnswer[i]){
  62.                         points -= 1f;
  63.                     }
  64.                 }
  65.                 double grade = (points / 40.0f) * 50.0f + 50.0f;
  66.                 char mark = 'F';
  67.                 if (grade >= 90 && grade <= 100)
  68.                     mark = 'A';
  69.                 else if (grade >= 80 && grade <= 89.99)
  70.                     mark = 'B';
  71.                 else if (grade >= 70 && grade <= 79.99)
  72.                     mark = 'C';
  73.                 else if (grade >= 60 && grade <= 69.99)
  74.                     mark = 'D';
  75.  
  76.                 System.out.println(String.format("%s %s (%s %s", studentId, answers, mark, grade) + "%)");
  77.             }
  78.  
  79.         }
  80.     }
  81. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×