In: Computer Science
My assignment requires the perfect hashed data structure with about 750 nodes containing information about tickets for the event. The number of the ticket would be the key field, the information nodes will store would be section number, row number, seat number, name and date of the event and purchaser's name. I suppose I need to use HashMap or linkedHashMap for this and create an array or linked list with all these nodes. But I don't know how to create and fill so many nodes, is there any way to make it automatically and how to approach this assignment? It's java data structures and algorithms
Here is Program for Above Problem ::
import java.util.*;
import java.util.Map.Entry;
public class Node {
private int nooftickets;
private int sec_no;
private int row_no;
private int seat_no;
private String name;
private String dateofevent;
private String purchaer_name;
public Node(int nooftickets, int sec_no, int row_no, int seat_no, String name, String dateofevent, String purchaer_name) {
this.nooftickets = nooftickets;
this.sec_no = sec_no;
this.row_no = row_no;
this.seat_no = seat_no;
this.name = name;
this.dateofevent = dateofevent;
this.purchaer_name = purchaer_name;
}
public Node() {
}
public int getNooftickets() {
return nooftickets;
}
public void setNooftickets(int nooftickets) {
this.nooftickets = nooftickets;
}
public int getSec_no() {
return sec_no;
}
public void setSec_no(int sec_no) {
this.sec_no = sec_no;
}
public int getRow_no() {
return row_no;
}
public void setRow_no(int row_no) {
this.row_no = row_no;
}
public int getSeat_no() {
return seat_no;
}
public void setSeat_no(int seat_no) {
this.seat_no = seat_no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDateofevent() {
return dateofevent;
}
public void setDateofevent(String dateofevent) {
this.dateofevent = dateofevent;
}
public String getPurchaer_name() {
return purchaer_name;
}
public void setPurchaer_name(String purchaer_name) {
this.purchaer_name = purchaer_name;
}
}
class Test
{
public static void main(String arp[])
{
Scanner sc=new Scanner(System.in);
HashMap<Integer, Node> h=new HashMap<Integer, Node>();
for(int i=0;i<750;i++)
{
Node n=new Node();
n.setNooftickets(sc.nextInt());
n.setSec_no(sc.nextInt());
n.setRow_no(sc.nextInt());
n.setSeat_no(sc.nextInt());
n.setName(sc.next());
n.setDateofevent(sc.next());
n.setPurchaer_name(sc.next());
h.put(n.getNooftickets(),n);
}
Set<Integer> keys = h.keySet();
Iterator<Integer> it = keys.iterator();
System.out.println("----------------Information of Tickets For The Event----------------------------");
System.out.println();
System.out.println(" No of Tickets "+" Section No "+" Row No "+" Seat No "+" Name "+" Date of Event "+" Purchaer Name ");
while(it.hasNext()){
int x=it.next();
Node p=h.get(x);
System.out.println(p.getNooftickets()+" "+p.getSec_no()+" "+p.getRow_no()+" "+p.getSeat_no()+" "+p.getName()+" "+p.getDateofevent()+" "+p.getPurchaer_name());
}
}
}
Here is Some test cases :
INPUT (ENTER ALL 750 VALUES LIKE THIS) :
i tried with 2.
1 2 1 12 Ram 27-10-2020 Shaym
2 3 2 20 xyz 26-10-2020 abcd
Output :
----------------Information of Tickets For The Event---------------------------- No of Tickets Section No Row No Seat No Name Date of Event Purchaer Name 1 2 1 12 Ram 27-10-2020 Shaym 2 3 2 20 xyz 26-10-2020 abcd