Define a class Resort with the following description:
- Members are : RNo to store Room Number, Name store customer name, Charges to store per day charges, Days to store number of days of stay.
- Member functions :
- Compute() to calculate and return Amount as Days * Charges and if the values of Days*Charges is more than 11000 then as 1.02*Days*Charges
- Getinfo() A function to enter the content Rno, Name, Charges and Days.
- DispInfo() A function to enter the content Rno, Name, Charges, Days and Amount by calling function Compute().
import java.util.*;
class RESORT
{
int RNo;
String Name;
int Charges;
int Days;
public double Compute(){
double amt;
amt=Charges*Days;
if(amt>=11000)
amt=amt*1.02;
return amt;
}
public void GetInfo(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Room Number : ");
RNo=sc.nextInt();
System.out.println("Enter Name : ");
Name=sc.next();
System.out.println("Enter Charges : ");
Charges=sc.nextInt();
System.out.println("Enter Days : ");
Days=sc.nextInt();
}
public void DispInfo(){
System.out.println("Room No : "+RNo);
System.out.println("Name : "+Name);
System.out.println("Charges : "+Charges);
System.out.println("Days : "+Days);
System.out.println("Total Amount : "+Compute());
}
}
class ResortData
{
public static void main(String args[])
{
RESORT res=new RESORT();
res.GetInfo();
res.DispInfo();
}
}
Save the above Program with “ResortData.Java” then compile it with the following command :
javac ResortData.java //to compile the code java ResortData // to run the code
Output is :
Enter Room Number : 105 Enter Name : Sunny Enter Charges : 3000 Enter Days : 8 Room No : 105 Name : Sunny Charges : 3000 Days : 8 Total Amount : 24480.0