This is my first post on here. This is for my homework but I am not asking anyone to do it for me. My code does not have any compile errors at the moment. My problem is that when I run the program the roomTotal is always zero. I think it has something to do with the initialization. But, if I do not intialize it an error will occur. Does anyone have any suggestions on how I can get this to output the actual room total.
import javax.swing.JOptionPane; //Needed for JOptionPane
import java.text.DecimalFormat; //Needed for DecimalFormat Class
public class Cruise
{
public static void main(String[] args)
{
//Input Variables
String customerNumber; //To hold customers ID number
int roomType; //To hold room Type
int roomPeople; //To hold the number of people staying in the room
double roomCharge; //To hold the room charges before possible discount
double roomDiscount; //To hold excursion discount
int excursionNum; //To hold the number of excursions that the customer will go on
int excursionPeople; //To hold the number of people that will be going on the excursions
double excursionCharge; //To hold the excursion charges before possible discount
double excursionDiscount; //To hold excursion discount
int internetUse; //To hold if the user wants Internet use in their room
int internetDays; //To hold the number of days that the user wants Internet in their room
int sodaCard; //To hold whether the user wants a soda card
int sodaPeople; //To hold the number of people that want soda cards in the customer's room
String input; //To hold keyboard input
//Ouput Variables
double excursionTotal; //To hold the excursion total after possible discount
double internetTotal; //To hold total Internet expense
double sodaTotal; //To hold total soda card expense
double cruiseTotal; //To hold the total expenses for the room
double roomTotal=0; //To hold the total room expenses
//Get user customer number
customerNumber=JOptionPane.showInputDialog("What is your customerNumber?");
//Get customers room selection
input=JOptionPane.showInputDialog("What type of room would you like to book?\n" +
"Press 0 for a state room which costs $649.00 per person.\n" +
"Press 1 for a ocean view room which costs $749.00 per person.\n" +
"Press 2 for a room with a balacony which costs $1,069.00 per person\n" +
"Press 3 for a suite which costs $1499.00 per person");
roomType=Integer.parseInt(input);
//Get the number of people that will be staying in the room
input=JOptionPane.showInputDialog("How many people will be staying in your room? There is a \n" +
"maximum of five people per room.\n" +
"Press 0 if there will be one person staying in your room.\n"+
"Press 1 if there will be two people staying in your room.\n"+
"Press 2 if there will be three people staying in your room.\n"+
"Press 3 if there will be four people staying in your room.\n"+
"Press 4 if there will be five people staying in your room.\n");
roomPeople=Integer.parseInt(input);
//Get the number of excursions the customer will be going on
input=JOptionPane.showInputDialog("The excursions that the cruise offers are:\n" +
"*Jet skiing\n*Snorkeling\n*Parasailing\n*Swimming with dolphins\n" +
"*Helmet\n All excursions have a flat rate of $180.00 per person.\n " +
"There is a limit of four excursions per room. How many excursions will you be going on? ");
excursionNum=Integer.parseInt(input);
//Get the number of people that will be attending the excursions
input=JOptionPane.showInputDialog("How many people will be going on the excursions with you?");
excursionPeople=Integer.parseInt(input);
//See is the user would like to have Internet access on the cruise
input=JOptionPane.showInputDialog("Would you like to have Internet access?\n"+
"Press 0 for no and 1 for yes:");
internetUse=Integer.parseInt(input);
//Get the number of days that the user would like to have Internet on the cruise
input=JOptionPane.showInputDialog("The Internet costs $15.00 per day.\n" +
"How many days would you like to have Internet access?");
internetDays=Integer.parseInt(input);
//See if the user would like a soda card on the cruise
input=JOptionPane.showInputDialog("The cruise line offers a soda card for $25.00 per person\n"+
"The soda card allows the card holder to have unlimited soda\n"+
"for the entire week that you are on the cruse.\n"+
"Would you like to get a soda card?\n" +
"Enter 0 for no and 1 for yes:");
sodaCard=Integer.parseInt(input);
//See how many people will be needing soda cards on the cruise
input=JOptionPane.showInputDialog("How many soda cards will you be needing for the people in your room?");
sodaPeople=Integer.parseInt(input);
//Call methods to perform calculations
roomCharge=calculateRoomCharge(roomType,roomPeople);
excursionCharge=calculateExcursionCharge(excursionNum, excursionPeople);
internetTotal=calculateInternetTotal(internetUse, internetDays);
sodaTotal=calculateSodaTotal(sodaCard, sodaPeople);
//Call method to diplay results
displayResults(customerNumber, roomTotal,excursionCharge, internetTotal, sodaTotal);
System.exit(0);
}
/** The calculateRoomCharge method will be used to calculate the total charge
*for the room
*@param roomType The type of room
*@param roomPeople The number of people sharing the room
*@return roomTotal The total cost of the room with a potential dicount
*/
public static double calculateRoomCharge(int roomType, int roomPeople)
{
double roomCharge;
double roomDiscount;
double roomTotal;
if(roomType==0 && roomPeople==0)
{
roomCharge=649*1;
}
else if(roomType==0 && roomPeople==1)
{
roomCharge=649*2;
}
else if(roomType==0 && roomPeople==2)
{
roomCharge=649*3;
}
else if(roomType==0 && roomPeople==3)
{
roomCharge=649*4;
}
else if(roomType==0 && roomPeople==4)
{
roomCharge=649*5;
}
else if (roomType==1 && roomPeople==0)
{
roomCharge=749*1;
}
else if(roomType==1 && roomPeople==1)
{
roomCharge=749*2;
}
else if(roomType==1 && roomPeople==2)
{
roomCharge=749*3;
}
else if(roomType==1 && roomPeople==3)
{
roomCharge=749*4;
}
else if(roomType==1 && roomPeople==4)
{
roomCharge=749*5;
}
else if(roomType==2 && roomPeople==0)
{
roomCharge=1069*1;
}
else if(roomType==2 && roomPeople==1)
{
roomCharge=1069*2;
}
else if(roomType==2 && roomPeople==2)
{
roomCharge=1069*3;
}
else if(roomType==2 && roomPeople==3)
{
roomCharge=1069*4;
}
else if(roomType==2 && roomPeople==4)
{
roomCharge=1069*5;
}
else if(roomType==3 && roomPeople==0)
{
roomCharge=1499*1;
}
else if(roomType==3 && roomPeople==1)
{
roomCharge=1499*2;
}
else if(roomType==3 && roomPeople==2)
{
roomCharge=1499*3;
}
else if(roomType==3 && roomPeople==3)
{
roomCharge=1499*4;
}
else if(roomType==3 && roomPeople==4)
{
roomCharge=1499*5;
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Data!");
roomCharge=7495;
}
if(roomPeople==3)
{
roomDiscount= (roomCharge *.10);
roomTotal=roomCharge-roomDiscount;
}
else if(roomPeople>=4)
{
roomDiscount= (roomCharge *.15);
roomTotal=roomCharge-roomDiscount;
}
else
{
roomTotal=roomCharge;
}
return roomTotal;
}
/** The calculateExcursionCharge method will be used to calculate the total charge
*for the excursions
*@param excursionNum Number of excursions the customer plans on going on
*@return excursionCharge The cost of the excursion with a potential discount
*/
public static double calculateExcursionCharge(int excursionNum, int excursionPeople)
{
double excursionCharge;
double excursionDiscount;
double excursionTotal;
if(excursionNum==1)
{
excursionCharge=180*excursionPeople;
}
else if(excursionNum==2)
{
excursionCharge=360*excursionPeople;
}
else if(excursionNum==3)
{
excursionCharge=540*excursionPeople;
}
else if(excursionNum==4)
{
excursionCharge=720*excursionPeople;
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Data!");
excursionCharge=720;
}
if(excursionNum==2)
{
excursionDiscount= (excursionCharge*.15);
excursionTotal=excursionCharge-excursionDiscount;
}
else if(excursionNum>=3)
{
excursionDiscount= (excursionCharge*.20);
excursionTotal= excursionCharge-excursionDiscount;
}
else
{
excursionTotal=excursionCharge;
}
return excursionTotal;
}
/** The calculateInternetTotal method will be used to calculate the total charge
*for the Internet
*@param internetUse How many days the Internet will be needed
*@return internetTotal The total Internet charge, which is the internetDays multiplied by the cost of the Internet
*/
public static double calculateInternetTotal(int internetUse, int internetDays)
{
double internetTotal;
if(internetUse==1)
{
internetTotal=internetDays*15;
}
else if(internetUse==0)
{
internetTotal=internetDays*0;
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Data.");
internetTotal=0;
}
return internetTotal;
}
/** The calculatesodaTotal method will be used to calculate the total charge
*for the soda card
*@param sodaCard If customer wants to purchase soda cards
*@return sodaTotal The total cost of the soda cards, which is the number of people who want one multiplied by 25
*/
public static double calculateSodaTotal(int sodaCard, int sodaPeople)
{
double sodaTotal;
if(sodaCard==1)
{
sodaTotal=sodaPeople * 25.00;
}
else if(sodaCard==0)
{
sodaTotal= sodaPeople * 0;
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Data.");
sodaTotal=0;
}
return sodaTotal;
}
/**The displayResults method outputs the results
*@param customerID The customer ID number
*@param roomTotal The total charge for the room
*@param excursionTotal The total charge for the excursions
*@param internetTotal The total charge for Internet use
*@param sodaTotal
*@param cruiseTotal The total charge for the cruise which if the roomTotal added to the excursion total added to the Internet
*total added to the soda total
*/
public static void displayResults(String customerNumber, double roomTotal, double excursionTotal, double internetTotal, double sodaTotal)
{
double cruiseTotal;
DecimalFormat formatter=new DecimalFormat("#0.00");
//Calculate the total charge
cruiseTotal=roomTotal+excursionTotal+internetTotal+sodaTotal;
//Output the customers expenses for the cruise
JOptionPane.showMessageDialog(null, "The cruise expenses for customer number " + customerNumber +
" for McCutcheon cruise line is as follows: ");
JOptionPane.showMessageDialog(null, "The total charge for the room is $" + formatter.format(roomTotal));
JOptionPane.showMessageDialog(null, "The total charge for the excusrions is $" + formatter.format(excursionTotal));
JOptionPane.showMessageDialog(null, "The total charge for the Internet is $" + formatter.format(internetTotal));
JOptionPane.showMessageDialog(null, "The total charge for the sodaCard is $" + formatter.format(sodaTotal));
JOptionPane.showMessageDialog(null, "The total charge for your cruise expenses is $" + formatter.format(cruiseTotal));
}
}