- I need the chegg expert to follow exactly what the instructions are asking for
ID: 669726 • Letter: #
Question
- I need the chegg expert to follow exactly what the instructions are asking for so that i can learn this material.
-the code needs to be writte in Java
- thank you for your help
Explanation / Answer
public class PrinterApp
{
public static void main(String[] args){
//Printer p=new Printer(1234567); cannot be created
InkjetPrinter ip=new InkjetPrinter(1234567);
System.out.println(ip);
System.out.println("Remaining Catridge: "+ip.remainingCatridge+"%");
LaserPrinter lp=new LaserPrinter(2345678);
System.out.println(lp);
System.out.println("Remaining Toner: "+lp.remainingToner+"%");
System.out.println("Array of printers:");
Printer[] p = new Printer[2];
p[0]=ip;
p[1]=lp;
for(Printer k:p){
k.print();
k.print();
System.out.println("");
}
}
}
public class InkjetPrinter extends Printer{
int remainingCatridge;
public InkjetPrinter(int sNumber) {
super(sNumber);
remainingCatridge=100;
// TODO Auto-generated constructor stub
}
@Override
public void print() {
if(remainingCatridge>0){
remainingCatridge=remainingCatridge-10;
System.out.println("CatridgePrinter is printing. Remaining Catridge: "+remainingCatridge+"%");
}else{
System.out.println("Catridge is empty.");
}
}
}
public abstract class Printer{
private int serialNumber;
public Printer(int number){
serialNumber=number;
}
public abstract void print();
public String toString(){
return this.getClass().getName()+" #"+serialNumber;
}
}
public class LaserPrinter extends Printer{
int remainingToner;
public LaserPrinter(int number) {
super(number);
remainingToner=100;
// TODO Auto-generated constructor stub
}
public int getRemainingToner(){
return remainingToner;
}
@Override
public void print() {
if(remainingToner>0){
remainingToner=remainingToner-10;
System.out.println("LaserPrinter is printing. Remaining toner: "+remainingToner+"%");
}else{
System.out.println("Toner is empty.");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.