Link to home
Start Free TrialLog in
Avatar of computerese
computerese

asked on

Help with designing a Java driver program

I need to determine inventory requirements, assuming that one group of customers always return their rented video tapes late (Group A) and another group always returns their rented video tapes on-time (Group B). I want to see how long it would take before Group A exceeds Group B. My method would use String Group, int Number, double lateFeePercent.

I have a class program (with data) already that compiles OK, but I need some guidance with assembling a test program (driver program) that will contain the methods.

I want to create a method in addition to the main method in the driver program that will be callable within the driver and will execute its statements each time the main method runs. If the driver contains a while loop, should the while loop be placed as the declarations for this second method (between the method's braces) , or after the method. I am getting a "cannot find symbol" compiler error with an early version of my driver program. How do ensure that the driver program is picking up information from the class program, or do I need to separately declare the variables in the driver program?

Any help would be appreciated.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>
I want to create a method in addition to the main method in the driver program that will be callable within the driver and will execute its statements each time the main method runs.
>>

You need to create an instance of the driver in its main method and then invoke that other method

>>
If the driver contains a while loop, should the while loop be placed ... or after the method.
>>

The while loop *can* only be placed within the method

If anything is not clear please ask questions in conjunction with posting the code you wrote
Avatar of computerese
computerese

ASKER

@CEHJ

Thanks for your speedy reply. Your info helps. Your reply regarding where to situate the while loop is clear to me, but I'm unclear what you mean about creating an instance of the driver in its main method. You invited me to post the code I wrote. Do you need just what I have for the driver program, or do you need to see posted both the class (data) and the driver program? Will post both if needed.
>>Do you need just what I have for the driver program

Let's post nothing for the moment.

>>but I'm unclear what you mean about creating an instance of the driver in its main method.

Let your class be called 'Driver'

public static void main(String[] args) {
    Driver d = new Driver();
    d.start();
}

is the sort of thing you should have
I implemented the changes you suggested regarding creating an instance of the driver in the Driver program's main method. I'm not sure what "d.start():" refers to. Could you elaborate a little as to why I would create an instance of the driver ("Driver"), instead of an instance of the class file that holds the data? I know you are right, but I just don't understand the logic. I am posting my driver program as it exists so far, in the hope that maybe we could start taking a look at that. I'm not sure how to make my while loop compare two different items (groupA and groupB).

Your knowledge and patience are greatly appreciated.

// class name
 public class Driver
{ //
/* Create an instance of the driver in its main method and then invoke the second method*/
            public static void main(String[] args)
            { //
            Driver groupA = new Driver (String name, int 10, double 15);
            groupA.start();
            Driver groupB = new Driver (String name, int 100, double 35);
            groupB.start();

/* Main method executes a second method that calls a method to do the calculations for groupA and groupB when the main method executes. After the inventoryAmount method is run the program ends*/
            
            inventoryAmount();
            } //      
                        
      //---------------------------------------------------------------------
      // class methods
      //method definition (inventoryAmount())            
      static void inventoryAmount()
      { //
            int inventoryAmount;
            int count = years;
            while (groupA < groupB)
            {  //
            groupA = (inventoryAmount + (lateFeePercent/100) *   inventoryAmount);
            count++;
                        
            groupB = (inventoryAmount + (lateFeePercent/100) * inventoryAmount);
            count++;
            if (groupA > groupB)
                        
            }  //
                                          
            System.out.println ("Late Returns Exceed On-time Returns in"
                        + years);
                        
            }  
}  //
SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Could you elaborate a little as to why I would create an instance of the driver ("Driver")

Because main is just an entry point for the program, which is essentially implemented not by the class Driver, but *by an object of type Driver*. Java is an object oriented language
@mayankeagle
@CEHJ

Thanks for your useful responses. However, I was wondering if a slightly different approach might be more productive. It might be best if this Driver file is built one piece at a time. Let's start with this: I want to call a method in the other class to my Driver class. Here is the other method's code:

public int inventoryAmount(int years)
{
     double inventoryAmount = inventory;
     int count = years;

     while ((count > 0)  &&  (inventoryAmount > 0))
    {
          inventoryAmount = (inventoryAmount +   (lateFeePercent/100)
                     * inventoryAmount);
          count--;
    }
    if   (inventoryAmount > 0)
         return (int)inventoryAmount;
else
      return 0;
}

Now, all I need is a little help with creating a while loop that will increment the years so the program can output information on how many years are required before groupA exceeds groupB. I reviewed the info about comparable interfaces, but I'm sure there must be a simpler way to do it, so I don't want to try comparable interfaces. Maybe something like a method in the class file and then a call from the driver file to that method. Can I see some code?

Here is my updated code:
/* class name*/
public class Driver
{
      public static void main(String[] args)
      {      
            Driver record1 = new Driver();
            Driver record2 = new Driver();
            int startingAmount1, startingAmount2, count;
            double percentChange;
            boolean areEqual;
                                                      
            record1.readInput();
            record2.readInput();
                                    
            startingAmount1 = record1.inventoryAmount;
            System.out.println ("\tSTATISTICAL                         RESULTS");
            System.out.println ("Delinquent Customers =                   " +  startingAmount1);
            startingAmount2 = record2.inventoryAmount;
            System.out.println ("Non-Delinquent                         Customers = " +  startingAmount2);
                  
            if (record1.largerInventoryThan(record2))
            System.out.println(record1.getName() + " has             the larger quantity.");
            else
            System.out.println(record2.getName() + " has             the larger quantity.");
                        
      }       
}                        
      




      
Can someone please make some suggestions?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@ CEHJ
It looks like your reference to "startingAmount1 = record1.inventoryAmount(numberOfYears);" is meant to call the method, which I am already doing as shown in my posted code. Am I wrong with this assessment about your suggestion.

My driver currently compiles OK, but the method posted above doesn't do these two things: (1) increment the years, and (2) I don't know how to setup the condition that stops the iteration. Again, what I'm doing is comparing GroupA to GroupB (or vice versa) and when one surpasses the other I want to output the year in which that occurs. I know how to state this in pseudocode, but not how to put it in a loop.

Is it possible that you could look at the above method and make a suggestion about how that could be changed to accomplish these two goals?
Can some please make some suggestions? Is there additional data I should provide?
I was thinking maybe I could use the variable count for the parameter in the method call to inventoryAmount and use a while loop to increment count. Any help on how to setup the while loop would be appreciated.
:-)

Hope you're OK now. Was away for a while