Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i run this code with this input.txt file? 389114 Dan Carte 5 399012 Prio Notim 0 685015 Hons Nohish 3 179318 Diran Egrac

How do i run this code with this input.txt file?

389114 Dan Carte 5 399012 Prio Notim 0 685015 Hons Nohish 3 179318 Diran Egrac 2 284139 Osama Laden 5

POI.java public class POI { private long ID; private String name; private int threatLevel; POI next; public POI(long Id,String name,int tl) { this.ID=Id; this.name=name; this.threatLevel=tl; this.next=null; } public long getID() { return ID; } public void setID(long iD) { ID = iD; } public String getName() { return name; } public void setName(String name) { this.name = name; } public POI getNext() { return next; } public void setNext(POI next) { this.next = next; } public int getThreatLevel() { return threatLevel; } public void setThreat_level(int threat_level) { this.threatLevel = threat_level; } }

import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter;

public class POIList { POI head; int length; public POIList() { head = null; length=0; } public void print() { if (head == null) { System.out.print("empty "); return; } POI node = head; while (node != null) { System.out.println(node.getID()); System.out.println(node.getName()); System.out.println(node.getThreatLevel()); node = node.getNext(); } } public int getLength() { return length; } public void setLength(int length) { this.length = length; } public void insert(long Id,String name,int tl) { POI node = new POI( Id, name,tl); length++ ; if(head == null) { head = node; } else { node.setNext(head); head = node; } } public void search(long ID){ POI node = head; while (node != null) { if(node.getID()==ID){ System.out.println("Found"); System.out.println(node.getID()); System.out.println(node.getName()); System.out.println(node.getThreatLevel()); break; } node = node.getNext(); } } public void insertAtPosition(long Id,String name,int tl, int pos) { POI newNode = new POI( Id, name, tl); POI ptr = head; pos = pos - 1 ; for (int i = 1; i < length; i++) { if (i == pos) { POI temp = ptr.getNext() ; ptr.setNext(newNode); newNode.setNext(temp); break; } ptr = ptr.getNext(); } length++ ; } public void removeByID(long ID) { POI node = head; int i=0; while (node != null) { if(node.getID()==ID && i==0){ head = head.getNext(); length--; break; } else if(node.getID()==ID){ POI temp = node.getNext(); temp = temp.getNext(); node.setNext(temp); length --; break; } node = node.getNext(); } } public void removeAllByTl(int tl) { POI node = head; int i=0; while (node != null) { if(node.getThreatLevel()==tl && i==0){ head = head.getNext(); length--; } else if(node.getThreatLevel()==tl){ POI temp = node.getNext(); temp = temp.getNext(); node.setNext(temp); length --; } node = node.getNext(); }

} public void swap(int pos1,int pos2) { POI node = head; POI newnode1 = null; POI newnode2=null; for(int i=0;i

AnalysePOI.java

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class AnalysePOI { public static void main(String args[]){ Scanner scan = null; try { scan = new Scanner(new File("test.in")); } catch (FileNotFoundException e1) { System.out.println("File not Found"); } /* Creating object of class POIList */ POIList list = new POIList(); while(scan.hasNextLine()){ long ID = scan.nextLong(); String name = scan.nextLine(); int threatLevel = scan.nextInt(); list.insert(ID, name, threatLevel); } scan = new Scanner(System.in); //List Operations System.out.println(" Person Linked List Operations "); System.out.println("1. Print the List"); System.out.println("2. Search a person"); System.out.println("3. Insert at position"); System.out.println("4. Swap records at 2 positions"); System.out.println("5. Remove a record with an ID"); System.out.println("6. Remove all records with a certain threatlevel"); System.out.println("7. Print List to a file"); System.out.println("8. Quit"); int choice = scan.nextInt(); switch (choice) { case 1 : list.print(); break; case 2 : System.out.println("Enter the ID of the person"); list.search( scan.nextInt() ); break; case 3 : System.out.println("Enter the ID,name & threatLevel of the person to insert"); long id = scan.nextInt() ; String name = scan.nextLine(); int tl =scan.nextInt(); System.out.println("Enter position"); int pos = scan.nextInt() ; if (pos <= 1 || pos > list.getLength() ) System.out.println("Invalid position "); else list.insertAtPosition(id,name,tl, pos); break; case 4 : System.out.println("Enter position one"); int p1 = scan.nextInt() ; System.out.println("Enter position two"); int p2 = scan.nextInt() ; if (p1 < 1 || p1 > list.getLength()||p2 < 1 || p2 > list.getLength() ) System.out.println("Invalid position "); else list.swap(p1,p2); break; case 5 : System.out.println("Enter the ID of the person"); list.removeByID( scan.nextInt() ); break; case 6 : System.out.println("Enter the threat level of the person"); list.removeAllByTl( scan.nextInt() ); break; case 7 : try { list.writeToFile(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("File not Found"); } break; case 8 : System.out.println("Enter the threat level of the person"); list.removeAllByTl( scan.nextInt() ); break; default :

system.exit(); break; }

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago

Question

Explain the alkaline nature of aqueous solution of making soda.

Answered: 1 week ago