I am making a program of vehicles and i have to make a car garage class. In the class the max amount of vehicles that could enter are 20 or 25000 lbs. I wrote the charstack and the pop() and the push() but dont know how to limit it to 20 vehicles or 25000 lbs. Could someone help with this. Also, I have a problem with the vehicle interface in my program. other classes come with an error so I threw an exception but we are supposed to add code to the classes to make them compile.

package saturn;
import java.util.Stack;

public class Saturn {
interface Domestic {}
interface Import {}
interface Japanese extends Import {}
interface German extends Import {}
interface Detroit extends Domestic {}
interface SpringHill extends Domestic {}

interface Vehicle 
{
    int getWeightInPounds(double Automobile, double LargeAutomobile );
        double Automobile = 1000;
        double LargeAutomobile = 2500;
}
interface Automobile extends Vehicle {}
interface LargeAutomobile extends Vehicle {}
interface Sedan extends Automobile {}
interface Van extends LargeAutomobile {}
interface Truck extends LargeAutomobile {}
interface Compact extends Automobile {}
interface SportsUtilityVehicle extends Truck, Van {}
    
class SaturnSL1 implements SpringHill, Sedan // All of this is the spot where there is a compile error.
{

        @Override
        public int getWeightInPounds(double Automobile, double LargeAutomobile) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
class HondaCivic implements Japanese, Compact 
{

        @Override
        public int getWeightInPounds(double Automobile, double LargeAutomobile) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
class MercedesC230 implements German, Sedan 
{

        @Override
        public int getWeightInPounds(double Automobile, double LargeAutomobile) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
class ChevyS10 implements Detroit, Truck 
{

        @Override
        public int getWeightInPounds(double Automobile, double LargeAutomobile) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
class SubaruOutback implements Japanese, SportsUtilityVehicle 
{

        @Override
        public int getWeightInPounds(double Automobile, double LargeAutomobile) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }

    public static void main(String[] args) 
    {   
         class ParkingGarage
         {
             private Stack vehiclesInGarage; 
             
             ParkingGarage()
             {
                vehiclesInGarage = new Stack();
             }
             
             public char peek()
             {
                 Character temp = (Character) vehiclesInGarage.peek();
                 return temp.charValue();
             }
             
             public void push( char vehicle)
             {
                 vehiclesInGarage.push(new Character(vehicle));
             }
             
             public char pop() 
             {
                 Character temp = (Character) vehiclesInGarage.pop();
                 return temp.charValue();
             }
             
             public boolean empty()
             {
                 return vehiclesInGarage.empty();
             }
         }
    }
}

You need to go through a Java tutorial. Couple things from a glance:

Each class/interface needs to defined in its own JAVA file, with the same name. For instance, SaturnSL1 must be in a file called SaturnSL1.java.

You should be declaring the ParkingGarage class outside of the main method().

Member Avatar for hfx642

You have to keep track of two things.
a) The number of vehicles in the stack
b) The total weight of the vehicles in the stack
When you push()/pop(), add/subtract your count/weight.
BEFORE you push()/pop(), check for your upper/lower limits.
You can't pop() when you have 0 elements.
You can't push() when you have 20 elements,
or if the added weight of the new vehicle will be over your weight limit.

first of all i think you need to understand the concept of overflow and underflow. These two will help you understand your problem, before you push() or pop() you have to use a condition to check the number of vehicles in a stack as well as the the total wight.For more information on this problem get any book of DATA STRUCTURE AND ALGORITHMS, it will explain in details. Sory i didn't have time to write the code for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.