Last active
January 27, 2019 07:03
-
-
Save annibuliful/bca8c9db432a00dd06d31cfdedf684e4 to your computer and use it in GitHub Desktop.
a simple calculated grade software with arrayList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class demo { | |
| @SuppressWarnings("resource") | |
| public static void main(String[] args) { | |
| gradeModel gradeF = new gradeModel(0, 49, "F"); | |
| gradeModel gradeD = new gradeModel(50, 59, "D"); | |
| gradeModel gradeC = new gradeModel(60, 69, "C"); | |
| gradeModel gradeB = new gradeModel(70, 79, "B"); | |
| gradeModel gradeA = new gradeModel(80, 100, "A"); | |
| gradeController listGrades = new gradeController(); | |
| listGrades.addGrade(gradeF); | |
| listGrades.addGrade(gradeD); | |
| listGrades.addGrade(gradeC); | |
| listGrades.addGrade(gradeB); | |
| listGrades.addGrade(gradeA); | |
| Scanner input = new Scanner(System.in); | |
| int score = input.nextInt(); | |
| String calculatedGrade = listGrades.findGrade(score); | |
| System.out.print("Your grade is "+calculatedGrade); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class gradeController { | |
| public ArrayList<gradeModel> listGrades = new ArrayList<gradeModel>(); | |
| public void addGrade(gradeModel grade) { | |
| this.listGrades.add(grade); | |
| } | |
| public String findGrade(int score) { | |
| for(gradeModel grade: listGrades) { | |
| if(score >= grade.minimum && score <= grade.maximum) { | |
| return grade.grade; | |
| } | |
| } | |
| return "Invalid score"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class gradeModel { | |
| public int minimum; | |
| public int maximum; | |
| public String grade; | |
| gradeModel(int min,int max,String grade){ | |
| this.minimum = min; | |
| this.maximum = max; | |
| this.grade = grade; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment