Last active
April 5, 2022 20:58
-
-
Save speters33w/9098821044851fd1ae4c0f8fbcc81999 to your computer and use it in GitHub Desktop.
Grades and Points exercise from University of Helsinki Java Programming 1
This file contains 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
// A different approach to the Grades and Points exercize from University of Helsinki’s Java Programming I | |
// https://java-programming.mooc.fi/part-1/6-conditional-statements | |
//Programming exercise: | |
// Grades and Points | |
// Points | |
// 1/1 | |
// | |
// The table below describes how the grade for a particular course is determined. | |
// Write a program that gives a course grade according to the provided table. | |
// | |
// points grade | |
// < 0 impossible! | |
// 0-49 failed | |
// 50-59 1 | |
// 60-69 2 | |
// 70-79 3 | |
// 80-89 4 | |
// 90-100 5 | |
// > 100 incredible! | |
// | |
//////////Sample outputs:////////// | |
// | |
// Sample output | |
// | |
// Give points [0-100]: | |
// 37 | |
// Grade: failed | |
// Sample output | |
// | |
// Give points [0-100]: | |
// 76 | |
// Grade: 3 | |
// Sample output | |
// | |
// Give points [0-100]: | |
// 95 | |
// Grade: 5 | |
// Sample output | |
// | |
// Give points [0-100]: | |
// -3 | |
// Grade: impossible! | |
import java.util.Scanner; | |
public class GradesAndPoints { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
System.out.println("Give points [0-100]:"); | |
int points = Integer.valueOf(scan.nextLine()); | |
if (points > 100) { | |
System.out.println("Grade: " + "incredible!"); | |
} else if (points < 0) { | |
System.out.println("Grade: " + "impossible!"); | |
} else if (points >= 50) { | |
points = (((points - 40) / 10)); | |
if (points == 6) points--; | |
System.out.println("Grade: " + points); | |
} else { | |
System.out.println("Grade: " + "failed"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment