HarrJ

Day 08

Aug 8th, 2023 (edited)
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1. package mng2023b5;
  2. import java.util.Scanner;
  3.  
  4. public class Day08B {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.        
  8.         int grade;
  9.         String txtIfResult;
  10.        
  11.         System.out.print("Enter Grade: ");
  12.         grade = sc.nextInt();
  13.         //using if statements only
  14.         if (grade >= 91){
  15.             System.out.println("Excellent");
  16.         }
  17.         if (grade >= 81 && grade <= 90) {
  18.             System.out.println("Great");
  19.         }
  20.         if (grade >= 75 && grade <= 80) {
  21.             System.out.println("Passed");
  22.         }
  23.         if (grade < 75) {
  24.             System.out.println("Failed");
  25.         }
  26.         //notes about if only code
  27.         //everyline uses a single sout command
  28.         //its possibly better to just put the value to print and print it later instead
  29.        
  30.         //now, utilizing if else if
  31.        
  32.         if (grade > 100) {
  33.             txtIfResult = "grade greater than 100";
  34.         } else if (grade == 100) {
  35.             txtIfResult = "1.0";
  36.         } else if (grade >= 95) {
  37.             txtIfResult = "1.25";
  38.         } else if (grade >= 91) {
  39.             txtIfResult = "1.5";
  40.         } else if (grade >= 86) {
  41.             txtIfResult = "2.0";
  42.         } else if (grade >= 81) {
  43.             txtIfResult = "2.5";
  44.         } else if (grade >= 75) {
  45.             txtIfResult = "3.0";
  46.         } else {
  47.             txtIfResult = "5.0";
  48.         }
  49.         System.out.println(txtIfResult);
  50.        
  51.     }
  52. }
  53.  
  54. //------------------------------------------
  55. package mng2023b5;
  56. import java.util.Scanner;
  57.  
  58. public class Day08D {
  59.     public static void main(String[] args) {
  60.         Scanner sc = new Scanner(System.in);
  61.         String colorName, colorGroup;
  62.        
  63.         System.out.println("Give a color name:");
  64.         colorName = sc.nextLine().toLowerCase();
  65.         // .toLowerCase() para yung mga if statements gagamit
  66.         // na lang ng .equals vs .equalsIgnoreCase
  67.        
  68.         if (colorName.equals("red")){
  69.             colorGroup = "Primary Color";
  70.         } else if (colorName.equals("blue")){
  71.             colorGroup = "Primary Color";
  72.         } else if (colorName.equals("yellow")){
  73.             colorGroup = "Primary Color";
  74.         } else if (colorName.equals("green")){//secondary color: green, orange, violet
  75.             colorGroup = "Secondary Color";
  76.         } else if (colorName.equals("orange")){
  77.             colorGroup = "Secondary Color";
  78.         } else if (colorName.equals("violet")){
  79.             colorGroup = "Secondary Color";
  80.         } else {
  81.             colorGroup = "not a primary or secondary color";
  82.         }
  83.        
  84.         System.out.println(colorName + " is a " + colorGroup);
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment