Please use JAVA only
Write a Printer device, which also derives from generic devices, but this time includes the notion of jobs to be printed. Like Disk, a Printer should extend from Device. Additionally, a Printer should have an intwhich represents the number of jobs currently in the printer's print queue. We can add or complete print jobs, or check the number currently in the queue, but for this assignment that is the extent of what we expect (we will not be passing full-fledged print jobs to the class, we will just keep track of the number of jobs).
The class should implement the following public methods:
Example:
Below is a sample run demonstrating how the class would function
using the following input:
1 abc 2.0 3 def 4.0 6 7 xyz 5.5
> Device dev = new Device("controller", 0);
> System.out.println(dev);
generic 0, controller
> dev.isEnabled()
false
> dev.enable();
> dev.isEnabled()
true
> Disk disk = new Disk("HDD", 1, 123456789);
> System.out.println(disk);
disk 1, HDD (123456789 bytes)
> disk.getSize()
123456789
> disk.enable();
> disk.isEnabled()
true
> Disk disk2 = new Disk("SDD", 2, 256000000000L);
> Printer p = new Printer("Laser Printer", 3);
> p.numJobs()
0
> p.submitJob();
> p.numJobs()
0
> p.isEnabled()
false
> p.enable();
> p.submitJob();
> p.numJobs()
1
> p.submitJob();
> p.numJobs()
2
> p.completeJob();
> p.numJobs()
1
> p.completeJob();
> p.completeJob();
> p.numJobs()
0
> Device[] devices = {dev, disk, disk2, p};
> for (Device d : devices) { System.out.println(d); }
generic 0, controller
disk 1, HDD (123456789 bytes)
disk 2, SDD (256000000000 bytes)
printer 3, Laser Printer
Please make sure that it passes the following: https://repl.it/@micky123/ColorfulGranularCode
Printer.java
// Declare class Printer inheritance from parents(Device)
class
public class Printer extends Device {
private int jobNum; // Initialize
public Printer(String name, int id) {
super(name, id); //
super() get info from parents class
this.jobNum=0; //
declare
}
@Override public String getCategory() {
return "printer"; //
@Override category to "printer"
}
@Override public void disable() {
super.disable(); //
Disable the device
this.jobNum=0; // and
set number of jobs to 0
}
public void submitJob() {
if
(super.isEnabled()==true) { //Check if the device is enable
this.jobNum++; //number of job increase by 1
}
}
// return current number of job
public int numJobs() {
return
this.jobNum;
}
//check if there is still job and decrease by 1
to complete 1 job
public void completeJob() {
if (this.jobNum >0)
{
this.jobNum--;
}
}
}
Device.java
// declare class Device
public class Device {
// Initialize all variables as private
private String name;
private int id;
private boolean enabledStatus;
// build up the constructor method
public Device(String name, int id) {
this.name=name;
this.id=id;
this.enabledStatus=false;
}
// getName() method return the name
public final String getName() {
return this.name;
}
// getID () method return the id
public final int getID() {
return this.id;
}
// getCategory() return "generic"
public String getCategory(){
return "generic";
}
// enable() doesn't have a return but set
enabledStatus to true
public void enable() {
this.enabledStatus =
true;
}
// disable() doesn't have a return but set
enabledStatus to false
public void disable() {
this.enabledStatus =
false;
}
// return boolean to check if the device is
enable/disable
public boolean isEnabled() {
return
this.enabledStatus;
}
// return a string
@Override public String toString() {
return (getCategory() +
" "+getID() +", "+getName());
}
}
Disk.java
// Declare class Disk inheritance from class Device
class Disk extends Device {
// Initialize variable
private long size;
public Disk(String name, int id, long size)
{
super(name, id); //
super() for children class to access parents' infomation
this.size = size;
}
@Override public String getCategory() {
return "disk"; //
@Override category to "disk"
}
// return the size of
public long getSize() {
return
(this.size);
}
// @Override: use super() to acess parents' info
and add new size info
@Override public String toString() {
return super.toString()
+ String.format(" (%d bytes)",getSize());
}
}
Please use JAVA only Write a Printer device, which also derives from generic devices, but this...
Now, we will write a Disk device, which is more specific than a generic device, and thus Disk should extend Device. Since we are extending the class, it will automatically inherit all of the functionality of the Device class. We will just add some specifics associated with disks - the notion of disk size, which should be stored as a long because disk sizes can be relatively large. Something to think about: since we are not defining enabled() or disabled()...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
JAVA - Given two List objects (input and output), write a generic method that 1) clears output list if it contains any element, and 2) copies every element of input list to the output list in the same order and position. Note that the type of output list can be any super type of the input list (e.g. type(output)=Numeric & type(input)=Double). import java.util.List; import java.util.ArrayList; public class Collections { // Modify method signature if needed & implement the body of...
Please USE JAVA only
Write a class named InputSplitter. This class will take input
from the keyboard (using a Scanner) and split the incoming tokens
into integers, floating point numbers, and strings. The incoming
tokens will be added to one of three accumulators which start out
at zero, and which keep a running total.
Thus, the class will have an accumulator for integers. It starts
out with the value zero. Every time another integer is read in, it
is added...
In Java. Please use the provided code
Homework 5 Code:
public class Hw05Source {
public static void main(String[] args)
{
String[] equations ={"Divide 100.0 50.0",
"Add 25.0 92.0", "Subtract 225.0 17.0",
"Multiply 11.0 3.0"};
CalculateHelper helper= new CalculateHelper();
for (int i = 0;i {
helper.process(equations[i]);
helper.calculate();
System.out.println(helper);
}
}
}
//==========================================
public class MathEquation {
double leftValue;
double rightValue;
double result;
char opCode='a';
private MathEquation(){
}
public MathEquation(char opCode) {
this();
this.opCode = opCode;
}
public MathEquation(char opCode,double leftVal,double
rightValue){...
Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...
Please use Java only. Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. -- Not needed Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. --needed ZeroException Task: -- Not needed Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise....
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans) A company would like to implement its inventory of computing machines as a linked list, called ComputerList. Write a Computer node class, called ComputerNode, to hold the following information about a Computer: • code (as a String) • brand (as a String) • model (as a String) • price (as double) • quantity (as int) ComputerNode should have constructors and methods (getters, setters, and toString()) to manage the above...
Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered or highest ordered) result it has seen so far. The class will be a generic type, so the type of results it sees depends on how it is declared. TopResult Task: There are a number of situations in which we want to keep track of the highest value we've seen so far - a highest score, a most recent entry, a name which is...