Switch Learn programming Java

Lesson:

Flow Control


Exercise:

Switch 10


Objetive:

Create a program in java to display the "text mark" corresponding to a certain "numeric mark", using the following equivalence:

9.10 = Outstanding
7.8 = Notable
6 = Good
5 = Approved
0-4 = Suspense

Your program should ask the user for a numerical mark and display the corresponding text mark. You need to do it twice: first using "if" and then using "switch".
9,10 = Sobresaliente
7,8 = Notable
6 = Bien
5 = Aprobado
0-4 = Suspenso

Your program must ask the user for a numerical mark and display the corresponding text mark. You must do it twice: first using "if" and then using "switch".


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int number;

		System.out.print("Number? ");
		number = Integer.parseInt(new Scanner(System.in).nextLine());

		if ((number == 9) || (number == 10))
		{
			System.out.println("Sobresaliente");
		}
		else if ((number == 7) || (number == 8))
		{
			System.out.println("Notable");
		}
		else if (number == 6)
		{
			System.out.println("Bien");
		}
		else if (number == 5)
		{
			System.out.println("Aprobado");
		}
		else if ((number >= 0) && (number <= 4))
		{
			System.out.println("Suspenso");
		}
		else
		{
			System.out.println("No válido");
		}

		switch (number)
		{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
				System.out.println("Suspenso");
				break;
			case 5:
				System.out.println("Aprobado");
				break;
			case 6:
				System.out.println("Bien");
				break;
			case 7:
			case 8:
				System.out.println("Notable");
				break;
			case 9:
				System.out.println("Bajo, pero... ");
			case 10:
				System.out.println("Sobresaliente");
				break;
			default:
				System.out.println("Nota no válida");
				break;
		}
	}
}