SlideShare a Scribd company logo
1 of 12
Download to read offline
package reservation;
import java.util.*; //For Scanner Class
import java.time.*; //For LocalDate
import java.time.format.*; //For DateTimeFormatter
public class Reservation
{
double perNight = 105.00, finalAmt;
long noDays;
int m, d, y;
LocalDate std, end;
//Sets the Arrival date inputed by the user
void setArrivalDate(LocalDate arrivalDate)
{
std = arrivalDate;
}
//Sets the Departure date inputed by the user
void setDepartureDate(LocalDate departureDate)
{
end = departureDate;
}
//Returns the Arrival date
LocalDate getArrivalDate()
{
return std;
}
//Returns the Departure date
LocalDate getDepartureDate()
{
return end;
}
//Formats the Arrival date as per the requirement given question
String getArrivalDateFormatted()
{
String stdFormat;
stdFormat = "Arrival Date: " + std.getMonth() + " " + String.valueOf(std.getDayOfMonth())
+ ", " + String.valueOf(std.getYear());
return stdFormat;
}
//Formats the Departure date as per the requirement given question
String getDepartureDateFormatted()
{
String stdFormat;
stdFormat = "Departure Date: " + end.getMonth() + " " +
String.valueOf(end.getDayOfMonth()) + ", " + String.valueOf(end.getYear());
return stdFormat;
}
//Returns the Price per night as per the format
String getPricePerNightFormatted()
{
String pr = "Price: $" + String.valueOf(perNight) + " per night";
return pr;
}
//Returns the number of nights
long getNumberOfNights()
{
//toEpochDay() returns number of days
noDays = end.toEpochDay() - std.toEpochDay();
return noDays;
}
//Calculates final Amount to be paid
double getTotalPrice()
{
finalAmt = (double)getNumberOfNights() * perNight;
return finalAmt;
}
//Returns the Total amount to be paid as per the format given in the question
String getTotalPriceFormatted()
{
String finA = "Total price: $" + String.valueOf(getTotalPrice()) + " for " +
String.valueOf(getNumberOfNights()) + " night" ;
return finA;
}
//Accepts the Arrival date and Departure date from console
void accept()
{
//Creates object of LocaleDate
LocalDate std1, end1;
//Creates the Date Time Formater object and applies Format Style
//SHORT in mm/dd/yy format
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
//Creates Scanner class object to accept data from console
Scanner s = new Scanner(System.in);
System.out.println("Enter starting date mm/dd/yyyy: ");
System.out.println("Enter the arrival month (1-12):");
m = s.nextInt(); //Accept data in integer format
System.out.println("Enter the arrival day (1-31):") ;
d = s.nextInt();
System.out.println("Enter the arrival year:") ;
y = s.nextInt();
//Initializes the LocalDate object for Arrival date
std1 = LocalDate.of(y, m, d);
//Sets the SHORT date format
fmt.format(std1);
//Assigns Arrival date to class data member
setArrivalDate(std1);
System.out.println("Enter ending date mm/dd/yyyy: ");
System.out.println("Enter the departure month (1-12):");
m = s.nextInt(); //Accept data in integer format
System.out.println("Enter the departure day (1-31):") ;
d = s.nextInt();
System.out.println("Enter the departure year:") ;
y = s.nextInt();
//Initializes the LocalDate object for Departure date
end1 = LocalDate.of(y, m, d);
//Sets the SHORT date format
fmt.format(std1);
//Assigns Departure date to class data member
setDepartureDate(end1);
}
public static void main(String[] args)
{
char ch;
System.out.println("Welcome to the Reservation Calculator  ");
//Creates Reservation class object
Reservation cc = new Reservation();
Scanner s = new Scanner(System.in);
//Loops till Y is pressed
do
{
cc.accept();
System.out.println(cc.getArrivalDateFormatted());
System.out.println(cc.getDepartureDateFormatted());
System.out.println(cc.getPricePerNightFormatted());
System.out.println(cc.getTotalPriceFormatted());
System.out.println("Would you like to continue? (y/n)");
ch = s.next().charAt(0);
if(ch == 'y' || ch == 'Y')
continue;
else
break;
}while(true);
}
}
Output
Welcome to the Reservation Calculator
Enter starting date mm/dd/yyyy:
Enter the arrival month (1-12):
5
Enter the arrival day (1-31):
16
Enter the arrival year:
2016
Enter ending date mm/dd/yyyy:
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.0 per night
Total price: $210.0 for 2 night
Would you like to continue? (y/n)
y
Enter starting date mm/dd/yyyy:
Enter the arrival month (1-12):
7
Enter the arrival day (1-31):
20
Enter the arrival year:
2016
Enter ending date mm/dd/yyyy:
Enter the departure month (1-12):
7
Enter the departure day (1-31):
27
Enter the departure year:
2016
Arrival Date: JULY 20, 2016
Departure Date: JULY 27, 2016
Price: $105.0 per night
Total price: $735.0 for 7 night
Would you like to continue? (y/n)
n
Solution
package reservation;
import java.util.*; //For Scanner Class
import java.time.*; //For LocalDate
import java.time.format.*; //For DateTimeFormatter
public class Reservation
{
double perNight = 105.00, finalAmt;
long noDays;
int m, d, y;
LocalDate std, end;
//Sets the Arrival date inputed by the user
void setArrivalDate(LocalDate arrivalDate)
{
std = arrivalDate;
}
//Sets the Departure date inputed by the user
void setDepartureDate(LocalDate departureDate)
{
end = departureDate;
}
//Returns the Arrival date
LocalDate getArrivalDate()
{
return std;
}
//Returns the Departure date
LocalDate getDepartureDate()
{
return end;
}
//Formats the Arrival date as per the requirement given question
String getArrivalDateFormatted()
{
String stdFormat;
stdFormat = "Arrival Date: " + std.getMonth() + " " + String.valueOf(std.getDayOfMonth())
+ ", " + String.valueOf(std.getYear());
return stdFormat;
}
//Formats the Departure date as per the requirement given question
String getDepartureDateFormatted()
{
String stdFormat;
stdFormat = "Departure Date: " + end.getMonth() + " " +
String.valueOf(end.getDayOfMonth()) + ", " + String.valueOf(end.getYear());
return stdFormat;
}
//Returns the Price per night as per the format
String getPricePerNightFormatted()
{
String pr = "Price: $" + String.valueOf(perNight) + " per night";
return pr;
}
//Returns the number of nights
long getNumberOfNights()
{
//toEpochDay() returns number of days
noDays = end.toEpochDay() - std.toEpochDay();
return noDays;
}
//Calculates final Amount to be paid
double getTotalPrice()
{
finalAmt = (double)getNumberOfNights() * perNight;
return finalAmt;
}
//Returns the Total amount to be paid as per the format given in the question
String getTotalPriceFormatted()
{
String finA = "Total price: $" + String.valueOf(getTotalPrice()) + " for " +
String.valueOf(getNumberOfNights()) + " night" ;
return finA;
}
//Accepts the Arrival date and Departure date from console
void accept()
{
//Creates object of LocaleDate
LocalDate std1, end1;
//Creates the Date Time Formater object and applies Format Style
//SHORT in mm/dd/yy format
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
//Creates Scanner class object to accept data from console
Scanner s = new Scanner(System.in);
System.out.println("Enter starting date mm/dd/yyyy: ");
System.out.println("Enter the arrival month (1-12):");
m = s.nextInt(); //Accept data in integer format
System.out.println("Enter the arrival day (1-31):") ;
d = s.nextInt();
System.out.println("Enter the arrival year:") ;
y = s.nextInt();
//Initializes the LocalDate object for Arrival date
std1 = LocalDate.of(y, m, d);
//Sets the SHORT date format
fmt.format(std1);
//Assigns Arrival date to class data member
setArrivalDate(std1);
System.out.println("Enter ending date mm/dd/yyyy: ");
System.out.println("Enter the departure month (1-12):");
m = s.nextInt(); //Accept data in integer format
System.out.println("Enter the departure day (1-31):") ;
d = s.nextInt();
System.out.println("Enter the departure year:") ;
y = s.nextInt();
//Initializes the LocalDate object for Departure date
end1 = LocalDate.of(y, m, d);
//Sets the SHORT date format
fmt.format(std1);
//Assigns Departure date to class data member
setDepartureDate(end1);
}
public static void main(String[] args)
{
char ch;
System.out.println("Welcome to the Reservation Calculator  ");
//Creates Reservation class object
Reservation cc = new Reservation();
Scanner s = new Scanner(System.in);
//Loops till Y is pressed
do
{
cc.accept();
System.out.println(cc.getArrivalDateFormatted());
System.out.println(cc.getDepartureDateFormatted());
System.out.println(cc.getPricePerNightFormatted());
System.out.println(cc.getTotalPriceFormatted());
System.out.println("Would you like to continue? (y/n)");
ch = s.next().charAt(0);
if(ch == 'y' || ch == 'Y')
continue;
else
break;
}while(true);
}
}
Output
Welcome to the Reservation Calculator
Enter starting date mm/dd/yyyy:
Enter the arrival month (1-12):
5
Enter the arrival day (1-31):
16
Enter the arrival year:
2016
Enter ending date mm/dd/yyyy:
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.0 per night
Total price: $210.0 for 2 night
Would you like to continue? (y/n)
y
Enter starting date mm/dd/yyyy:
Enter the arrival month (1-12):
7
Enter the arrival day (1-31):
20
Enter the arrival year:
2016
Enter ending date mm/dd/yyyy:
Enter the departure month (1-12):
7
Enter the departure day (1-31):
27
Enter the departure year:
2016
Arrival Date: JULY 20, 2016
Departure Date: JULY 27, 2016
Price: $105.0 per night
Total price: $735.0 for 7 night
Would you like to continue? (y/n)
n

More Related Content

Similar to package reservation; import java.util.; For Scanner Class .pdf

please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
arishmarketing21
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
anonaeon
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
sooryasalini
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
aquadreammail
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdf
arihantgiftgallery
 
computer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptxcomputer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptx
IshooYadav
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
allystraders
 
URGENTJavaPlease updated the already existing Java program and m.pdf
URGENTJavaPlease updated the already existing Java program and m.pdfURGENTJavaPlease updated the already existing Java program and m.pdf
URGENTJavaPlease updated the already existing Java program and m.pdf
erremmfab
 
Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdf
saxenaavnish1
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
ezzi552
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
anushasarees
 
proj6Collision.javaproj6Collision.javapackage proj6;import.docx
proj6Collision.javaproj6Collision.javapackage proj6;import.docxproj6Collision.javaproj6Collision.javapackage proj6;import.docx
proj6Collision.javaproj6Collision.javapackage proj6;import.docx
wkyra78
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdf
ezzi97
 

Similar to package reservation; import java.util.; For Scanner Class .pdf (20)

please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
Creating an Uber Clone - Part III.pdf
Creating an Uber Clone - Part III.pdfCreating an Uber Clone - Part III.pdf
Creating an Uber Clone - Part III.pdf
 
Reloj en java
Reloj en javaReloj en java
Reloj en java
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdf
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
computer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptxcomputer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptx
 
Tank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineTank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engine
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
 
URGENTJavaPlease updated the already existing Java program and m.pdf
URGENTJavaPlease updated the already existing Java program and m.pdfURGENTJavaPlease updated the already existing Java program and m.pdf
URGENTJavaPlease updated the already existing Java program and m.pdf
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
 
Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdf
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
 
proj6Collision.javaproj6Collision.javapackage proj6;import.docx
proj6Collision.javaproj6Collision.javapackage proj6;import.docxproj6Collision.javaproj6Collision.javapackage proj6;import.docx
proj6Collision.javaproj6Collision.javapackage proj6;import.docx
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdf
 
date2.docx
date2.docxdate2.docx
date2.docx
 

More from anitasahani11

1. Confidential or privileged information cannot be denied to the co.pdf
1. Confidential or privileged information cannot be denied to the co.pdf1. Confidential or privileged information cannot be denied to the co.pdf
1. Confidential or privileged information cannot be denied to the co.pdf
anitasahani11
 
Whales are mammals that breathe into the lungs. Whales contain blow .pdf
Whales are mammals that breathe into the lungs. Whales contain blow .pdfWhales are mammals that breathe into the lungs. Whales contain blow .pdf
Whales are mammals that breathe into the lungs. Whales contain blow .pdf
anitasahani11
 
This site provides illustrative experience in the use of Excel for d.pdf
This site provides illustrative experience in the use of Excel for d.pdfThis site provides illustrative experience in the use of Excel for d.pdf
This site provides illustrative experience in the use of Excel for d.pdf
anitasahani11
 
The conch symbolizes social order, respect and power. When the boys .pdf
The conch symbolizes social order, respect and power. When the boys .pdfThe conch symbolizes social order, respect and power. When the boys .pdf
The conch symbolizes social order, respect and power. When the boys .pdf
anitasahani11
 
The bone marrow is the wellspring of numerous immune and blood cells.pdf
The bone marrow is the wellspring of numerous immune and blood cells.pdfThe bone marrow is the wellspring of numerous immune and blood cells.pdf
The bone marrow is the wellspring of numerous immune and blood cells.pdf
anitasahani11
 
Traffic intersection is a piece of transportation infrastructure wha.pdf
  Traffic intersection is a piece of transportation infrastructure wha.pdf  Traffic intersection is a piece of transportation infrastructure wha.pdf
Traffic intersection is a piece of transportation infrastructure wha.pdf
anitasahani11
 
There is actually a few differences. Firstly, a p.pdf
                     There is actually a few differences. Firstly, a p.pdf                     There is actually a few differences. Firstly, a p.pdf
There is actually a few differences. Firstly, a p.pdf
anitasahani11
 

More from anitasahani11 (20)

2.Kernel need to be protected because non-root user execute kernel.pdf
2.Kernel need to be protected because non-root user execute kernel.pdf2.Kernel need to be protected because non-root user execute kernel.pdf
2.Kernel need to be protected because non-root user execute kernel.pdf
 
1.C. Fate of the blastopore becomes the mouth.2.C. Endodermis Casp.pdf
1.C. Fate of the blastopore becomes the mouth.2.C. Endodermis Casp.pdf1.C. Fate of the blastopore becomes the mouth.2.C. Endodermis Casp.pdf
1.C. Fate of the blastopore becomes the mouth.2.C. Endodermis Casp.pdf
 
1. a. -8 to 4 is 12 unitsb. D to B is 8 unitsc. idk what that de.pdf
1. a. -8 to 4 is 12 unitsb. D to B is 8 unitsc. idk what that de.pdf1. a. -8 to 4 is 12 unitsb. D to B is 8 unitsc. idk what that de.pdf
1. a. -8 to 4 is 12 unitsb. D to B is 8 unitsc. idk what that de.pdf
 
1. Confidential or privileged information cannot be denied to the co.pdf
1. Confidential or privileged information cannot be denied to the co.pdf1. Confidential or privileged information cannot be denied to the co.pdf
1. Confidential or privileged information cannot be denied to the co.pdf
 
The three different 3SolutionThe three different 3.pdf
The three different 3SolutionThe three different 3.pdfThe three different 3SolutionThe three different 3.pdf
The three different 3SolutionThe three different 3.pdf
 
Whales are mammals that breathe into the lungs. Whales contain blow .pdf
Whales are mammals that breathe into the lungs. Whales contain blow .pdfWhales are mammals that breathe into the lungs. Whales contain blow .pdf
Whales are mammals that breathe into the lungs. Whales contain blow .pdf
 
w12-8v6Solutionw12-8v6.pdf
w12-8v6Solutionw12-8v6.pdfw12-8v6Solutionw12-8v6.pdf
w12-8v6Solutionw12-8v6.pdf
 
This site provides illustrative experience in the use of Excel for d.pdf
This site provides illustrative experience in the use of Excel for d.pdfThis site provides illustrative experience in the use of Excel for d.pdf
This site provides illustrative experience in the use of Excel for d.pdf
 
The conch symbolizes social order, respect and power. When the boys .pdf
The conch symbolizes social order, respect and power. When the boys .pdfThe conch symbolizes social order, respect and power. When the boys .pdf
The conch symbolizes social order, respect and power. When the boys .pdf
 
The bone marrow is the wellspring of numerous immune and blood cells.pdf
The bone marrow is the wellspring of numerous immune and blood cells.pdfThe bone marrow is the wellspring of numerous immune and blood cells.pdf
The bone marrow is the wellspring of numerous immune and blood cells.pdf
 
Stanley Miller experiment explains the origin and evolution of earth.pdf
Stanley Miller experiment explains the origin and evolution of earth.pdfStanley Miller experiment explains the origin and evolution of earth.pdf
Stanley Miller experiment explains the origin and evolution of earth.pdf
 
service revenueSolutionservice revenue.pdf
service revenueSolutionservice revenue.pdfservice revenueSolutionservice revenue.pdf
service revenueSolutionservice revenue.pdf
 
public class DecimalToBinary {    public void printBinaryFormat(in.pdf
public class DecimalToBinary {    public void printBinaryFormat(in.pdfpublic class DecimalToBinary {    public void printBinaryFormat(in.pdf
public class DecimalToBinary {    public void printBinaryFormat(in.pdf
 
#includeiostream #includequeue #includefstream using nam.pdf
#includeiostream #includequeue #includefstream using nam.pdf#includeiostream #includequeue #includefstream using nam.pdf
#includeiostream #includequeue #includefstream using nam.pdf
 
Traffic intersection is a piece of transportation infrastructure wha.pdf
  Traffic intersection is a piece of transportation infrastructure wha.pdf  Traffic intersection is a piece of transportation infrastructure wha.pdf
Traffic intersection is a piece of transportation infrastructure wha.pdf
 
Step1 pH =2 ; [H+] = 1 x10^-2 moleslitre Step2 .pdf
                     Step1 pH =2 ; [H+] = 1 x10^-2 moleslitre  Step2 .pdf                     Step1 pH =2 ; [H+] = 1 x10^-2 moleslitre  Step2 .pdf
Step1 pH =2 ; [H+] = 1 x10^-2 moleslitre Step2 .pdf
 
ZnOCu2OV2O3,Ni2O3MnO .pdf
                     ZnOCu2OV2O3,Ni2O3MnO                         .pdf                     ZnOCu2OV2O3,Ni2O3MnO                         .pdf
ZnOCu2OV2O3,Ni2O3MnO .pdf
 
There is actually a few differences. Firstly, a p.pdf
                     There is actually a few differences. Firstly, a p.pdf                     There is actually a few differences. Firstly, a p.pdf
There is actually a few differences. Firstly, a p.pdf
 
Hg^2+ is soft acid and thus akin to bind to soft .pdf
                     Hg^2+ is soft acid and thus akin to bind to soft .pdf                     Hg^2+ is soft acid and thus akin to bind to soft .pdf
Hg^2+ is soft acid and thus akin to bind to soft .pdf
 
HCl dissociates into H+ and Cl- in solution. The .pdf
                     HCl dissociates into H+ and Cl- in solution. The .pdf                     HCl dissociates into H+ and Cl- in solution. The .pdf
HCl dissociates into H+ and Cl- in solution. The .pdf
 

Recently uploaded

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

package reservation; import java.util.; For Scanner Class .pdf

  • 1. package reservation; import java.util.*; //For Scanner Class import java.time.*; //For LocalDate import java.time.format.*; //For DateTimeFormatter public class Reservation { double perNight = 105.00, finalAmt; long noDays; int m, d, y; LocalDate std, end; //Sets the Arrival date inputed by the user void setArrivalDate(LocalDate arrivalDate) { std = arrivalDate; } //Sets the Departure date inputed by the user void setDepartureDate(LocalDate departureDate) { end = departureDate; } //Returns the Arrival date LocalDate getArrivalDate() { return std; } //Returns the Departure date LocalDate getDepartureDate() { return end;
  • 2. } //Formats the Arrival date as per the requirement given question String getArrivalDateFormatted() { String stdFormat; stdFormat = "Arrival Date: " + std.getMonth() + " " + String.valueOf(std.getDayOfMonth()) + ", " + String.valueOf(std.getYear()); return stdFormat; } //Formats the Departure date as per the requirement given question String getDepartureDateFormatted() { String stdFormat; stdFormat = "Departure Date: " + end.getMonth() + " " + String.valueOf(end.getDayOfMonth()) + ", " + String.valueOf(end.getYear()); return stdFormat; } //Returns the Price per night as per the format String getPricePerNightFormatted() { String pr = "Price: $" + String.valueOf(perNight) + " per night"; return pr; } //Returns the number of nights long getNumberOfNights() { //toEpochDay() returns number of days noDays = end.toEpochDay() - std.toEpochDay(); return noDays; } //Calculates final Amount to be paid
  • 3. double getTotalPrice() { finalAmt = (double)getNumberOfNights() * perNight; return finalAmt; } //Returns the Total amount to be paid as per the format given in the question String getTotalPriceFormatted() { String finA = "Total price: $" + String.valueOf(getTotalPrice()) + " for " + String.valueOf(getNumberOfNights()) + " night" ; return finA; } //Accepts the Arrival date and Departure date from console void accept() { //Creates object of LocaleDate LocalDate std1, end1; //Creates the Date Time Formater object and applies Format Style //SHORT in mm/dd/yy format DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); //Creates Scanner class object to accept data from console Scanner s = new Scanner(System.in); System.out.println("Enter starting date mm/dd/yyyy: "); System.out.println("Enter the arrival month (1-12):"); m = s.nextInt(); //Accept data in integer format System.out.println("Enter the arrival day (1-31):") ; d = s.nextInt(); System.out.println("Enter the arrival year:") ; y = s.nextInt(); //Initializes the LocalDate object for Arrival date
  • 4. std1 = LocalDate.of(y, m, d); //Sets the SHORT date format fmt.format(std1); //Assigns Arrival date to class data member setArrivalDate(std1); System.out.println("Enter ending date mm/dd/yyyy: "); System.out.println("Enter the departure month (1-12):"); m = s.nextInt(); //Accept data in integer format System.out.println("Enter the departure day (1-31):") ; d = s.nextInt(); System.out.println("Enter the departure year:") ; y = s.nextInt(); //Initializes the LocalDate object for Departure date end1 = LocalDate.of(y, m, d); //Sets the SHORT date format fmt.format(std1); //Assigns Departure date to class data member setDepartureDate(end1); } public static void main(String[] args) { char ch; System.out.println("Welcome to the Reservation Calculator "); //Creates Reservation class object Reservation cc = new Reservation(); Scanner s = new Scanner(System.in); //Loops till Y is pressed do
  • 5. { cc.accept(); System.out.println(cc.getArrivalDateFormatted()); System.out.println(cc.getDepartureDateFormatted()); System.out.println(cc.getPricePerNightFormatted()); System.out.println(cc.getTotalPriceFormatted()); System.out.println("Would you like to continue? (y/n)"); ch = s.next().charAt(0); if(ch == 'y' || ch == 'Y') continue; else break; }while(true); } } Output Welcome to the Reservation Calculator Enter starting date mm/dd/yyyy: Enter the arrival month (1-12): 5 Enter the arrival day (1-31): 16 Enter the arrival year: 2016 Enter ending date mm/dd/yyyy: 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.0 per night Total price: $210.0 for 2 night Would you like to continue? (y/n)
  • 6. y Enter starting date mm/dd/yyyy: Enter the arrival month (1-12): 7 Enter the arrival day (1-31): 20 Enter the arrival year: 2016 Enter ending date mm/dd/yyyy: Enter the departure month (1-12): 7 Enter the departure day (1-31): 27 Enter the departure year: 2016 Arrival Date: JULY 20, 2016 Departure Date: JULY 27, 2016 Price: $105.0 per night Total price: $735.0 for 7 night Would you like to continue? (y/n) n Solution package reservation; import java.util.*; //For Scanner Class import java.time.*; //For LocalDate import java.time.format.*; //For DateTimeFormatter public class Reservation { double perNight = 105.00, finalAmt; long noDays; int m, d, y; LocalDate std, end;
  • 7. //Sets the Arrival date inputed by the user void setArrivalDate(LocalDate arrivalDate) { std = arrivalDate; } //Sets the Departure date inputed by the user void setDepartureDate(LocalDate departureDate) { end = departureDate; } //Returns the Arrival date LocalDate getArrivalDate() { return std; } //Returns the Departure date LocalDate getDepartureDate() { return end; } //Formats the Arrival date as per the requirement given question String getArrivalDateFormatted() { String stdFormat; stdFormat = "Arrival Date: " + std.getMonth() + " " + String.valueOf(std.getDayOfMonth()) + ", " + String.valueOf(std.getYear()); return stdFormat; } //Formats the Departure date as per the requirement given question String getDepartureDateFormatted()
  • 8. { String stdFormat; stdFormat = "Departure Date: " + end.getMonth() + " " + String.valueOf(end.getDayOfMonth()) + ", " + String.valueOf(end.getYear()); return stdFormat; } //Returns the Price per night as per the format String getPricePerNightFormatted() { String pr = "Price: $" + String.valueOf(perNight) + " per night"; return pr; } //Returns the number of nights long getNumberOfNights() { //toEpochDay() returns number of days noDays = end.toEpochDay() - std.toEpochDay(); return noDays; } //Calculates final Amount to be paid double getTotalPrice() { finalAmt = (double)getNumberOfNights() * perNight; return finalAmt; } //Returns the Total amount to be paid as per the format given in the question String getTotalPriceFormatted() { String finA = "Total price: $" + String.valueOf(getTotalPrice()) + " for " + String.valueOf(getNumberOfNights()) + " night" ; return finA; }
  • 9. //Accepts the Arrival date and Departure date from console void accept() { //Creates object of LocaleDate LocalDate std1, end1; //Creates the Date Time Formater object and applies Format Style //SHORT in mm/dd/yy format DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); //Creates Scanner class object to accept data from console Scanner s = new Scanner(System.in); System.out.println("Enter starting date mm/dd/yyyy: "); System.out.println("Enter the arrival month (1-12):"); m = s.nextInt(); //Accept data in integer format System.out.println("Enter the arrival day (1-31):") ; d = s.nextInt(); System.out.println("Enter the arrival year:") ; y = s.nextInt(); //Initializes the LocalDate object for Arrival date std1 = LocalDate.of(y, m, d); //Sets the SHORT date format fmt.format(std1); //Assigns Arrival date to class data member setArrivalDate(std1); System.out.println("Enter ending date mm/dd/yyyy: "); System.out.println("Enter the departure month (1-12):"); m = s.nextInt(); //Accept data in integer format System.out.println("Enter the departure day (1-31):") ; d = s.nextInt();
  • 10. System.out.println("Enter the departure year:") ; y = s.nextInt(); //Initializes the LocalDate object for Departure date end1 = LocalDate.of(y, m, d); //Sets the SHORT date format fmt.format(std1); //Assigns Departure date to class data member setDepartureDate(end1); } public static void main(String[] args) { char ch; System.out.println("Welcome to the Reservation Calculator "); //Creates Reservation class object Reservation cc = new Reservation(); Scanner s = new Scanner(System.in); //Loops till Y is pressed do { cc.accept(); System.out.println(cc.getArrivalDateFormatted()); System.out.println(cc.getDepartureDateFormatted()); System.out.println(cc.getPricePerNightFormatted()); System.out.println(cc.getTotalPriceFormatted()); System.out.println("Would you like to continue? (y/n)"); ch = s.next().charAt(0); if(ch == 'y' || ch == 'Y') continue; else break; }while(true);
  • 11. } } Output Welcome to the Reservation Calculator Enter starting date mm/dd/yyyy: Enter the arrival month (1-12): 5 Enter the arrival day (1-31): 16 Enter the arrival year: 2016 Enter ending date mm/dd/yyyy: 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.0 per night Total price: $210.0 for 2 night Would you like to continue? (y/n) y Enter starting date mm/dd/yyyy: Enter the arrival month (1-12): 7 Enter the arrival day (1-31): 20 Enter the arrival year: 2016 Enter ending date mm/dd/yyyy: Enter the departure month (1-12): 7 Enter the departure day (1-31): 27
  • 12. Enter the departure year: 2016 Arrival Date: JULY 20, 2016 Departure Date: JULY 27, 2016 Price: $105.0 per night Total price: $735.0 for 7 night Would you like to continue? (y/n) n