|
| 1 | +import java.util.Scanner; |
| 2 | +public class Quiz_2 { |
| 3 | + public static void main(String[] args) { |
| 4 | + |
| 5 | + Scanner scanner = new Scanner(System.in); |
| 6 | + |
| 7 | + /* TODO: Write a Java program to get a mark from user using java input then calculate the grade based on below instructions. |
| 8 | + • 90-100: Grade A |
| 9 | + • 80-89: Grade B |
| 10 | + • 70-79: Grade C |
| 11 | + • 60-69: Grade D |
| 12 | + • Below 60: Grade F |
| 13 | + Be aware to: |
| 14 | + 1- Warn the user if the input mark is less than 0 or greater than 100. |
| 15 | + 2- Give 5% adjustment to the mark but be aware to not exceed 100. |
| 16 | + 3- Use nested if else |
| 17 | + */ |
| 18 | + System.out.print("Enter your mark (0-100): "); |
| 19 | + int marks = scanner.nextInt(); |
| 20 | + if (marks < 0 || marks > 100) { |
| 21 | + System.out.println("Error: Marks should be between 0 and 100."); |
| 22 | + } else { |
| 23 | + double curvePercentage = 0.05; |
| 24 | + double adjustedMarks = marks + (marks * curvePercentage); |
| 25 | + if (adjustedMarks > 100) { |
| 26 | + adjustedMarks = 100; |
| 27 | + } |
| 28 | + if (adjustedMarks >= 90) { |
| 29 | + System.out.println("Mark = " + marks + "\nAdjusted mark = " + adjustedMarks + "\ngrade is A"); |
| 30 | + } else if (adjustedMarks >= 80) { |
| 31 | + System.out.println("Mark = " + marks + "\nAdjusted mark = " + adjustedMarks + "\ngrade is B"); |
| 32 | + } else if (adjustedMarks >= 70) { |
| 33 | + System.out.println("Mark = " + marks + "\nAdjusted mark = " + adjustedMarks + "\ngrade is C"); |
| 34 | + } else if (adjustedMarks >= 60) { |
| 35 | + System.out.println("Mark = " + marks + "\nAdjusted mark = " + adjustedMarks + "\ngrade is D"); |
| 36 | + } else { |
| 37 | + System.out.println("Mark = " + marks + "\nAdjusted mark = " + adjustedMarks + "\ngrade is F"); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /* TODO: Write a Java program that allows the user to choose one of the following conversions: |
| 42 | + 1.Miles (ml) to Kilometers (km) - (divide by 0.621371) |
| 43 | + 2.Pounds (lbs) to Kilograms (kg) - (multiply by 0.453592) |
| 44 | + 3.Feet (ft) to Meters (m) - (multiply by 0.3048) |
| 45 | + 4.Gallons (gal) to Liters (L) - (multiply by 3.78541) |
| 46 | + After choosing the conversion, the user will input the value, and the program will display |
| 47 | + the converted result. |
| 48 | + Be aware to: |
| 49 | + 1- Warn the user if entered a wrong choice. |
| 50 | + 2- Use switch case |
| 51 | + */ |
| 52 | + System.out.print("Choose conversion (1. Ml to Km 2. lbs to Kg 3. ft to m 4. gal to L): "); |
| 53 | + int choice = scanner.nextInt(); |
| 54 | + |
| 55 | + switch (choice) { |
| 56 | + case 1: |
| 57 | + System.out.print("Enter distance in miles: "); |
| 58 | + double miles = scanner.nextDouble(); |
| 59 | + System.out.println(miles + " Ml = " + miles / 0.621371 + " Km."); |
| 60 | + break; |
| 61 | + |
| 62 | + case 2: |
| 63 | + System.out.print("Enter weight in pounds: "); |
| 64 | + double pounds = scanner.nextDouble(); |
| 65 | + System.out.println(pounds + " lbs = " + pounds * 0.453592 + " Kg."); |
| 66 | + break; |
| 67 | + |
| 68 | + case 3: |
| 69 | + System.out.print("Enter length in feet: "); |
| 70 | + double feet = scanner.nextDouble(); |
| 71 | + System.out.println(feet + " ft = " + feet * 0.3048 + " m."); |
| 72 | + break; |
| 73 | + case 4: |
| 74 | + System.out.print("Enter volume in gallons: "); |
| 75 | + double gallons = scanner.nextDouble(); |
| 76 | + System.out.println(gallons + " gal = " + gallons * 3.78541 + " L."); |
| 77 | + break; |
| 78 | + |
| 79 | + default: |
| 80 | + System.out.println("Invalid choice."); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments