Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'dart:io';
- import 'dart:async';
- class Student
- {
- //varibale aspect of the student class
- //the majority are already provided by the input file
- int studentID;
- int claScore;
- int olaScore;
- int quizScore;
- int examScore;
- int finalScore;
- int totalPoints;
- String letterGrade;
- /*default constructor, commented out as we wont need it due to having the paremters
- Student()
- {
- }
- */
- //paremeterized constructor, uses the data given in the input to create students
- Student(int stuID, int claS, int olaS, int quizS, int examS, int finalS)
- {
- print("Student Created \n");
- studentID = stuID;
- claScore = claS;
- olaScore = olaS;
- quizScore = quizS;
- examScore = examS;
- finalScore = finalS;
- }
- //deconstructor
- //Not nesscecary since darts contains active garbage collection
- //could not have been typed a "setter" due to them needing to pass only 1 paremeter
- //however can still be used as a "method"
- //talies up the points for the total
- void setTotalPoints(int stuID, int claS, int olaS, int quizS, int examS, int finalS)
- {
- totalPoints = stuID + claS + olaS + quizS + examS + finalS;
- }
- //could have been typed as "int TotalPoints" making it a method
- //however in practice of utilizing Darts features, made it a
- //direct "getter" using the "get" keyword
- int get TotalPoints
- {
- return totalPoints;
- }
- //typed as a "setter" since it only passes one parameter
- //checks the value of the of the total points
- //and a assigns a string to it, dart has no chars
- void setLetterGrade(int TotalP)
- {
- if (TotalP >= 90)
- {
- letterGrade = "A";
- }
- else if (TotalP >= 87 && TotalP <90)
- {
- letterGrade = "B+";
- }
- else if (TotalP >=83 && TotalP <87)
- {
- letterGrade = "B";
- }
- else if (TotalP >=80 && TotalP <83)
- {
- letterGrade = "B-";
- }
- else if (TotalP >=77 && TotalP <80)
- {
- letterGrade = "C+";
- }
- else if (TotalP >=73 && TotalP <77)
- {
- letterGrade = "C";
- }
- else if (TotalP >=70 && TotalP<73)
- {
- letterGrade = "C-";
- }
- else if (TotalP >=67 && TotalP <70)
- {
- letterGrade = "D+";
- }
- else if (TotalP >=63 && TotalP <67)
- {
- letterGrade = "D";
- }
- else if (TotalP >=60 && TotalP <63)
- {
- letterGrade = "D-";
- }
- else
- {
- letterGrade = "F";
- }
- }
- String getLetterGrade()
- {
- return letterGrade;
- }
- }
- /*
- class Roster
- {
- Define a class Roster, which has an associative array
- (other similar data structures like map, hash map are also fine)
- to store all Student objects. Define appropriate methods in the class
- to calculate, update, and query individual student information as well
- as required statistic information of all students.
- }
- */
- void main() async
- {
- //Greets the user and prompts for the file scores.txt
- print("Hello, please enter the file you would like to open (including the file exstension)");
- //User should be requesting this fiile specifically
- String properFile = "scores.txt";
- //takes input from the user
- String requestedFile = stdin.readLineSync();
- //as long as the user fails to enter "scores.txt", they will be reprompted for the proper file
- //this is hardcoded in such a way to work specificcaly for this project. Standard programs will be more flexible
- while (requestedFile != properFile)
- {
- print("incorrect file, please try again");
- requestedFile = stdin.readLineSync();
- }
- //the proper file has been submitted, Hooray!
- //we will now use the variable "myFile" to holds scores.txt, by waiting till after
- //the user submits the correct input we'll hold onto whatever memoery we can
- //we also create a 2nd variable which we will transfer the information into called "contents"
- var myFile = File(properFile);
- Stream<List<int>> inputStream = myFile.openRead();
- Stream<String> lines = inputStream
- // Decode to UTF8.
- .transform(utf8.decoder)
- // Convert stream to individual lines.
- .transform(new LineSplitter());
- try
- {
- await for (String line in lines) print('$line');
- }
- catch (e)
- {
- print(e.toString());
- }
- print(lines);
- print(inputStream);
- //print(lines[10]);
- //print(lines[18]);
- print('File is now closed.');
- // Stream<List<int>> inputStream = myFile.readAsStringSync() as Stream<List<int>>;
- // ^^ PLan B ^^
- //String inputStream = myFile.readAsStringSync();
- //22 studnets in this file
- //minus the header which is uneeded
- //0 - 21
- //once last check to cover our butts, since Dr. Dong wants the user to be prompted for the file
- //we still have to check if the file is actually in the directory
- //this is made easy in dart with the ".exist" method
- if ( await myFile.exists())
- {
- //because im not familiar enough with Darts asynchrous proccesses
- //I'm going to force the code to run synchronously
- //this is done with readAsStringSync rather than readAsString"
- // contents = await myFile.readAsStringSync();
- // print(contents);
- }
- else
- {
- print("Error: File not found");
- }
- //count how many lines get read in from file
- //set a variable to that respective number (ex: # of students)
- //do a for loop that takes the respective input per student
- //an create the students with the relative information
- //while storing them in the
- // NEED counter to keep track of performed queries.
- // when counter <= 2 perform q1/q2
- // when counter >2 perform full list
- //q1 : the user inputs C#, and your program should print all
- //information (including his/her final letter grade) of the student with the given C#.
- //q2 : the user inputs C#, and your program should print all
- //information (including his/her final letter grade) of the student with the given C#.
- //After two queries, your program print information of all students as well as the average and
- //highest scores of CLA, OLA, quizzes, exams, and final exam on the screen.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement