Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- public class carShop {
- Car[] cars;
- int capacity;
- carShop(int capacity){
- cars = new Car[capacity];
- }
- boolean addCar(Car car){
- if(this.capacity > 0){
- this.cars[capacity-1] = car;
- this.capacity--;
- return true;
- }
- else{
- return false;
- }
- }
- Car getNextCar(){
- return cars[capacity];
- }
- void sellNextCar(Person buyer){
- buyer.car = this.cars[capacity];
- }
- boolean removeCar(Car car){
- this.cars[capacity] = null;
- return true;
- }
- void showAllCarsInTheShop(){
- for (int i = 0; i < cars.length; i++) {
- if(cars[i] != null){
- System.out.println(cars[i].model);
- System.out.println(cars[i].price);
- System.out.println(cars[i].color);
- System.out.println(cars[i].isSportCar);
- System.out.println(cars[i].maxSpeed);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement