java - Tracking how many cars are rented and available in a Class -


i've been having trouble code. assignment java class.its past due i'm going nuts trying figure out problem.

problem:

when upload wileyplus(automatic correcting server), keeps saying when 'int n = 14' it's expecting result "24 , 15", "23, 16". however, when enter 12 expected, "7,5". can't seem find what's causing this.

with code, make more sense.

public class rentalcar {     private boolean rented;     private static int availablecars = 0;     private static int rentedcars = 0;      public rentalcar() {         availablecars++;         rented = false;     }      public static int numavailable() {         return availablecars;     }      public static int numrented() {         return rentedcars;     }      public boolean rentcar() {         availablecars--;         rentedcars++;         rented = true;         return rented;     }      public boolean returncar() {         if (rented) {             availablecars++;             rentedcars--;             rented = false;         }          return false;     }      public static string check(int n) {         rentalcar[] cars = new rentalcar[n];         (int = 0; < n; i++) {             cars[i] = new rentalcar();         }          (int = 0; < n; = + 2) {             cars[i].rentcar();         }          (int = 0; < n; = + 3) {             cars[i].rentcar();         }          (int = 0; < n; = + 4) {             cars[i].returncar();         }          return rentalcar.numrented() + " " + rentalcar.numavailable();     } } 

in returncar() check, if car trying return rented. in rentcar() don't that. seems can rent car that's rented. try prevent renting cars rented.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -