1

Question: How can I solve it in "Java program"?, i need test code also. Define Pi...

Question

Question: How can I solve it in "Java program"?, i need test code also. Define Pi...

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

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 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 cach 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 Array Single Linked List 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 Insert Remove Insert Insert Insert Insert Remove Insert Remove Insert Remove 8 do 0000000000

Answers

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.


Similar Solved Questions

1 answers
Help Seve&Exit Submit Check my work QS 21-19B Variable costing income statement LO P5 Aces Inc.,...
Help Seve&Exit Submit Check my work QS 21-19B Variable costing income statement LO P5 Aces Inc., a manufacturer of t ennis rackets, began operations this year. The company produced 6.200 rackets and sold 5,100 Each racket was sold at a price of $92. Fixed overhead costs are $81,840, and fixed se...
1 answers
Starts from rest and at +2.01 m/s? for 7.25 s. At the end of this time,...
starts from rest and at +2.01 m/s? for 7.25 s. At the end of this time, the boat 6.10 s with an this, the boat accelerates at -1.49 m/s? for 7.80 What is the velocity of the boat att 21.15 s m/s (b) Find the total displacement of the boat...
1 answers
Construct a cumulative frequency distribution of the 20 brain volumes(cm3) listed below. Use the classes 900-999,...
Construct a cumulative frequency distribution of the 20 brain volumes(cm3) listed below. Use the classes 900-999, 1000-1099, and so on. (6-classes) 1005   963 1035 1027 1281 1272 1051 1079 1034 1070 1173 1079 1067 1104 1347 1439 1029 1100 1204 1160.Also find relative frequency for each cl...
1 answers
P2.7-1 Ammeter 11 455 V Voltmeter 4? 18v ( Determine the value of r, the gain...
P2.7-1 Ammeter 11 455 V Voltmeter 4? 18v ( Determine the value of r, the gain of the CCvS in this circuit: the tolerance is +7.2% .corned gen/shared/assignment/test/agist un?idsasnmt22076 55#N1008C...
1 answers
5. There are 12 people on a basketball team, and the coach needs to choose 5...
5. There are 12 people on a basketball team, and the coach needs to choose 5 to put into a game. How many different possible ways can the coach choose a team of 5 if each person has an equal chance of being selected? (1) 12Ps (3) 12Cs (2) sP12 4) sCi2...
1 answers
A very long, straight wire carries a constant current.
A very long, straight wire carries a constant current. The magnetic field a distance d from the wire and far from its ends varies with distance d according toA) d^-3B) dC) d^2D) d^-1E) d^-2...
1 answers
Two pyramids are similar. Pyramid A has a volume of 32m^3 and with a surface area of 100m^2 while Pyramid B has a volume of 500m^3 and is 60m tall. What is the height of Pyramid A? What is the surface area of Pyramid B?
Two pyramids are similar. Pyramid A has a volume of 32m^3 and with a surface area of 100m^2 while Pyramid B has a volume of 500m^3 and is 60m tall. What is the height of Pyramid A? What is the surface area of Pyramid B?...
1 answers
Type your answer in the box. Two capital budgeting approaches that use discounted cash flows are...
Type your answer in the box. Two capital budgeting approaches that use discounted cash flows are the value method and the return method. (Enter only one word per blank.) When the cash flows associated with an investment project change from year to year, the payback period must be calculated: Click t...
1 answers
With explanation please Question 18 O out of 1.5 points During 2019, Hadley Merchandising Company purchased...
With explanation please Question 18 O out of 1.5 points During 2019, Hadley Merchandising Company purchased $34,843 of inventory on account. Hadley sold inventory on account that cost $19,854 for $35,089. Cash payments on accounts payable were $21,685. There was $26,756 cash collected from accounts ...
2 answers
How many isomers can a formula of #C_4H_10O# generate?
How many isomers can a formula of #C_4H_10O# generate?...
1 answers
Homework help question 9 multiple choice .Boost 1:58 PM 1 39% < Back Econ 2 -...
homework help question 9 multiple choice .Boost 1:58 PM 1 39% < Back Econ 2 - Final... a @ best explain the Which of the following changes in the electricitymarket ice of electricity! An increase in demand and a decrease in pply Ademain demand and supply As b e demand supply Ademain both deman...
1 answers
S Content Assessments Communication v Resources Library DesignTutoring ime Left:0:36:45 Nacori Dial: Attempt 1 Question 12...
s Content Assessments Communication v Resources Library DesignTutoring ime Left:0:36:45 Nacori Dial: Attempt 1 Question 12 (8 points) E Alexander Litvinenko was poisoned with 10 micrograms of the radioactive substa Polonium-210. determine the amount of substance left in Alexander Litvinenko's bo...
1 answers
Total The direct labor information for the production of 8.160 units of each product is as...
Total The direct labor information for the production of 8.160 units of each product is as follows: Department Assembly Test and Pack Blender 675 dlh 2.440 din Toaster oven 2,265 815 Total 2,940 dih 3,255 dih Four Finger Appliance used direct labor hours to allocate production department factory ove...
1 answers
Newhard Company assigns overhead cost to jobs on the basis of 119% of direct labor cost....
Newhard Company assigns overhead cost to jobs on the basis of 119% of direct labor cost. The job cost sheet for Job 313 includes $20,343 in direct materials cost and $10,300 in direct labor cost. A total of 1,300 units were produced in Job 313. Required: a. What is the total manufacturing cost assig...
1 answers
Ww Dong 7. This family has members who suffer from a rare disorder (abbreviated PMĚ) that...
ww Dong 7. This family has members who suffer from a rare disorder (abbreviated PMĚ) that presents with action myoclonus, and progressive neurological decline. (6 pts) Figure 1. Family pedigree and magnetic resonance imaging. (A) The six-generation family showing segregation of PME and ataxia. ...

-- 0.011616--