Need some basic help with program
Hi, I am taking a java class first semester and need some basic help
on this program. I know it's not as technical as it needs to be, but
I'm new at this and our goal is just to make it run.
I need to be able to include a provision to accept multiple lodgers
(which is in there) but also need to have a summary screen of all
multiple entries that are entered into the application. I am not sure
how to get my stored values correct. We need to: Produce an output
line that includes the total number of occupancy nights represented
(total of all "duration" entries) and total rental income processed
(total cost of all stays by all lodgers). Also, produce a list of all
lodgers names.
This is the section I am still trying to complete. I have the code
needed for customerDuration but it's not adding it... if I enter 1
night and then 1 night, instead of showing 2 nights it shows 11. Not
sure how I can convert it where it's not just combining the stays,
instead of adding them. Any help is appreciated. We are turning this
in tomorrow and you might help save me a few hours of figuring out
what I am missing on my own. The code is below:
/*
Project 1: Yellowstone National Park
Lodging Reservation System
Programmer: Student A
Date: September 17, 2007
Program Name: ProbThree
*/
import javax.swing.*; // Access to the package containing JOptionPane
import java.text.*;
public class ProbThree
{
public static void main (String[] args)
{
//Declaring Variables
String customerNameString = "";
String customerOccupancyString;
int reservationCount = 1;
String customerOccupancyRate;
String customerUnitString = "";
String customerDateString = "";
String customerDurationString = "";
byte customerDuration;
String customerCostString = "";
float customerCost;
double customerTotal;
String continueString = "y";
String ProbThreeTitle = "Welcome to Yellowstone National Park's
Lodging Reservation System";
String outputLine = "";
String outputLine2 = "";
String out1 = "";
String out2 = "";
String out3 = "";
String dur1 = "";
String dur2 = "";
String dur3 = "";
String final1 = "";
String final2 = "";
String final3 = "";
String moreInput = "yes";
while (!moreInput.equalsIgnoreCase("no"))
{
outputLine = "To complete your reservation, please answer the
following questions. (After each entry, press the ENTER key. Enter
only one value per question)";
JOptionPane.showMessageDialog(null, outputLine, ProbThreeTitle,
JOptionPane.PLAIN_MESSAGE);
//Prompt and get input from User
customerNameString =
JOptionPane.showInputDialog(null, "Your Name?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
customerOccupancyString =
JOptionPane.showInputDialog(null, "How many occupants during your
stay?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
while (!moreInput.equalsIgnoreCase("no"))
{
customerUnitString =
JOptionPane.showInputDialog(null, "Which unit do you wish to
reserve?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
customerDateString =
JOptionPane.showInputDialog(null, "Arrival Date (format: MM/DD/
YYYY)?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
customerDurationString =
JOptionPane.showInputDialog(null, "What is the duration of your
stay?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
customerCostString =
JOptionPane.showInputDialog(null, "What is the cost of per-night
rental?",
ProbThreeTitle, JOptionPane.INFORMATION_MESSAGE);
moreInput = JOptionPane.showInputDialog(null, "Do you wish to
reserve multiple lodge accomodations during your stay? (Yes or No)",
ProbThreeTitle, JOptionPane.PLAIN_MESSAGE);
if (moreInput.equals ("Yes"))
reservationCount = reservationCount + 1;
out1 = out1 + customerUnitString + " for arrival on " +
customerDateString + " for " + customerDurationString + " days at a
rental cost of $" + customerCostString;
out2 = out1 + out2 + "as well as " + customerUnitString + " for
arrival on " + customerDateString + " for " + customerDurationString +
" days at a rental cost of $" + customerCostString;
out3 = out1 + out2 + out3 + customerUnitString + " for arrival on "
+ customerDateString + " for " + customerDurationString + " days at a
rental cost of $" + customerCostString;
customerDuration = Byte.parseByte(customerDurationString);
dur1 = dur1 + customerDurationString;
dur2 = dur2 + customerDurationString;
dur3 = dur3 + customerDurationString;
}
//Conversions
customerCost = Float.parseFloat(customerCostString);
customerDuration = Byte.parseByte(customerDurationString);
int customerOccupancy = 0;
customerOccupancy = Integer.parseInt(customerOccupancyString);
//Calculations
double overAmount = 0;
//Calculate the occupancy rate
if (customerOccupancy >= 3)
{
System.out.println("bigger than 2");
overAmount = (customerOccupancy - 2) * 10 * customerDuration;
}
customerTotal = Math.round(customerCost * customerDuration) +
overAmount;
System.out.println(overAmount);
//Output
outputLine = "This program produced by: Student A\n\n" + "\nThis
reservation is for " + customerNameString + ". You have " +
customerOccupancyString + " guests total during your stay for " +
customerDurationString + " days, beginning on " + customerDateString +
". You have reserved " + out1 + ".\nYour total cost is: $" +
customerTotal + "\nYour price is based on a per night rental of $" +
customerCostString + " and a fee of $" + overAmount + " for all
extra occupants.";
JOptionPane.showMessageDialog(null, outputLine, ProbThreeTitle,
JOptionPane.PLAIN_MESSAGE);
outputLine2 = "You have made " + reservationCount + " reservations
total." + "\nTotal days at our facility:" + dur3;
JOptionPane.showMessageDialog(null, outputLine2, ProbThreeTitle,
JOptionPane.PLAIN_MESSAGE);
moreInput = JOptionPane.showInputDialog(null, "Do you wish to make
another reservation? (Yes or No)",
ProbThreeTitle, JOptionPane.PLAIN_MESSAGE);
outputLine = "";
}
}
}