Advertisement
Guest User

Untitled

a guest
Apr 13th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.21 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:async';
  4.  
  5. class Student
  6. {
  7.   //varibale aspect of the student class
  8.   //the majority are already provided by the input file
  9.   int studentID;
  10.   int claScore;
  11.   int olaScore;
  12.   int quizScore;
  13.   int examScore;
  14.   int finalScore;
  15.   int totalPoints;
  16.   String letterGrade;
  17.  
  18.  
  19.   /*default constructor, commented out as we wont need it due to having the paremters
  20.      Student()
  21.     {
  22.    
  23.     }
  24.   */
  25.  
  26.   //paremeterized constructor, uses the data given in the input to create students
  27.   Student(int stuID, int claS, int olaS, int quizS, int examS, int finalS)
  28.   {
  29.       print("Student Created \n");
  30.        
  31.       studentID = stuID;
  32.       claScore =  claS;
  33.       olaScore = olaS;
  34.       quizScore = quizS;
  35.       examScore = examS;
  36.       finalScore = finalS;
  37.   }
  38.  
  39.   //deconstructor
  40.   //Not nesscecary since darts contains active garbage collection
  41.  
  42.   //could not have been typed a "setter" due to them needing to pass only 1 paremeter
  43.   //however can still be used as a "method"
  44.   //talies up the points for the total  
  45.   void setTotalPoints(int stuID, int claS, int olaS, int quizS, int examS, int finalS)
  46.   {
  47.     totalPoints = stuID + claS + olaS + quizS + examS + finalS;      
  48.   }
  49.  
  50.   //could have been typed as "int TotalPoints" making it a method
  51.   //however in practice of utilizing Darts features, made it a
  52.   //direct "getter" using the "get" keyword
  53.   int get TotalPoints
  54.   {
  55.     return totalPoints;
  56.   }
  57.  
  58.   //typed as a "setter" since it only passes one parameter
  59.   //checks the value of the of the total points
  60.   //and a assigns a string to it, dart has no chars
  61.   void setLetterGrade(int TotalP)
  62.   {
  63.     if (TotalP >= 90)
  64.     {
  65.       letterGrade = "A";
  66.     }
  67.      
  68.     else if (TotalP >= 87 && TotalP  <90)
  69.     {
  70.       letterGrade = "B+";
  71.     }
  72.  
  73.     else if (TotalP >=83 && TotalP <87)
  74.     {
  75.       letterGrade = "B";
  76.     }
  77.  
  78.     else if (TotalP >=80 && TotalP <83)
  79.     {
  80.       letterGrade = "B-";
  81.     }
  82.  
  83.     else if (TotalP >=77 && TotalP <80)
  84.     {
  85.       letterGrade = "C+";
  86.     }
  87.  
  88.     else if (TotalP >=73 && TotalP <77)
  89.     {
  90.       letterGrade = "C";
  91.     }
  92.  
  93.     else if (TotalP >=70 && TotalP<73)
  94.     {
  95.       letterGrade = "C-";
  96.     }
  97.  
  98.     else if (TotalP >=67 && TotalP <70)
  99.     {
  100.       letterGrade = "D+";
  101.     }
  102.  
  103.     else if (TotalP >=63 && TotalP <67)
  104.     {
  105.       letterGrade = "D";
  106.     }
  107.  
  108.     else if (TotalP >=60 && TotalP <63)
  109.     {
  110.       letterGrade = "D-";
  111.     }
  112.  
  113.     else
  114.     {
  115.       letterGrade = "F";
  116.     }
  117.   }
  118.  
  119.      String getLetterGrade()
  120.    {
  121.      return letterGrade;
  122.    }
  123. }
  124.  
  125.  
  126.  
  127. /*
  128. class Roster
  129. {
  130. Define a class Roster, which has an associative array
  131. (other similar data structures like map, hash map are also fine)
  132.  to store all Student objects. Define appropriate methods in the class
  133.  to calculate, update, and query individual student information as well
  134.   as required statistic information of all students.
  135. }
  136. */
  137.  
  138.  
  139.  
  140. void main() async
  141. {
  142.  
  143.   //Greets the user and prompts for the file scores.txt
  144.   print("Hello, please enter the file you would like to open (including the file exstension)");
  145.  
  146.    //User should be requesting this fiile specifically
  147.   String properFile = "scores.txt";
  148.  
  149.   //takes input from the user
  150.   String requestedFile = stdin.readLineSync();
  151.  
  152.   //as long as the user fails to enter "scores.txt", they will be reprompted for the proper file
  153.   //this is hardcoded in such a way to work specificcaly for this project. Standard programs will be more flexible
  154.   while (requestedFile != properFile)
  155.   {
  156.     print("incorrect file, please try again");
  157.     requestedFile = stdin.readLineSync();
  158.   }
  159.  
  160.   //the proper file has been submitted, Hooray!
  161.   //we will now use the variable "myFile" to holds scores.txt, by waiting till after
  162.   //the user submits the correct input we'll hold onto whatever memoery we can
  163.   //we also create a 2nd variable which we will transfer the information into called "contents"
  164.   var myFile = File(properFile);
  165.   Stream<List<int>> inputStream = myFile.openRead();
  166.  
  167.   Stream<String> lines = inputStream
  168.   // Decode to UTF8.
  169.   .transform(utf8.decoder)
  170.   // Convert stream to individual lines.
  171.   .transform(new LineSplitter());
  172.  
  173.   try
  174.   {
  175.   await for (String line in lines) print('$line');
  176.   }
  177.   catch (e)
  178.   {
  179.   print(e.toString());
  180.   }
  181.  
  182. print(lines);
  183. print(inputStream);
  184. //print(lines[10]);
  185. //print(lines[18]);
  186.  
  187.  
  188.  
  189.  
  190.  
  191.   print('File is now closed.');
  192.  
  193.  
  194.  
  195.  
  196.   //  Stream<List<int>> inputStream = myFile.readAsStringSync() as Stream<List<int>>;
  197.   // ^^ PLan B ^^
  198.   //String inputStream = myFile.readAsStringSync();
  199.  
  200.  
  201.  
  202.  
  203.   //22 studnets in this file
  204.   //minus the header which is uneeded
  205.   //0 - 21
  206.  
  207.  
  208.  
  209.   //once last check to cover our butts, since Dr. Dong wants the user to be prompted for the file
  210.  //we still have to check if the file is actually in the directory
  211.  //this is made easy in dart with the ".exist" method
  212.   if ( await myFile.exists())
  213.   {
  214.     //because im not familiar enough with Darts asynchrous proccesses
  215.     //I'm going to force the code to run synchronously
  216.     //this is done with readAsStringSync rather than readAsString"
  217.       // contents = await myFile.readAsStringSync();
  218.       // print(contents);
  219.   }
  220.  
  221.   else
  222.   {
  223.     print("Error: File not found");
  224.   }
  225.  
  226.  
  227.   //count how many lines get read in from file
  228.   //set a variable to that respective number (ex: # of students)
  229.  
  230.   //do a for loop that takes the respective input per student
  231.   //an create the students with the relative information
  232.  
  233.   //while storing them in the
  234.  
  235.  
  236.  
  237.  
  238.   // NEED counter to keep track of performed queries.
  239.   // when counter <= 2 perform q1/q2
  240.   // when counter >2 perform full list
  241.  
  242.   //q1 : the user inputs C#, and your program should print all
  243.   //information (including his/her final letter grade) of the student with the given C#.
  244.  
  245.   //q2 : the user inputs C#, and your program should print all
  246.   //information (including his/her final letter grade) of the student with the given C#.
  247.  
  248.   //After two queries, your program print information of all students as well as the average and
  249.   //highest scores of CLA, OLA, quizzes, exams, and final exam on the screen.
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement