堆栈和队列渡轮模拟器

时间:2015-10-21 23:13:07

标签: java stack queue

我正在制作渡轮模拟器,我有一个有效的stackqueue课程,但我正在尝试为渡轮课程清理我的代码。有关如何做到这一点的任何想法?我还试图了解如何展示完整的stackqueue

这就是我所拥有的:

import java.util.Scanner;

public class Ferry {

    static Stack ferry1 = new Stack();
    static Queue ferry2 = new Queue();
    Stack ferryStack = new Stack();
    static int car1, car2, car3, car4, car5, car6, car7, car8, car9, car10, car11, car12, car13, car14, car15, car16, car17, car18, car19, car20;
    static int getTag(){

        Scanner tag = new Scanner(System.in);
        int carID;

        System.out.print("Enter in a tag number.");
        carID = tag.nextInt();
        return carID;
    }
    public static Queue ferry2Loading(){
        car1 = getTag();
        car2 = getTag();
        car3 = getTag();
        car4 = getTag();
        car5 = getTag();
        car6 = getTag();
        car7 = getTag();
        car8 = getTag();
        car9 = getTag();
        car10 = getTag();
        car11 = getTag();
        car12 = getTag();
        car13 = getTag();
        car14 = getTag();
        car15 = getTag();
        car16 = getTag();
        car17 = getTag();
        car18 = getTag();
        car19 = getTag();
        car20 = getTag();

        ferry2.queuePush("car1");
        ferry2.queuePush("car2");
        ferry2.queuePush("car3");
        ferry2.queuePush("car4");
        ferry2.queuePush("car5");
        ferry2.queuePush("car6");
        ferry2.queuePush("car7");
        ferry2.queuePush("car8");
        ferry2.queuePush("car9");
        ferry2.queuePush("car10");
        ferry2.queuePush("car11");
        ferry2.queuePush("car12");
        ferry2.queuePush("car13");
        ferry2.queuePush("car14");
        ferry2.queuePush("car15");
        ferry2.queuePush("car16");
        ferry2.queuePush("car17");
        ferry2.queuePush("car18");
        ferry2.queuePush("car19");
        ferry2.queuePush("car20");
         return ferry2;
    }
    public static Stack ferry1Loading(){
        car1 = getTag();
        car2 = getTag();
        car3 = getTag();
        car4 = getTag();
        car5 = getTag();
        car6 = getTag();
        car7 = getTag();
        car8 = getTag();
        car9 = getTag();
        car10 = getTag();
        car11 = getTag();
        car12 = getTag();
        car13 = getTag();
        car14 = getTag();
        car15 = getTag();
        car16 = getTag();
        car17 = getTag();
        car18 = getTag();
        car19 = getTag();
        car20 = getTag();

        ferry1.stackPush(car1);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car2);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car3);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car4);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car5);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car6);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car7);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car8);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car9);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car10);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car11);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car12);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car13);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car14);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car15);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car16);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car17);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car18);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car19);
        System.out.println(ferry1.stackPeek());
        ferry1.stackPush(car20);
        System.out.println(ferry1.stackPeek());

        return ferry1;
    }

public static void main(String args[]){

    ferry1Loading();
    ferry2Loading();    
    //System.out.println("CARS ON THE FERRY "+ferry1+"");
        //ferry1.push("s5gsg");

//      
//      Stack ferryStack = new Stack(20);
//      System.out.println(ferryStack.peek());
//      ferryStack.push("2b");
//      System.out.println(ferryStack.peek());
//      ferryStack.push("665sg");
//      System.out.println(ferryStack.peek());
//      ferryStack.push("12sgs");
//      System.out.println(ferryStack.peek());
//      ferryStack.push("3sgsg2");
//      System.out.println(ferryStack.peek());
//      ferryStack.pop();
//      ferryStack.push("2sg0");
//      System.out.println(ferryStack.peek());

    }
}

0 个答案:

没有答案