Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package main;
  2.  
  3. public class carShop {
  4.  
  5. Car[] cars;
  6. int capacity;
  7.  
  8. carShop(int capacity){
  9. cars = new Car[capacity];
  10. }
  11.  
  12. boolean addCar(Car car){
  13. if(this.capacity > 0){
  14. this.cars[capacity-1] = car;
  15. this.capacity--;
  16. return true;
  17.  
  18. }
  19. else{
  20. return false;
  21. }
  22. }
  23. Car getNextCar(){
  24. return cars[capacity];
  25. }
  26.  
  27. void sellNextCar(Person buyer){
  28. buyer.car = this.cars[capacity];
  29. }
  30. boolean removeCar(Car car){
  31. this.cars[capacity] = null;
  32. return true;
  33. }
  34. void showAllCarsInTheShop(){
  35. for (int i = 0; i < cars.length; i++) {
  36. if(cars[i] != null){
  37. System.out.println(cars[i].model);
  38. System.out.println(cars[i].price);
  39. System.out.println(cars[i].color);
  40. System.out.println(cars[i].isSportCar);
  41. System.out.println(cars[i].maxSpeed);
  42. }
  43.  
  44. }
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement