Question

Question: How can I solve it in "Java program"?, i need test code also.
Define P to be a parking lane i in a parking lot and car; to be the jth car, where the number of lanes in a parking lot is 4

Define Pi to be a parking lane i in a parking lot and carj to be the jth car; where the number of lanes in a parking lot is 4 and there are 7 cars to park. 1<= i<=4, and Cj: 1<=j<=7. Assume that all lanes are of the same length, and all cars are also of the same length, hence, the same number of cars could be lined up in each lane. Only 5 cars can be lined up in each lane. However, different lanes have different lining up rules according to their data structures. The first parking lot lane is an array, the second is a single listed, and the third is a stack.

Parking lot line - Structure

P1 - Array

P2 - Single Linked List

P3 - Stack

When a car arrives to the parking lot, the valet parking lot staff insert the car in one of lanes. However, customers may also ask the staff to get their cars back later. Keep in mind that any (inserting/ removing) operation (corresponding to moving any car into or out of any lanes) cost 1 KD.

Test the program on each data structure using the following Insert operations.

lane operation - Car Number

Insert - C1

Insert - C4

Remove - C1

Insert - C5

Insert - C7

Insert - C3

Insert - C2

Remove - C2

Insert - C1

Remove - C7

Insert - C6

Remove - C1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

So basically here we want a class to have three structures array,single LinkedList and a stack.we want insert and remove operations on each.lets concentrate on this part:

importjava.util.*;

class Stack{

private :

int arr[];

int top;

int capacity;

Stack(int size)

{

art=new int[size];

capacity=size;

top=-1;

}

public void push(int x)

{

if(isFull()){

System.out.println("Parking full); System.exit(1);}

System.out.println("Inserting"+x);

arr[++top]=x;

}

public int pop(){

if(isEmpty()) System.out.println("Empty');System.exit(1);

System.out.orintln("Removing")+perk());

return arr[top--];}

public int peek(){

if(!isEmpty()) return art[top]; else System.exit(1);return -1}

public int size(){return top+1;}

public Boolean isEmpty(){return top=-1;}

public Boolean isFull(){return top=capacity-1;}

}

class SinglyLInkList

{.

int data;

Node next;

Node(int d){data=d;next=null;}

public void pushkal(int new_data){

Node newnode=new Node(new_data)

newnode.next=head;head=newnode;}

void deleteNode(int pos){if(head==null) return; Node temp=head; if(pos==0){head=temp.next; return; }for(int i=0;temp!=null && i<pos-1;i++) temp=temp.next; Node next =temp.next.next;temp.next=next;

}

class Array{

static int ind( int ar[],int n,int key){.

for(int I=0;I<n; I++) if(art[I]==key) return i; return -1}

static int insert(int ar[],int key,int capacity,int n){

if(n>capacity) return n;

ar[n]=key; return n+1;

}

}

class Main{

public static void main (String[] args){

//Implement all the three classes in this for Inserting and Removing elements using condition al loops.

}

}

Hope this helps.Kindly compile for typing error

add Your code in Main .

Regards.

Add a comment
Know the answer?
Add Answer to:
Question: How can I solve it in "Java program"?, i need test code also. Define Pi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This...

    PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This is the input: JAV001 ARRIVE JAV002 ARRIVE JAV003 ARRIVE JAV004 ARRIVE JAV005 ARRIVE JAV001 DEPART JAV004 DEPART JAV006 ARRIVE JAV007 ARRIVE JAV008 ARRIVE JAV009 ARRIVE JAV010 ARRIVE JAV011 ARRIVE JAV012 ARRIVE JAV013 ARRIVE JAV014 ARRIVE JAV006 DEPART JAV014 DEPART JAV013 DEPART JAV005 DEPART JAV015 ARRIVE JAV010 DEPART JAV002 DEPART JAV015 DEPART JAV014 DEPART JAV009 DEPART JAV003 DEPART JAV008 DEPART JAV007 DEPART JAV012 DEPART JAV011...

  • Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car...

    Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...

  • Can someone help me get started on this question? I am not sure where to begin...

    Can someone help me get started on this question? I am not sure where to begin here. Thank you! Question B: Car traffic arrives at a large toll plaza at different rates depending on the time of day. The rate (in cars-per-hour) at time "t" is r(t) = 5000*(1 - 0.8cos(2 pit/24)) for t measured in hours between 0 and 24. i) Define A(T) = the # of cars that have arrived by time "T". Find a formula for A(T)....

  • This program needs to be in JAVA language. Also, I need to create my own LinkedList...

    This program needs to be in JAVA language. Also, I need to create my own LinkedList class, I can not use the Java LinkedList Library. Please read all aspects of the program, it needs to display 200 random numbers that are 5 digits long sorted from smallest to largest. I can not use Collection(s) or packages libraries. Should only need: import java.util.Random; import java.util.Scanner; Please provide output screenshots after the code. Thank you! You are going to create a Linked...

  • I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

    I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas. Part II: PA3: Car Dealership (40 points) For Programming Assignment 3 you will be creating a program to...

  • JAVA: Already completed: MyList.java, MyAbstractList.java, MyArrayList.java, MyLinkedLink.java, MyStack.java, MyQueue.java. Need to complete: ReversePoem.java. This program has...

    JAVA: Already completed: MyList.java, MyAbstractList.java, MyArrayList.java, MyLinkedLink.java, MyStack.java, MyQueue.java. Need to complete: ReversePoem.java. This program has you display a pessimistic poem from a list of phrases. Next, this program has you reverse the phrases to find another more optimistic poem. Use the following algorithm. 1.   You are given a list of phrases each ending with a pound sign: ‘#’. 2.   Create a single String object from this list. 3.   Then, split the String of phrases into an array of phrases...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • /*hello everyone. my question is mostly related to the garagetest part of this assignment that i've...

    /*hello everyone. my question is mostly related to the garagetest part of this assignment that i've been working on. i am not sure how to read the file's contents AND put them into variables/an array. should it be in an arraylist? or maybe a regular array? or no arrays at all? i am also not sure how to call the factory method from garagec. i'm thinking something along the lines of [Garage garage = new GarageC.getInstance("GarageC", numFloors, areaofEachFloor);] but i...

  • code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation...

    code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...

  • I need help with this C code Can you explain line by line? Also can you...

    I need help with this C code Can you explain line by line? Also can you explain to me the flow of the code, like the flow of how the compiler reads it. I need to present this and I want to make sure I understand every single line of it. Thank you! /* * Converts measurements given in one unit to any other unit of the same * category that is listed in the database file, units.txt. * Handles...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT