0% found this document useful (0 votes)
32 views

Project Program Question 3

The PrintJob class models a printing queue with methods to add and remove print jobs. It uses integer arrays to store jobs with front and rear pointers. The constructor initializes capacity to 20 and front/rear to -1. The addJob method adds jobs to the rear until full, then displays a message. RemoveJob removes from the front, displaying empty if nothing to remove. Main creates a PrintJob, adds 4 jobs, removes 1, and displays the remaining jobs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Project Program Question 3

The PrintJob class models a printing queue with methods to add and remove print jobs. It uses integer arrays to store jobs with front and rear pointers. The constructor initializes capacity to 20 and front/rear to -1. The addJob method adds jobs to the rear until full, then displays a message. RemoveJob removes from the front, displaying empty if nothing to remove. Main creates a PrintJob, adds 4 jobs, removes 1, and displays the remaining jobs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Question 4:-

Class printjob with the following details:

Class name:PrintJob

Instance variable/data members:

Job[]: array of integers to hold the printing jobs.

Newjob: to add a new printing job into the array

Capacity: the maximum capacity of the integer array.

Front: to point index of the front.

Rear: point index of the rear.

Members function/methods:

Printjob(): to initialise data members capacity=20, Front Rear= -1.

void addJob-adds the new printing job at the end point of the last printing job,

if possible otherwise

display a message "friend job is ful cannot add anymore".

Void removeJob() :remove the printing job from the front of the printing job is

not empty, otherwise

display a message" print job is empty".

Specify the class print job given the details of the constructor and function.
Algorithm:-

public static void main()

Step 1: start

Step 2: Initialise the size of an array.

Step 3: a local variable size int data type is declared.

Step 4: object of the class is created

Step 5: methods are called

Step 6: end

PrintJob()

Step 1:start

Step 2: initialise capacity, front and rear.

Step 3: end

void addJob()

Step 1: start

Step 2: input through scanner

Step 3: condition to check whether rear equals to capacity-1,if rear

equals to capacity-1 than print "job is

full can't add anymore.

Step 4:else, increase rear with 1.

Step 5: end

void removeJob()

Step 1:start
Step 2: condition to check whether front and rear is equals to -1, if yes

then print,"job is empty".

Step 3: else, initialise variable int data type

Step 4: check front equals to rear or not

Step 5: if equals then initialise front and rear with -1

Step 6: else, increase the value of front by 1.

Step 7: end

void displayJob()

Step 1: start

Step 2: initialise a variable 'i ' for loop

Step 3: execute the loop to print the array

Step 4: end
import java.util.*;

class PrintJob

int job[]=new int[20];

int Newjob,Capacity, Front, Rear;

PrintJob()

Capacity =20;

Front=-1;

Rear=-1;

void addJob()

Scanner sc=new Scanner(System.in);

System.out.println("ENTER NEW JOB");

Newjob-sc.nextInt();

if(Rear==(Capacity-1))

System.out.println(" PRINT JOB IS FULL CANNOT ADD ANYMORE");

else

if(Front==-1&&Rear==-1)

Front =0;

Rear=0;

else

Rear=Rear+1;
job[Rear]=newJob;

void removeJob()

if(Front=-1&&Rear ==-1)

System.out.println("JOB IS EMPTY");

else

int val=job[Front];

if(Front==Rear)

else

Front=-1;

Rear=-1;

else

Front=Front+1;

void displayJob()

{
int i;

System.out.println("JOBS:");

for(i=Front;i<=Rear;i++)

System.out.println(job[i]);

public static void main()

PrintJob ob=new PrintJob();

ob.addJob();

ob.addJob();

ob.addJob();

ob.addJob();

ob.removeJob();

ob.displayJob();

}
OUTPUT:-
Enter new job

Enter new job

Enter new job

Enter new job

Jobs:

4
Variable Description Table:-

Variable Data type Description

job[] int Array of integers to hold the


printing jobs

newjob int To add a new printing jobs into


the array

capacity int The maximum capacity of the


integers array

front int To point index of the front

rear int To point index of the rear

val int To store element

i int Loop variable

You might also like