Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assming your program has a linked list class with the standard linked list metho

ID: 3801496 • Letter: A

Question

Assming your program has a linked list class with the standard linked list methods. Your program will create a list of patient objects and provide the user with a menu of
choices for accessing and manipulating the data on that list. At the start, your program should read in patient data
from a text file for an initial set of patients for the list. The name of this file should be
included on the “command line” when the program is run. (Don’t hard code the file name)
Each data item for a patient will appear on a separate line in the file. Your program
should be menu-driven, meaning that it will display a menu of options for the user. The
user will choose one of these options, and your program will carry out the request. The
program will then display the same menu again and get another choice from the user.
This interaction will go on until the user chooses QUIT, which should be the last of the
menu’s options. The menu should look something like the following:
1. Display list
2. Add a new patient
3. Show information for a patient
4. Delete a patient
5. Show average patient age
6. Show information for the youngest patient
7. Show notification list
8. Quit
Enter your choice:
Details of each option:
• Option 1: Display (on the screen) the names and patient id #’s of all patients in
order starting from the first one. Display the information for one patient per line;
something like: Susan Smith, 017629
• Option 2: Add a new patient to the END of the list. All information about the new
patient (including name, patient id #, etc.) is to be requested (input) from the user
interactively. That is, you will need to ask for 14 pieces of data from the user.
You’ll, of course, need to create a new patient object to hold this data.
NOTE: As mentioned above, the patient id # field is a key. So, if the user types in
a patient id # that happens to be the same as an already existing patient’s, then
you should display an error message and cancel the operation. Therefore, it is
probably a good idea to ask for the patient id # first and test it immediately (by
scanning the objects on the list).
• Option 3: Display (in a neat format) all the information pertaining to the patient
whose patient id # is given by the user. Namely, display the following information:
o name
o patient id # o address
o height (shown in feet and inches; for example, 5 ft, 10 in)
o weight
o age
o number of years as a patient (display “less than one year” if 0)
o number of years since last visit (display “less than one year” if 0)
o Indication that patient is overdue for a visit
NOTE: The last item is displayed only if it has been 3 or more years since
the patient’s last visit.
If the user inputs a patient id # that does not exist, then the program should
display an error message and the operation should be canceled (with the menu
immediately being displayed again for another request).
• Option 4: Delete the patient whose id # is given by the user. If the patient is not
on the list, display an error message.
• Option 5: Show the average age (to one decimal place) of the patients.
• Option 6: Display (in a neat format) all the information (same as operation 3)
about the youngest patient.
• Option 7: Display the names (and patient id #’s) of all patients who are overdue
for a visit. As noted above, “overdue” is defined as 3 or more years since the last
visit.
• Option 8: Quit the program.
NOTE: When the user chooses to quit, you should ask if they would like to save
the patient information to a file. If so, then you should prompt for the name of an
output (text) file, and then write the data pertaining to all patients to that file. The
output for each patient should be in the same format as in the input file. In this
way, your output file can be used as input on another run of your program.

Explanation / Answer


import java.util.Scanner;
class linkedlistnode
{
protected int data;
protected Node link;

  
public Node()
{
link = null;
data = 0;
}

public Node(int d,Node n)
{
data = d;
link = l;
}

public void setLink(Node l)
{
link = l;
}
public void setData(int d)
{
data = d;
}

public Node getLink()
{
return link;
}
  
  
}

class linkedList
{
protected Node start;
protected Node quit ;
public int size1 ;


public linkedList()
{
start = null;
quit = null;
size1 = 0;
}
  
public boolean isEmpty()
{
return start == null;
}
  
public int getSize1()
{
return size1;
}

public void insertAtStart(int val)
{
Node nptr = new Node(val, null);
size1++ ;
if(start == null)
{
start = nptr;
end = start;
}
else
{
nptr.setLink(start);
start = nptr;
}
}
public void insertAtEnd(int val)
{
Node nptr = new Node(val,null);
size++ ;
if(start == null)
{
start = nptr;
quit = start;
}
else
{
end.setLink(nptr);
end = nptr;
}
}
public void insertAtPos(int val , int pos)
{
Node nptr = new Node(val, null);
Node ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size; i++)
{
if (i == pos)
{
Node tmp = ptr.getLink() ;
ptr.setLink(nptr);
nptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size1++ ;
}

public void deleteAtPos(int pos)
{
if (pos == 1)
{
start = start.getLink();
size1--;
return ;
}
if (pos == size1)
{
Node s = start;
Node t = start;
while (s != quit)
{
t = s;
s = s.getLink();
}
quit = q;
end.setLink(null);
size1 --;
return;
}
Node ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == pos)
{
Node tmp = ptr.getLink();
tmp = tmp.getLink();
ptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size1-- ;
}

public void display()
{
System.out.println("Singly Linked List = ");
if (size == 0)
{
System.out.println("empty");
return;
}
if (start.getLink() == null)
{
System.out.println(start.getData() );
return;
}
Node ptr = start;
System.out.println(start.getData()+ "->");
ptr = start.getLink();
while (ptr.getLink() != null)
{
System.out.print(ptr.getData()+ "->");
ptr = ptr.getLink();
}
System.out.print(ptr.getData()+ " ");
}
}

public class linkedlist
{
public static void main(String[] args)
{   
Scanner scan = new Scanner(System.in);
  
linkedList list = new linkedList();
System.out.println("Linked List Test ");
char ch;
  
do
{
System.out.println("List of Operations");
System.out.println("A. insert at start");
System.out.println("B. insert at quit");
System.out.println("C. insert at place");
System.out.println("D. delete at place");
System.out.println("E. check empty");
int choice = scan.nextInt();
switch (choice)
{
case A :
System.out.println("Enter element to insert");
list.insertAtStart( scan.nextInt() );   
break;
case B:
System.out.println("Enter element to insert");
list.insertAtEnd( scan.nextInt() );   
break;   
case C :
System.out.println("Enter integer element to insert");
int num = scan.nextInt() ;
System.out.println("Enter place");
int pos = scan.nextInt() ;
if (pos <= 1 || pos > list.getSize1() )
System.out.println("Invalid place");
else
list.insertAtPla(num, pla);
break;
case D :
System.out.println("Enter place");
int p = scan.nextInt() ;
if (p < 1 || p > list.getSize() )
System.out.println("Invalid place");
else
list.deleteAtPla(p);
break;
case E :
System.out.println("Empty = "+ list.isEmpty());
break;   

default :
System.out.println("Wrong Entry ");
break;   
}
list.display();
System.out.println("Do you want to continue (Type yes or no) ");
ch = scan.next().charAt(0);
} while (ch == 'Yes'|| ch == 'yes');   
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote