HELP! JAVA CLASS, QUEUES And Scanners

+3 Jacob Fellows · December 6, 2014
Hi there,
I'm struggling with my assignment on queues that is to create a program that creates a print queue and am allowed to use any method such as a linked list, dequeue or the queue<E> function. I would rather use the queue function as it seems simple.
I have attached the java class code I have done so far and I am learning to use these code boxes as well.

The java class code:
package bobsyouruncleassignment2;
import java.util.*;
/**
 *
 * @author Jacob
 */
public class DeQueCode
{ //Start of class
    int fileSize;
    private String fileName;
    private String userID;
    private UUID printerID;
   
    /**
    *This is the constructor of the JavaDoc for my program
    * It is used to create a new print job.
    *@param fileSize is the file size
    *@param fileName is the file name
    *@param userID is the user Identification
    * @param printerID is the identification for the printer
    */
    public DeQueCode(int fileSize, String fileName, String userID, UUID printerID)
    { //The word *this.* means set the value in the instance of a print job
        this.fileSize = fileSize;
        this.fileName = fileName;
        this.userID = userID;
        this.printerID = printerID;
    } //End of the constructor
   
    //------------------------------------------------------------------------------
    //Now to the methods that are going to be used in my program
    //------------------------------------------------------------------------------
   
    //Starting with the getters
    /**
     * Gets the file name
     */
    public int getFileSize()
    {
        return this.fileSize;
    }
   
    /**
     * Gets the last name
     */
      public String getFileName()
    {
        return this.fileName;
    }
     
    /**
     * Gets the telephone number
     */
        public String getUserID()
    {
        return this.userID;
    }
   
        /*
        *Gets the printer ID.
        */
        public UUID getPrinterID()
        {
            return this.printerID;
        }
       
        //Now the setters
        /**
         * Sets the print job for the file size
         * @param fs file size of the print job
         */
       
    public void setFileSize (int fs)
    {
        this.fileSize = fs;
    }
   
        /**
         * Sets the print job for the file name
         * @param fn file name of print job
         */
       public void setFileName (String fn)
    {
        this.fileName = fn;
    }
      
        /**
         * Sets the print jobs user name
         * @param ui user ID for the print job
         */
       public void setUserID (String ui)
    {
        this.userID = ui;
    }
       /**
        * Sets the print job a random printer ID
        * @param
        */
       public void setPrinterID (UUID pi)
       {
           this.printerID = pi;
       }
      
       //Finally the toString method to show all the print jobs info
       @Override
     public String toString()
     {
         return ("File sizee: " + fileSize + "\n"
                 + "File name:" + fileName + "\n"
                 + "User ID: " + userID + "\n"
                 + "Printer ID: " + printerID);
     }
            
} //End of class


I would like to then make the program itself have a few option choices such as the code below that will go along with the above.
    public static void main(String[] args) {
       
    Queue q = new Queue(); //Queue of size 5
    int ch;
    Scanner sc =new Scanner(System.in);
    do
    {
    System.out.println("Menu\n1.insert\n2,delete\n3.display\n4.destroy\n5.exit\n");
    System.out.println("Enter choice :");
    ch=sc.nextInt();
    switch(ch)
    {
        case 1:
            System.out.println("Enter data to insert");
        int x=sc.nextInt();
        q.insert(x);
        break;
        case 2:
            if(q.empty())
            System.out.println("Queue underflow");
            else
            {
                int z =q.delete();
                System.out.println("data deleted =" + z );
            }
            break;
        case 3: q.display();
            break;
        case 4: q.destroy();
            break;
        case 5: break;
        default : System.out.println("Wrong Choice");
    }
    }while(ch!=5);
    }
   
}

Please help and all the help is greatly appreciated from you guys as you seem to know stuff better than I do and I would love to become part of your java crew.
Thanks again,
Jacob.
P.S If you do help me Santa will be very happy with you this year! :) LOL

Post a Reply

Replies

- page 3
Oldest  Newest  Rating
0 Jacob Fellows · December 7, 2014
Hi there,

The program is meant to be a print job queue that gets input via a scanner from the user and then puts it into an array queue that you can then delete the head of the queue and add to the end of the queue. Thanks for pointing out the scanner close thing and should I change it to print instead of println?

Thanks,
Jacob.
P.S Does any of the above make any sense???
0 Developer John · December 8, 2014
Yes it makes sense, I just wanted a clear meaning of what you want it to do, since you said this is what I have so far. I don't think it's necessary to change to print, just delete the \n. Now I understand the whole getting user input part of it and storing the user input in an array, but I don't understand the deletion of the head of the queue and addition of the end of the queue part. Do you mind explaining that to me?

-Thanks!:sideways:
0 Developer John · December 12, 2014
How did it go? I'm guessing not well.:(
0 Developer John · December 8, 2014
Yes, it does help. Thanks for explaining it some more!
0 Jacob Fellows · December 8, 2014
Do you think I will need to use import java.util.queue<E> for the program instead of the array deque because we need to order them and then remove or add to the queue. A queue is a type of data structure that you can use and I need to use it. Also there are no examples of the type of thing I need to do as they all contain ints and no one seems to have the courage to try a class containing strings, ints and UUID (Random generated text for the printer ID

if you hit a wall just let me know.

Java / Android Development

107,307 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator