Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:43:28+00:00 2026-06-12T22:43:28+00:00

Basically, I want to do something like this: patientReference = ((Patient) TreatmentRoomQueue).peekFront(); But my

  • 0

Basically, I want to do something like this:

patientReference = ((Patient) TreatmentRoomQueue).peekFront();

But my IDE claims the types are inconvertible. (required: Patient; found: TreatmentRoomQueue<Patient>). You can see that I’m attempting to cast the Node as a Patient object and that I am attempting to call my peekFront method that should return the first node in the list. It is however apparent that this is illegal. My syntax could be wrong, or maybe I’m just approaching this the wrong way.

My motivation behind this is that I have a program for running a (fictional) Emergency Room. I need to get someone from my TreatmentRoomQueue, discharge them, and then, if someone is in my WaitingRoomQueue, move them to the Treatment Room. I am not using the Java built in LinkedList class, I am using my own linked list (which I have used previously and know it works).

I could just say screw it and used an array instead of a linked list, but since linked lists are a bit harder for me to understand, I think there’s more to be learned from a linked list implementation.

Any pointers, code snippets, advice, or whatever would be greatly appreciated! Thanks for reading.

I declare TreatmentRoomQueue in my Main class this way:

TreatmentRoomQueue<Patient> TreatmentRoomQueue = new TreatmentRoomQueue();

Here’s the code for TreatmentRoomQueue:

public class TreatmentRoomQueue <ClassType> 
{
    private Node frontQueueNodeRef = null;
    private Node backQueueNodeRef = null;
    private int counter = 0;

    private class Node 
    {
      private ClassType classTypeObjectRef;
      private Node nextNodeRef;
      Node(ClassType newClassTypeObjectRef)
      {
          classTypeObjectRef = newClassTypeObjectRef;
      }
    }

    private Node peekFront()
    {
        return frontQueueNodeRef;
    }

    public void enqueue(ClassType enqueueObjectRef) 
    {            
     Node queueNodeRef = new Node(enqueueObjectRef);
     if (frontQueueNodeRef == null)
     {
         frontQueueNodeRef = backQueueNodeRef = queueNodeRef;
     }
     else {
         backQueueNodeRef.nextNodeRef = queueNodeRef;
         backQueueNodeRef = queueNodeRef;
         counter++;
     }

    }

    public ClassType dequeue() 
    {
    if ( frontQueueNodeRef == null )
    {
        return null;
    } else {
    ClassType firstClassTypeObjectRef = frontQueueNodeRef.classTypeObjectRef;
    frontQueueNodeRef = frontQueueNodeRef.nextNodeRef;
    counter--;
    return firstClassTypeObjectRef;
    }
    }

    public boolean isFull()
    {
        return false;
    }

    public boolean isEmpty()
    {
        return frontQueueNodeRef == null;
    }     
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:43:30+00:00Added an answer on June 12, 2026 at 10:43 pm

    First, you are casting the list, not the element that you get from it. All you need to do is moving the parentheses to the right place:

    patientReference = (Patient) (TreatmentRoomQueue.peekFront());
    

    The way you placed the parentheses, Java tried casting TreatmentRoomQueue to Patient first, and after that attempted to call the peekFront() method on the Patient object.

    Next, you need to make a public method for looking at the front element of your queue: replace your

    private Node peekFront()
    

    method with

    public ClassType peekFront()
    {
        return frontQueueNodeRef.classTypeObjectRef;
    }
    

    Since classTypeObjectRef is private, you should make it public to make it available to peekFront.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I basically want to do something like this: http://jsfiddle.net/bUV6S/1/ ... But I want
Basically, I want to do something like this (in Python, or similar imperative languages):
I just want to ask if anybody has done something like this. Basically, it's
what I want to do is to use something like name=validate[required] basically use it
Basically, I want something like this: Dictionary<object, string> dict = new Dictionary<object, string>(); dict.Add(null,
Basically I want something like this. What are the ready-made options for me? Is
Basically I want to do something like this: $(document).ready(function() { if ($(body).attr(class) === HomePage)
I basically want to create something like this: So, a user can add/remove items
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
I want to have something like this five buttons, one button surrounded by four

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.