Hi, I am trying to create a reserve console app using Java. Any Help is appreciated.
The Params are:
Calculate reservation totals
Welcome to the Reservation Calculator
Enter the arrival month (1-12): 5
Enter the arrival day (1-31): 16
Enter the arrival year: 2016
Enter the departure month (1-12): 5
Enter the departure day (1-31): 18
Enter the departure year: 2016
Arrival Date: May 16, 2016
Departure Date: May 18, 2016
Price: $105.00 per night
Total price: $210.00 for 2 nights
Continue? (y/n): n
· This application calculates the charges for a stay at a hotel based on the arrival and departure dates.
· The application prompts the user for the month, day, and year of the arrival and the departure. Then, the application displays the arrival date, the departure date, the room rate, the total price, and the number of nights.
Specifications
· Create a class named Reservation that defines a reservation. This class should contain instance variables for the arrival date and departure date. It should also contain a constant initialized to the nightly rate of $105.00.
· The Reservation class should include the following methods:
setArrivalDate(LocalDate arrivalDate)
LocalDate getArrivalDate()
String getArrivalDateFormatted()
setDepartureDate(LocalDate departureDate)
LocalDate getDepartureDate()
String getDepartureDateFormatted()
int getNumberOfNights()
String getPricePerNightFormatted()
double getTotalPrice()
String getTotalPriceFormatted()
I have tried to get this to work but I am stuck:
CURRENT CODE:
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Scanner;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.time.Month;
import java.text.DateFormat;
public class ResCalc {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Welcome!");
getArrivalDate();
}
public static void getArrivalDate(){
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
System.out.print("Enter the arrival month (1-12): ");
int month = sc.nextInt();
System.out.print("Enter the arrival day (1-31): ");
int day = sc.nextInt();
System.out.print("Input arrival year: ");
int year = sc.nextInt();
System.out.println();
System.out.println(setArrivalDate(day, month, year));
choice = sc.nextLine();
}
}
public static void getDepartureDate(){
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
System.out.print("Enter the departure month (1-12): ");
int month = sc.nextInt();
System.out.print("Enter the departure day (1-31): ");
int day = sc.nextInt();
System.out.print("Input departure year: ");
int year = sc.nextInt();
System.out.println();
//Users choice
choice = sc.nextLine();
}
}
public static String setArrivalDate(int month, int day, int year) {
String monthStr = "";
switch (month) {
case 1:
monthStr = "January";
break;
case 2:
monthStr = "February";
break;
case 3:
monthStr = "March";
break;
case 4:
monthStr = "April";
break;
case 5:
monthStr = "May";
break;
case 6:
monthStr = "June";
break;
case 7:
monthStr = "July";
break;
case 8:
monthStr = "August";
break;
case 9:
monthStr = "September";
break;
case 10:
monthStr = "October";
break;
case 11:
monthStr = "November";
break;
case 12:
monthStr = "December";
break;
}
return "Arrival Date: " + monthStr + day + year;
}
public static String getArrivalDateFormatted()
{
DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(
FormatStyle.LONG);
return df.format(setArrivalDate());
}
public static String setDepartureDate(int month, int day, int year) {
String monthStr = "";
switch (month) {
case 1:
monthStr = "January";
break;
case 2:
monthStr = "February";
break;
case 3:
monthStr = "March";
break;
case 4:
monthStr = "April";
break;
case 5:
monthStr = "May";
break;
case 6:
monthStr = "June";
break;
case 7:
monthStr = "July";
break;
case 8:
monthStr = "August";
break;
case 9:
monthStr = "September";
break;
case 10:
monthStr = "October";
break;
case 11:
monthStr = "November";
break;
case 12:
monthStr = "December";
break;
}
return monthStr + day + year;
}
Not sure where to go from here. Been stuck for 4 hours.