Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4. public class TestTutorialMark{
  5.  
  6. public static void main(String[] args){
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. TutorialMark person = new TutorialMark("", "", "", "");
  10.  
  11. System.out.print("Enter student's name: ");
  12. person.setName(scan.nextLine());
  13. System.out.print("Enter student's tutorial: ");
  14. person.setTutorial(scan.nextLine());
  15. System.out.print("Enter number of questions: ");
  16. person.setQuestions(scan.nextLine());
  17. System.out.println("# Enter questions in format: passed,total,value");
  18.  
  19. ArrayList<String> list = new ArrayList<String>();
  20.  
  21. double score;
  22. double total;
  23. double numQuestion;
  24. double avg = 0;
  25. double grandTotal = 0;
  26.  
  27. for(int i = 0; i < Integer.parseInt(person.getQuestions()); i++){
  28. System.out.print("Enter Q" + (i +1) + ": ");
  29. list.add(scan.nextLine());
  30. }
  31. System.out.println("\n# Moodle Summary");
  32. System.out.println(person.getName() + " - " + person.getTutorial());
  33.  
  34. for(int i = 0; i < list.size(); i++ ){
  35. if(list.sub){
  36. score = Integer.parseInt(list.get(i).substring(0,1));
  37. total = Integer.parseInt(list.get(i).substring(2,3));
  38. numQuestion = Integer.parseInt(list.get(i).substring(4,6));
  39.  
  40. avg = (score/total) * numQuestion;
  41. grandTotal += avg;
  42.  
  43. System.out.println("Q" + (i+1) + " (" + String.format("%.0f", score) + "/" + String.format("%.0f", total) + ") " + String.format("%.1f", avg));
  44. }
  45. else{
  46. score = Integer.parseInt(list.get(i).substring(0,1));
  47. total = Integer.parseInt(list.get(i).substring(2,3));
  48. numQuestion = Integer.parseInt(list.get(i).substring(4,5));
  49.  
  50. avg = (score/total) * numQuestion;
  51. grandTotal += avg;
  52.  
  53. System.out.println("Q" + (i+1) + " (" + String.format("%.0f", score) + "/" + String.format("%.0f", total) + ") " + String.format("%.1f", avg));
  54. }
  55. }
  56. System.out.println("\nTotal: " + grandTotal);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement