Results 1 to 5 of 5
  1. #1
    ITStudent is offline Member
    Join Date
    Jul 2013
    Posts
    25
    Rep Power
    0

    Default Programming Help

    Here is my main class
    Java Code:
    import javax.swing.*;
    public class HotelRoom
    {
    
    	private int roomNumber;
    	protected double rate;
    
    	public void setroomNumber(int num)
    	{
    		roomNumber=num;
    	}
    
    	public int getroomNumber()
    	{
    		return roomNumber;
    	}
    
    	public void setRate (double r)
    	{
    		rate=r;
    	}
    
    	public double getRate()
    	{
    		return rate;
    	}
     
    	public HotelRoom(int room)
    	{
    		roomNumber=room;
    		if(room <=299)
    			rate=69.95;
    		else
    			rate=89.95;
    	}
    
    	 public void displayRate(int room)
    	{
    		 if(room<=299)
    		JOptionPane.showMessageDialog(null,
    				"The room will cost $69.95 per night.");
    		 else
    			 JOptionPane.showMessageDialog(null,
    					 "The room will cost $89.95 per night.");
    	}
    }
    Here is the extended class
    Java Code:
    public class Suite extends HotelRoom
    {
     
    	public Suite (int room)
    	{
    		super(room);
    		rate +=40;
    	}
    	
    }
    Now this is the application
    Java Code:
    import javax.swing.*;
    public class UseHotelRoom
    {
    
    	public static void main (String [] args)
    	{
    		
    
    		HotelRoom myRoom = new HotelRoom(300);
    			myRoom.displayRate();
    		 
    
    		HotelRoom theirRoom = new HotelRoom(201);
    			theirRoom.displayRate();
    		
    		
    	}
    
    }
    Now what I need help with is the error handling and I need to compute the rental fee for the nights stayed. Also the indication of either it's a Suite or a regular room with it's specific number
    Last edited by ITStudent; 09-03-2013 at 04:15 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Programming Help

    What in particular about error handling are you having trouble with?

  3. #3
    ITStudent is offline Member
    Join Date
    Jul 2013
    Posts
    25
    Rep Power
    0

    Default Re: Programming Help

    Never mind Here is the answer to the program

    Java Code:
    public class HotelRoom {
    	private double nRate;
    	private int roomNum;
    	private double numHrs;
    	
    	HotelRoom(int rum)
    	{
    		roomNum = rum;
    	}
    	public double getnumHrs()
    	{
    		return numHrs;
    	}
    	public int getRumNumber()
    	{
    		return roomNum;
    	}
    	
    	public double getnRate()
    	{
    		return nRate;
    	}
    	public void setNumHrs(double hrs)
    	{
    		numHrs = hrs;
    	}
    	
    	public double computeRental(double nHrs)
    	{
    		double rent = 0;
    		
    		numHrs = nHrs;
    		
    		if (roomNum <= 299)
    			rent = 69.95 * numHrs;
    		else
    			rent = 89.95 * numHrs;
    				
    		return rent;
    			
    	}
    }
    _______________________
    
    
    public class Suite extends HotelRoom {
    
    	public Suite(int rum, double numHrs)
    	{
    	    super(rum);
    	}
    		
    	
    	public double computeRental(double hrs)
    	{
    		super.setNumHrs(hrs);
    		
    		return (super.computeRental(hrs)+ 40.00);
    		
    	}
    	
    }
    
    ___________________
    
    import java.util.*;
    
    public class UseHotelRoom {
    
    	
    	public static void main(String[] args) {
    		
    		int rum;
    		double numHrs;
    		int suite =0;
    		
    		Scanner console = new Scanner(System.in);
    		
    		System.out.println("Enter Room Number:");
    		rum=console.nextInt();
    		
    		System.out.println("Enter Number of Hours:");
    		numHrs = console.nextDouble();
    		
    		System.out.println("Type of Room Occupied:");
    		System.out.println("Enter 1 if Suite, 0 if not:");
    		suite = console.nextInt();
    		
    		if (suite == 0){
    		     HotelRoom customer = new HotelRoom(rum);
    		     System.out.println("The Rental fee is :" + customer.computeRental(numHrs));
    		} 
    		else
    		{
    			Suite customer = new Suite(rum, numHrs);
    			System.out.println("The Rental fee is :" + customer.computeRental(numHrs));}
    	}		
    
    		     
    	
    	}

  4. #4
    ITStudent is offline Member
    Join Date
    Jul 2013
    Posts
    25
    Rep Power
    0

    Default Re: Programming Help

    I need help with my Lab work Write an application that displays a JFrame containing the words to any well-known nursery rhyme. I didn't get the concept about GUI cause the discussion was so short.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Programming Help

    1. Start a new thread
    2. Ask a specific question

Similar Threads

  1. Replies: 1
    Last Post: 04-20-2013, 09:16 PM
  2. Replies: 1
    Last Post: 04-20-2013, 09:15 PM
  3. android programming vs game programming using java
    By vgoel38 in forum Forum Lobby
    Replies: 2
    Last Post: 09-08-2012, 12:11 AM
  4. GPS programming =)
    By santa in forum New To Java
    Replies: 6
    Last Post: 01-23-2011, 06:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •