+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
     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.out.println("Enter choice :");
        case 1:
            System.out.println("Enter data to insert");
        int x=sc.nextInt();
        case 2:
            System.out.println("Queue underflow");
                int z =q.delete();
                System.out.println("data deleted =" + z );
        case 3: q.display();
        case 4: q.destroy();
        case 5: break;
        default : System.out.println("Wrong Choice");

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,
P.S If you do help me Santa will be very happy with you this year! :) LOL

Post a Reply


- page 2
Oldest  Newest  Rating
0 Developer John · December 9, 2014
Lol, no problem. I usually help people with their code lots of times outside these forums. I'm sorry for saying this, but I don't think it's a great idea copying code. I feel like it's better to make your own unique program so that someone gets ideas from you instead. When I copy someone's code, I feel like I don't know what I'm doing, or I'm just bored lol.:sideways:
0 Jacob Fellows · December 9, 2014
Hi there, I found the code online and wanted to do something similar and wanted to change it to make it function the way I want it too. I struggle with programming and I don't enjoy it because my lecturer seems to be doing things in a very odd order. Such as in my first assignment we were meant to use javadocs comments and I didn't get it and then two weeks ago we learn about it.

Also the code is to be used for a print job. The UUID is a way of creating a unique identifier for the printer ID.

Here is where I got the code from:

I just thought I would change it so that it makes sense for the program in mind. Also I am using the scanner so that it can take inputs and display outputs in the same box.

1. I am not aware of what the ad.set, ad.get or ad.add are.
2. I need to organise the switch to match the block of methods you can do in the program. maybe move them around so that they work good.
3. The Boolean is used as a true or false statement and probably be changed to an if statement or something so that it works. Also if the array is 0 then it means that it is empty and needs data to be inputted from the user.
4. Also in the java class there needs to be a method for adding a instance of the object, setting the head and tail of the array queue, display the array deque with all the values inputted into it and a way to clear the data from the array deque.

Thanks for the help my dude! It boosts my spirits and makes me feel as if I need to do something nice for you.

0 Developer John · December 9, 2014
First off, lets go over the main problems I seen in your code before I can start organizing your request. Are you aware of the errors you get when using your object variable in the switch statement(ad.set(), ad.get(), ad.add())? Secondly, in your switch statement, why do you go from one to six(lol)? Another problem in your code I noticed was that you used a char for the user input. What I suggest is making it a String instead and using:

Lastly, I don't understand your boolean call isEmpty. Why did you return n == 0?

Here is you're code, but a bit more indented lol:

Class DeQue:

import java.util.UUID;

 * @author Jacob
class ArrayDeQue{
  //Start of class

     private int fileSize;
     private String fileName;
     private String userID;
     private UUID printerID;
     private int n;
     public ArrayDeQue(){
    //Start of constructor
    fileSize = 0;
    fileName = "";
    userID = "";
    n = 0;
    } //end of the constructor
     //This will check to see if the array queue is empty or not.
     public boolean isEmpty(){
            return n == 0;
     //This will make the array queue empty of values.
        public void clear(){
           n = 0;
           fileSize = 0;
           fileName = null;
           userID = null;
} //End of class


import java.util.ArrayDeque;
import java.util.Scanner;

 * @author Jacob
public class Assignment2ArrayDeQuePrintJob{
  //Start of the class
    public static void main(String[] args){ 
        //Start of the main method
        //Declaring a scanner to get inputs from the output box.
        Scanner scan = new Scanner(;
        //This is the welcome message to my program.
        System.out.println("Welcome to the Print Job Program");
        //This is declaring a new array dequeue function.
        ArrayDeque ad = new ArrayDeque();
        //This is used throughout the cases on this java program.
        String answer;
        //This is the message that will be displayed so that the person can\n
        //decide what they want to do when the program runs.
        //Declaring the names of the cases that are going to be below this.
        System.out.println("Print Job Operations\n"
                         + "1.insert\n"
                         + "2.delete\n"
                         + "3.display\n"
                         + "4.destroy\n"
                         + "5.Array empty or not\n"
                         + "6.exit\n");
        //Below is what we use to iterate through the array and what we do to \n
        //use the functions above within this code.
        int choice = scan.nextInt();
        switch (choice){
        case 1:
            System.out.println("Enter index and element");
            ad.add(scan.nextInt(), scan.nextInt());                    
        case 6:
            System.out.println("Enter index");
            System.out.println("Result : " + ad.get(scan.nextInt()));
        case 3:
            System.out.println("Enter index and element");
            ad.set(scan.nextInt(), scan.nextInt()); 
        case 4:
            System.out.println("Enter index");
        case 5:
            System.out.println("Empty Status: " + ad.isEmpty());
        case 2:
            System.out.println("Array Deque Cleared");
            System.out.println("Wrong Entry");
        //This action is the way you exit out of the program at any point.
        System.out.println("Do you want to continue using the program (Type y or n)");
        answer = scan.nextLine();                        
        //This action will take place when you say yes to continue on with the
        //program and when you say no it will end the program.
    } //End of the main method
} //End of the class

Keep in mind, I haven't started on your request yet. I need these questions answered before I can get started. Some changes I've made to your code though:

-Obviously indentation
-Made the println statements not have \n only if they were printing out one String
-Improved the do while loop by making a String called answer, and then made it .equalsIgnoreCase inside of the while loop
-Made your Scanner close before the end of the method body
-I've imported all the necessary utilities you need for your program
-I've also lined up your println statement at the beginning of the do while loop that has multiple Strings in it, so that you can see the actual format it will be on the screen.

I expect my questions to be answered lol.:sideways:
0 Jacob Fellows · December 9, 2014
^^^Create yourself a thread as that just seems unfair that you can go onto someone elses thread and then post your problems, Please it is really simple. Anyways my problem i'm still having trouble with.
0 Developer John · December 9, 2014
I've been looking at your code and using my resources right now. It might take me some time to figure out your request. It shouldn't be too long though.
0 Developer John · December 9, 2014
Umm... lol
0 Ledio Ballhysa · December 8, 2014
Hello.I am currently a newbie in Java and I was wondering if smn would help me for this project.
Build a class named Rectangle that represents a two - dimensional area . This class
must contain:
public Rectangle ( int x , int y , int width, int length)
-Constructs a rectangle that has the height of the upper - left coordinates x , y , and size as width and length:
public Rectangle ( Point p , int width , int length)
-Builds a rectangle that has the height of the upper - left point p and with sizes as width and length.
( Point is a class that you have to build that contains two fields that define the position of a point in the coordinate plan ) .
public int getWidth ( )
public int getGjat ( )
public int getX ( )
public int getY ( )
public boolean contains ( int x , int y )
-Returns true if the point with coordinates x , y is located within the rectangle .
public boolean contains ( Point p )
Returns true if the point p is inside the rectangle .
public Rectangle cross ( Rectangle r )
-Returns a new rectangle that represents the largest surface that is contained to this rectangle and to the other rectangle r . If rectangulars does not cross at all, should be returned a rectangle with width and length equal to 0 :
public String toString ( )
-Returns a string representation of the rectangle ,shaped in the form (for example):
" Rectangle [ x = 1 , y = 2 ,width = 3 , length = 6 ] " .
-Build an application that tests the Rectangle class .
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.
0 Developer John · December 8, 2014
Yes, it does help. Thanks for explaining it some more!
+1 Jacob Fellows · December 8, 2014
Well when you are in a shop and you our queuing to buy something the person at the front gets served and then leaves. At the end of the queue people join onto the end of it. Does this help. Also instead of using the Array Deque do you think I should use import java.util.Queue<E> at all???

Java / Android Development


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

Bucky Roberts Administrator