NIC institute's Resource manager has decided to network the computer resources like printer storagemediathat minimum resource and maximum sharing could be availedaccordingly printers are linked to a centralised system and the printing jobs are done on a first come first served basis only this is like the first person's printing job will get done first and the next person job will Bdone as the next job in the list and so on in order to avoid collision the restriction is that no more than 20 printing jobs can be added.
Define a class PrintJob with the following details:
Class name       PrintJob

Data members :

job[] Array of integers to hold the printing jobs
Newjob To add a new printing job into the array
Capacity  maximum capacity of the integer array
Front To point to the index of the Front
Rear To point to the index of the last

Member Functions 

PrintJobs()   Constructor to initialise the data member capacity 20 
Front = Rear = 1 and Call the function createJob()
voidcreateJob() To create an array to hold the printing PrintJobs
voidaddJob()   Adds the new printing job to the end of the last printing job if 
possible otherwise displays the message print job is full cannot add anymore
voidremoveJob() - Remove the printing job from the front if the printing job 
is not empty otherwise displays the message paint job is empty

Also write the main function



            





import java.util.*;
public class PrintJob
{ 
    int job[];
    int newjob,capacity,front,rear;
    PrintJob(){
        capacity=20;
        newjob=0;
        front=rear=1;
        job=new int[20];
    }

    void createJob()
    {

    }

    void addJob()
    { 

        if(rear == capacity-1)
        {
            System.out.println("Printjob is full,cannot add any more");
        }
        else if (front == 1)
        {

            front=rear=2;
            job[rear]=newjob;
        }
        else
        {
            job[++rear]=newjob;
        }
    }

    void removeJob()
    { 

        if(rear == 0)
        {
            System.out.println("Printjob is empty");
        }

        else if(front == rear)
        {

            front=rear=1;
        }
        else
        {
            ++front;
        }
    }

    public static void main(String args[])
    {

        Scanner sc=new Scanner(System.in);
        PrintJob obj=new PrintJob();
        int ch=0,n;
        do{
            System.out.println("Menu \n1.Insert Job ID\n2.Delete Job ID\n3.Exit");
            System.out.println("Enter your choice");
            ch=sc.nextInt();
            switch(ch)
            {
                case 1:
                    System.out.println("Enter Job ID");
                    obj.newjob=sc.nextInt();
                    obj.addJob();
                    break;
                case 2:
                    obj.removeJob();
                    break;

                case 3:
                    System.out.println("Your are now is exiting");
                    System.exit(0);
                    break;
                default:
                    System.out.println("Invalid choice");
                    break;
            }
        }while(true);

    }
}


     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com