State University charges $90.00 for each semester hour of credit, $200.00 per semester for a regular room, $250.00 per semester for an air-conditional room, and $400.00 per semester for food. All students are charged a $30.00 matriculation fee. Graduating students must also pay a $35.00 diploma fee. Write a program to compute the fees that must be paid by a student. Your program should include an appropriate warning message if a student is taking more than 21 credit hours or fewer than 12 credit hours. A typical line of data for one student would include room type (R or A), student number (in four digits), credit hours, and graduation status (T or F).
this is my code:
package Assignment.Q86;
import java.util.Scanner;
public class Q086 {
public static void main(String[] args) {
int matriculation = 30, food = 400, hour, room = 0, graduation = 0, sum;
String roomType, graduationStatus;
Scanner input = new Scanner(System.in);
System.out.println(
"Your food cost $400.\nYour matriculation cost $30.\n"
);
System.out.println("Enter your semester hour:");
hour = input.nextInt();
System.out.println("Enter room type you want(A or R):");
roomType = input.next();
System.out.println("Enter your graduation status(T or F):");
graduationStatus = input.next();
//semester time
if (hour < 12 && hour > 21) {
System.out.println(
"Alert!! Your semester hour is more or less than the usual.\n"
);
} else {
hour = hour * 90;
}
//choosing room type
if (roomType == "A" || roomType == "a") {
room = 250;
} else if (roomType == "R" && roomType == "r") {
room = 200;
} else {
System.out.println("Please enter the correct room type");
}
//working for choosing the graduation type
if (graduationStatus == "T" || graduationStatus == "t") {
graduation = 35;
} else if (graduationStatus == "F" || graduationStatus == "f") {
graduation = 0;
} else {
System.out.println(
"Please enter the correct graduation status value"
);
}
sum = matriculation + food + room + hour + graduation;
System.out.println("your total fees is " + sum);
System.out.println(" your student number is ****");
System.out.println("your room type is " + room);
System.out.println("your graduation status is " + graduation);
System.out.println("your total credit hours is " + hour);
}
}
The problem is when I clicked any of the room type and graduation status = T. the result of both graduation and room shows the value of 0. The program says that the room and graduation has to be initialize in order to work.
this is the output example
Your food cost $400.
Your matriculation cost $30.
Enter your semester hour:
12
Enter room type you want(A or R):
r
Enter your graduation status(T or F):
t
Please enter the correct room type
Please enter the correct graduation status value
your total fees is 1510
your student number is ****
your room type is 0
your graduation status is 0
your total credit hours is 1080