Results 1 to 10 of 10

Thread: Help! Help!

  1. #1
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default Help! Help!

    Here are three Java files:

    Rental.java
    Java Code:
    public class Rental extends Main_Rental
    {
     String[] ID=new String[35];
     int[] RentalDays=new int[35];
     float[] RatePerDay=new float[35];
     String[] car=new String[35];
     
     String UserID;
     int DaysOfRental;
     float RentalRatePerDay;
     String carName;
     
     public Rental(String id,String category,int days)
     {
      UserID=id;
      carName=category;
      DaysOfRental=days;
     }
     
     public void economyCar()
     {
      carName="economyCar";
      RentalRatePerDay=110f;
     }
     
     public void compactCar()
     {
      carName="compactCar";
      RentalRatePerDay=125f;
     }
     
     public void miniCar()
     {
      carName="miniCar";
      RentalRatePerDay=100f;
     }
     
     public void standardCar()
     {
      carName="standardCar";
      RentalRatePerDay=150f;
     }
     
     public void fullSizeCar()
     {
      carName="fullSizeCar";
      RentalRatePerDay=250f;
     }
     
     public void midSizeCar()
     {
      carName="midSizeCar";
      RentalRatePerDay=160f;
     }
     
     public void luxuryCar()
     {
      carName="luxuryCar";
      RentalRatePerDay=300f;
     }
     
     public void passengerVan()
     {
      carName="passengerVan";
      RentalRatePerDay=120f;
     }
     
     public boolean longParking()
     {
      if (DaysOfRental>6)
      {
       return true;
      }
      else
      {
       return false;
      }
        
     }
     
     public void economyCar(float rate)
     {
      carName="economyCar";
      RentalRatePerDay=rate;
     }
     
     public void compactCar(float rate)
     {
      carName="compactCar";
      RentalRatePerDay=rate;
     }
     
     public void miniCar(float rate)
     {
      carName="miniCar";
      RentalRatePerDay=rate;
     }
     
     public void standardCar(float rate)
     {
      carName="standardCar";
      RentalRatePerDay=rate;
     }
     
     public void fullSizeCar(float rate)
     {
      carName="fullSizeCar";
      RentalRatePerDay=rate;
     }
     
     public void midSizeCar(float rate)
     {
      carName="midSizeCar";
      RentalRatePerDay=rate;
     }
     
     public void luxuryCar(float rate)
     {
      carName="luxuryCar";
      RentalRatePerDay=rate;
     }
     
     public void passengerVan(float rate)
     {
      carName="passengerVan";
      RentalRatePerDay=rate;
     }
     
    }
    Carpark.java
    Java Code:
    import java.io.*;
    public class Carpark extends Main_Rental
    {
     int[] season_rental=new int[35];
      public void newRentalInformation() throws IOException
     {
      BufferedReader newInfo=new BufferedReader(new InputStreamReader(System.in));
      String info=newInfo.readLine();
      info.toLowerCase();
      char x=info.charAt(0);
      
     }
     
     public String searchCarRentalInfo(String car) throws IOException
     {
      BufferedReader search=new BufferedReader(new InputStreamReader(System.in));
      String carSearch=search.readLine();
      return car;
     }
     public float increaseRentingRate(float ratePerDay, Rental rent)
     {
      if (rent.longParking()==true)
      {
       ratePerDay = ratePerDay + (ratePerDay * 0.12f);
      } 
       return ratePerDay;
     }
     public void viewAllRecords(Rental rent2)
     {
       for (int i = 0; i < 35; i++)
      {
       System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
       System.out.println("ID\tDays\tRate/Day\tCarType\tTotal");
       System.out.println(rent2.ID[i]);
       System.out.println("\t"+rent2.RentalDays[i]);
       System.out.println("\t"+rent2.RatePerDay[i]);
       System.out.println("\t"+rent2.car[i]);
       System.out.println("\t"+rent2.RentalDays[i]*rent2.RatePerDay[i]);
      }
     }
    }
    Main_Rental.java
    Java Code:
    import java.io.*;
    public class Main_Rental
    {
    	int count, count2;
    	Rental rental = new Rental();
    	Carpark run = new Carpark();
    	public void main(String args[]) throws IOException
    	{
    		mainMenu();
    	}
    	public void mainMenu() throws IOException
    	{
    		char choice;
    		BufferedReader input2=new BufferedReader(new InputStreamReader(System.in));
    		System.out.println("\t**||||-----------------------------------------------||||**");
    		System.out.println("\t**||||-------C A R   R E N T A L   S Y S T E M-------||||**");
    		System.out.println("\t**||||-----------------------------------------------||||**");
    		System.out.println("\t\t   [A] - Add rental information");
    		System.out.println("\t\t   [V] - View all rental information");
    		System.out.println("\t\t   [S] - Search for rental information");
    		System.out.println("\t\t   [E] - Exit rental system");
    		System.out.println();
    		System.out.println();
    		System.out.println();
    		System.out.print("Select option: ");
    		String in=input2.readLine();
    		in.toLowerCase();
    		choice=in.charAt(0);
    		switch (choice)
    		{
    			case 'a':
    		{
    		BufferedReader addLine=new BufferedReader(new InputStreamReader(System.in));
    		System.out.print("\nEnter line number (0-34): ");
    		count=Integer.parseInt(addLine.readLine());
    		BufferedReader addID=new BufferedReader(new InputStreamReader(System.in));
    		System.out.print("\nEnter customer's ID: ");
    		rental.ID[count]=addID.readLine();
    		BufferedReader addCategory=new BufferedReader(new InputStreamReader(System.in));
    		System.out.print("\nChoose a car Category: ");
    		System.out.print("\n[1] Economy car");
    	 	System.out.print("\n[2] Compact car");
    	 	System.out.print("\n[3] Mini car");
    	 	System.out.print("\n[4] Standard car");
    	 	System.out.print("\n[5] Full-size car");
    	 	System.out.print("\n[6] Mid-size car");
    	 	System.out.print("\n[7] Luxury car");
    	 	System.out.print("\n[8] Passenger van");
    	 	int select=Integer.parseInt(addCategory.readLine());
     		switch (select)
     		{
      			case 1:
       			{
        			rental.economyCar();
        			break;
       			}
       			case 2:
       			{
        			rental.compactCar();
        			break;
       			}
       			case 3:
       			{
        			rental.miniCar();
        			break;
       			}
       			case 4:
       			{
        			rental.standardCar();
        			break;
       			}
    	   		case 5:
       			{
        			rental.fullSizeCar();
    	    		break;
       			}
       			case 6:
    	   		{
        			rental.midSizeCar();
        			break;
       			}
    	   		case 7:
    	   		{
        			rental.luxuryCar();
        			break;
      	 		}
      	 		case 8:
       			{
        			rental.passengerVan();
        			break;
       			}
       			default:
       			{
       				System.out.println("Error");
       				break;
       			}
    		}
      
      		BufferedReader addDays=new BufferedReader(new InputStreamReader(System.in));
      		System.out.print("\nEnter number of days to be rented: ");
      		rental.RentalDays[count]=Integer.parseInt(addDays.readLine());
    		rental.longParking();
    		run.increaseRentingRate(rental.RatePerDay[count], rental);
    		mainMenu();
    		}
    			case 'v':
    			{
    				System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    				System.out.println("#\tID\tDays\tRate/Day\tCarType\tTotal");
    				while (count < 35)
    				{
    					System.out.print("\n"+count);
    					System.out.print("\t"+rental.ID[count]);
    					System.out.print("\t"+rental.RentalDays[count]);
    					System.out.print("\t"+rental.RatePerDay[count]);
    					System.out.print("\t"+rental.car[count]);
    					System.out.print("\t"+rental.RentalDays[count]*rental.RatePerDay[count]);
    				}
    				mainMenu();
    			}
    			case 's':
    			{
    				BufferedReader searchMan=new BufferedReader(new InputStreamReader(System.in));
    		System.out.print("\nWhat line number are you looking for: ");
    		count2=Integer.parseInt(searchMan.readLine());
    		if (count2 == count)
    		{
    					System.out.print("\n"+count);
    					System.out.print("\t"+rental.ID[count]);
    					System.out.print("\t"+rental.RentalDays[count]);
    					System.out.print("\t"+rental.RatePerDay[count]);
    					System.out.print("\t"+rental.car[count]);
    					System.out.print("\t"+rental.RentalDays[count]*rental.RatePerDay[count]);
    		}
    		else
    		{
    			System.out.println("Not found\n");
    		}
    				mainMenu();
    			}
    			case 'e':
    			{
    				break;
    			}
    			default:
    			{
    				System.out.println("\nSystem error");
    				mainMenu();
    			}
    		}
    	}
    }
    Whenever I'm trying to compile my program, it reads:

    Main_Rental.java, line 5: Rental(java.lang.String,java.lang.String,int) in Rental cannot be applied to ()
    Java Code:
    Rental rental = new Rental();
    (1 error)

    What's the meaning of this? How can it be solved?

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Rental(java.lang.String,java.lang.String,int) in Rental cannot be applied to ()

    That error means your trying to create a new rental object without any parameters when the constructor requires a (String, String, int)

  3. #3
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    In this case, what are the parameters?

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    the parameters are what you need in the constructor. in the case of new Rental() you need new Rental(id,category,days)

  5. #5
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    okay.

    Java Code:
    Rental rental = new Rental(String id,String category,int days);
    but there's still an error. what would i do?

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    remove the descriptors in front of the variables. send it how I had it. Those variables should be pre-defined and when are sent to the constructor the constructor knows how to cast them.

  7. #7
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    nevermind I see your problem. You can't have Rental rental = new Rental() where you have it. If you need it just defined then do Rental rental;

    Once you get all your values you then create a new Rental by calling rental = new Rental(id, category, days);

  8. #8
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    okay thanks. but i have another problem. i know main's supposed to be a static function, but when i try to run my program (public void main), there's an exception in "main" thread. what would i do?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    tell us more about this exception: show us the exception in its entirety and let us know which line on of your main causes it to occur.

  10. #10
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    normally this exception occurs if i have an error in the java. good thing i tweaked everything to make it work.

Posting Permissions

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