Question

In Java please

Project 14-1: Reservation Calculator Create an application that gets arrival and departure dates for a reservation and calcul

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;

public class Reservation {
    private final double RESERVATION_RATE = 145.00;
    private LocalDate arrivalDate;
    private LocalDate departureDate;

    //Getters and setters

    public LocalDate getArrivalDate() {
        return arrivalDate;
    }
    public String getArrivalDateFormatted()
    {
        return arrivalDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM));
    }
    public void setArrivalDate(LocalDate arrivalDate) {
        this.arrivalDate = arrivalDate;
    }
    public String getDepartureDateFormatted()
    {
        return departureDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM));
    }
    public int getNumberOfNights()
    {
        return (int) ChronoUnit.DAYS.between(arrivalDate,departureDate);
    }
    public String getPricePerNightFormatted()
    {
        return NumberFormat.getCurrencyInstance().format(RESERVATION_RATE);
    }
    public double getTotalPrice()
    {
       return RESERVATION_RATE * getNumberOfNights();

    }
    public String getTotalPriceFormatted()
    {
        return NumberFormat.getCurrencyInstance().format(getTotalPrice());
    }

    public LocalDate getDepartureDate() {
        return departureDate;
    }

    public void setDepartureDate(LocalDate departureDate) {
        this.departureDate = departureDate;
    }
}

//===========================================

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class ReservationCalculator {
    public static void main(String[] args) {
        System.out.println("Reservation Calculator\n");
        Scanner input = new Scanner(System.in);
        char choice;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mm/DD/yyyy");//.withLocale(Locale.US);
        do {

            Reservation reservation = new Reservation();
            System.out.print("Enter arrival date in format (MM/DD/YYYY): ");
            String arrivalDate = input.next();
            System.out.print("Enter departure date in format (MM/DD/YYYY): ");
            String departureDate = input.next();
            reservation.setArrivalDate(LocalDate.parse(arrivalDate,formatter));
            reservation.setDepartureDate(LocalDate.parse(departureDate,formatter));
            //Print
            System.out.println("Arrival Date: " + reservation.getArrivalDateFormatted());
            System.out.println("Departure Date: " + reservation.getDepartureDateFormatted());
            System.out.println("Price: " + reservation.getPricePerNightFormatted() + " per night");
            System.out.println("Total price: " + reservation.getTotalPriceFormatted() + " for " + reservation.getNumberOfNights() + " nights");

            System.out.print("Continue? (y/n): ");
            choice = input.next().toLowerCase().charAt(0);
        }while (choice=='y');
        System.out.println("Bye!");
    }
}

//Output

C:\Program Files\Java\jdk1.8.0_221\bin\java.exe ... Reservation Calculator Enter arrival date in format (MM/DD/YYYY): 05/16

//If you need any help regarding this solution .......... please leave a comment....... thanks

Add a comment
Know the answer?
Add Answer to:
In Java please Project 14-1: Reservation Calculator Create an application that gets arrival and departure dates...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Date212 to represent a date. It will store the year, month and...

    Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...

  • Create a Java application named Problem14 using the two files Dr. Hanna provided to you—Date.java andProblem14.java—then change his code to add two non-trivial public, non-static methods to the Date class.

    Create a Java application named Problem14 using the two files Dr. Hanna provided to you—Date.java andProblem14.java—then change his code to add two non-trivial public, non-static methods to the Date class.1. Increment a Date to the next day (for example, 1-31-2011 increments to 2-1-2011; 12-31-2010 increments to 1-1-2011).2. Decrement a Date to the previous day (for example, 2-1-1953 decrements to 1-31-1953; 1-1-1954 decrements to 12-31-1953).. Extra Credit (up to 5 points) Re-write the Date member functions Input() and Output() to usedialog boxes to...

  • Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java,...

    Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following:  Ask user to enter Today’s...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • please write program in java and comment the code clearly. I am providing previous classes Media...

    please write program in java and comment the code clearly. I am providing previous classes Media and payment codes to be used for this class.(its not a big code to write , it seems ,because i added previous classes , pleases help. public class Media { String name; int year;    // a constructor which initializes the media with the provided name and publication year. public Media(String name, int year) { this.name = name; this.year = year; }    //...

  • 1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler...

    1) (10 points) Create a new Java project, name it "Quiz02". Create a java class Traveler that has four data members, String name, Date bDate, int id and int noOfDependens. Generate the following: 1- Getters and Setters. 2- Four parametrize constructor to initialize the four data members above. 3- toString() method. Create a java class Flight that has four data members, String number, String destination, int capacity, and ArrayList<Traveler> travelers. • Notel - travelers will be used to track the...

  • the first question java code eclipse app the second question is java fx gui caculator please...

    the first question java code eclipse app the second question is java fx gui caculator please fast 1. Create project called "YourFirstName_QUID'. Eg. Aliomar_202002345 2. Create two package Q1 and Q2. 3. Add your name and studentID as comments on the top of each Java source file you submit. Question 1. Bookings APP [80 Points-six parts] Implement the following hotel booking system. Use the following class diagram to understand the structure of the system's classes, their attributes operations (or methods),...

  • Create a program, Weather.java, which loads an unsorted set of weather data for Pendleton, sorts the...

    Create a program, Weather.java, which loads an unsorted set of weather data for Pendleton, sorts the data by date (handling date errors), and performs some analysis of the data (e.g. min/max temperature), and outputs the sorted data set to a file. Sample data: 2015-12-12,47,43,38,32,12,39,0.09,7,Rain,205 2015-05-08,73,56,38,18,7,22,0,0,,75 2015-11-10,51,44,37,18,8,21,0,4,,261 2016-02-02,45,36,26,12,5,14,0,1,,111 2015-06-28,109,89,68,38,11,48,T,0,Rain-Thunderstorm,296 Write methods to calculate each of the following on the given data set: Max. temperature Min. temperature Max. wind gust Max. precipitation and what the 'events' were for that day Each result...

  • JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...

    JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT