Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I need help with writing the code for this project. (JAVA CODE) You are a so

ID: 3819765 • Letter: H

Question

Hi, I need help with writing the code for this project. (JAVA CODE)

You are a software developer working for company that sells printers and they have a new printer for which they need to create software so that it can handle print requests properly. This printer will have two separate trays, one for requests that are printed on white paper and one for requests that are printed on yellow paper. When requests come to the printer they will be processed on a first come first serve basis.

The request will need to include the name of the request, the text that is to be printed, the sheets of paper that are required for the job, and the color paper that it should be printed (white or yellow). If there is not enough paper to process the request then it will not be processed and the user will be informed that the request could not be processed until more paper is placed in the appropriate tray. The request itself will be removed and placed behind all of the requests that have already come in. This way the user will not have to send another request, but place more paper in the appropriate tray. At any point during the execution of these requests a person may opt to fill either tray with more paper of the appropriate color. Once this is done the execution of the next request can continue.

This software will be tested with a prototype. This prototype should have five main options. The first option is to process the next request that has come in. Requests will not be processed automatically to allow a user to test this software. If user attempts to process the next request when there are no more requests to process an error message should be shown and the program should ask the user what they would like to do next. The second option is to add a print request. The user will be asked to enter all the information for a request and then it will be added. The third option is to look at all the requests that have come in the order in which they came. The fourth option is to look at the amount paper in both trays of the printer. The fifth option is to load more paper into each of these trays. This part will require the user entering the amount of paper that was loaded into each tray. The maximum number of paper in each tray cannot be more than 100 so if a user attempts to load an amount of paper that would push the total above 100 the user will be given an error message and the paper tray will not close so the user will have to enter an amount that will not push the total above 100.

The first step in this process is to develop the Print Job class which would hold all the information for the request. This class should follow object-oriented methodology by making its instance variables private and having appropriate accessor and mutator methods to allow access and manipulation of the attributes of the Print Job class. The number of sheets of paper required for the job cannot be less than 1 and if a user enters a value less than one an exception should be thrown to inform the user of this. This exception class should be developed as the LessThanOneException which should inherit from the Exception class. The color of the paper passed in can only be white or yellow, if any other color is passed an exception should be thrown to inform the user of this. This exception class should be developed as the ColorPaperException which should inherit from the Exception class. The Print Job class should also override the toString method from the Object class to return in String form all the information about a Print Job.

The next step will be to develop a Paper Tray class which represents the paper tray inside the printer. This class should have attributes for the name of the tray, the color of paper that is assigned to it, the amount of paper currently in the tray, and a constant that represents the maximum amount of paper that will fit into that tray. The maximum for all trays should be 100 pieces of paper. This class should follow object-oriented methodology by making its instance variables private and having appropriate accessor and mutator methods to allow access and manipulation of the attributes of the Paper Tray class. Attempting to add more paper to tray than it can hold will cause a PaperOverFlowException which should inherit from the Exception class. The Paper Tray class should also override the toString method form the Object class to return in String form all the information about a Paper Tray.

The third step in the development process is to use take the NodeBasedQueue class and add a toString method that overrides the one from the Object class to show all the Print Jobs in the queue. Your project will also need to include QueueInterface, UnboundedQueueInterface and the QueueEmptyException without the need for any changes. This project uses the node based version because this printer should have no limit on the number of requests that it can receive.

The fourth step in the development process is to create a Printer class that will represent the printer that will receive and process Print Jobs. Since this printer will have two paper trays it will have two instance variables of the Paper Tray class. One should handle requests for white paper and the other for requests on yellow paper. They should be given an appropriate name and the initial amount of paper for each tray will be set at 100. The Printer class will also have an instance variable to handle all of the Print Jobs that come in. These should be stored in a queue of the NodeBasedQueue. The Printer class should have a few methods. One is to print the next job in the queue. The next is to accept a Print Job and add it to the end of the queue. It should be able to display all the Print Jobs in the queue. Methods for checking the amount of paper in each in tray along with loading and removing paper in each tray should also be part of the Printer class.

Finally, develop a demo class that will allow the user to do try all of these options. Make sure to test things such as trying to process a job when there is no job in the queue, or trying to process a job when there isn’t enough paper to process that job, and also to load more paper into a tray than it can handle to test to make sure your program can handle these exceptional situations. All exceptions should be handled by using try/catch construct to prevent the program from ending when an exception occurs.

Explanation / Answer

import java.util.*;

import java.io.*;

class PrintJob

{

private int Sheets,numLoad; //sheets!<1

String printReq,printText,sheetColor;

Scanner reader = new Scanner(System.in); // Reading from System.in

System.out.println("Please enter "print" request/ "load" paper request");

try{ //try block starts

System.out.println("Please enter text to be printed");

System.out.println("Please enter sheets required");

System.out.println("Enter color of sheets to be printed");

sheetColor=reader.nextLine();

}

else if(request=="load")

{

System.out.println("Enter number of papers to be loaded");

numLoad=reader.nextInt();

if(numLoad<1 )

{

System.out.println("Request cant be processed,add more paper to tray");

}

}

else

{

System.out.println("Enter valid request again");

break;

}

}//try block ends

catch(LessThanOneException e1)

{

System.out.println("Number of sheets cant be <1 ");

}

catch(ColorPaperException e2)

{

System.out.println("Color of sheet should be only white or yelow ");

}

}//class PrintJob ends

public class LessThanOneException extends Exception

{

public class LessThanOneException extends Exception

{

public class LessThanOneException extends Exception

{

public class PaperTray

{

String TrayName;

String PaperColor;

int PaperInTray;

public static final MAXPAPER=3;

// class NodeBasedQueue

public class QueueInterface extends Exception

{

public class UnboundedQueueInterface extends Exception

{

public class QueueEmptyException extends Exception

{

class Printer

{

t2.addRequest("white",2);

t1.removePaper(9);

t2.removePapert(10);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote