I'm new to programming, and am taking a class. One of my assignments involves using a switch statement, which is something we've only recently learned. I got most of my code, but for some reason, the switch statement won't work. The program compiles, and prompts the necessary inputs, but does not print any of the switch statements when I enter the values. Basically, I want to prompt the user to enter in the student number (any number), enter in the credits, and print the correct statement. Here is my code:
import java.io.*;
import java.util.*;
public class Prog222
{
public static void main(String[] args)
{
for(int i = 1; i<=4; i++)
{
double freshmanC = 1.0;
double sophomoreC = 2.0;
double juniorC = 3.0;
double seniorC = 4.0;
Scanner kbReader = new Scanner(System.in);
System.out.print("Enter student number "); //Enter 2352, 3639, 4007, and 4915 respectively
int studentNumber = kbReader.nextInt();
System.out.print("Enter credits "); //Enter 30.0, 29.9, 70, and 103.7 respectively
double credits = kbReader.nextDouble();
switch((int) credits)
{
case '1': //Below 30 credit
System.out.println("Grade level code = " + freshmanC);
break;
case '2': //30 credits or more but less than 70 credits
System.out.println("Grade level code = " + sophomoreC);
break;
case '3': //70 credits or more but less than 90 credits
System.out.println("Grade level code = " + juniorC);
break;
case '4': //90 credits or more
System.out.println("Grade level code = " + seniorC);
break;
}
}
}
}
I've worked on this for a few hours, but I can't really find where I'm going wrong with my switch statement since it won't print. I'd really appreciate the help! Thanks!
'1'and1in Java: the first one is a character constant that is equal to 49, while the second one is equal to 1.