Create the java programming code for Eclipse IDE for this project this project also comes with jUnit
Question:
Create the java programming code for Eclipse IDE for this project this project also comes with jUnit code files I need the class files that go with the jUnit tests please read all material carefully
Printer:
Notice that the class name Printer and the method name print are italicized. In the context of a UML class diagram, this indicates that Printer is an abstract class and print is an abstract method.
Also, notice that the field count is underlined. In UML class diagrams, underlining indicates that the class member is static.
- In the constructor do the following:
Update the value of the field count by incrementing it by one.
Initialize the field model based on the value provided as an argument.
Calculate the value of the field serialNumber by adding the updated value of count to the number 12345. - The methods getModel and getSerialNumber have the typical functionality of a getter.
- The method print is abstract. Nonetheless, it needs a doc comment that describes the functionality that should be provided by subclasses.
Look what the print methods in class InkjetPrinter and LaserPrinter are doing. See what they have in common and generalize the behavior so it remains a valid description in case other subclasses (e.g. MatrixPrinter) were added later. - In method toString do the following:
Return a string of the following format:
{className}: {model} #{serialNumber}
Where {className}, {model}, and {serialNumber} are the actual values of the corresponding fields.
e.g.: InkjetPrinter Canon Pixma #12346
e.g.: LaserPrinter HP LaserJet Pro #12347
LaserPrinter and InkjetPinter:
- In the constructor do the following:
Set the value of remainingToner / remainingCartridge to 100, which indicates that the toner/cartridge is 100% full, and initialize the superclass. - The methods getRemainingToner / getRemainingCartridge have the typical functionality of a getter.
- The methods refillToner / refillCartridge set the fields remainingToner / remainingCartridge to 100.
- In method print do the following:
Check the field value to find out whether the toner/cartridge is empty.- If it is empty, print one of the following messages:
The toner is empty. or The cartridge is empty.
The field values remain unchanged. - If the toner/cartridge is not empty, reduce the value of the field remainingToner / remainingCartridge by 10.
In addition, print a message that informs the user which printer is printing and how much remaining toner/cartridge is left.
e.g.: HP LaserJet Pro is printing. Remaining toner: 90%
e.g.: Canon Pixma is printing. Remaining cartridge: 80% - Expected Output
- If it is empty, print one of the following messages:
- PrinterApp:
The class PrinterApp is a test client and it includes the main method.- Create an array of printers and add two printers:
an InkjetPrinter of model Canon TS202
a LaserPrinter of model Samsung Xpress - Loop through the array. For each of the printers do the following:
- Print the printer (the string provided by the toString method)
- Call the print method 11 times (avoid code duplication)
- Print an empty line
- Refill the toner / cartridge of the printers.
- Dynamically access and display the remaining toner / cartridge after refilling.
Use labels (descriptive text) to match the expected output.
FYI: "dynamically access" means that the number 100 should not be hard-coded. Instead, the remaining amount of toner/cartridge should be obtained at run-time by calling a method.
- Create an array of printers and add two printers:
InkjetPrinter: Canon TS202 #12346
Canon TS202 is printing. Remaining cartridge: 90%
Canon TS202 is printing. Remaining cartridge: 80%
Canon TS202 is printing. Remaining cartridge: 70%
Canon TS202 is printing. Remaining cartridge: 60%
Canon TS202 is printing. Remaining cartridge: 50%
Canon TS202 is printing. Remaining cartridge: 40%
Canon TS202 is printing. Remaining cartridge: 30%
Canon TS202 is printing. Remaining cartridge: 20%
Canon TS202 is printing. Remaining cartridge: 10%
Canon TS202 is printing. Remaining cartridge: 0%
The cartridge is empty.
LaserPrinter: Samsung Xpress #12347
Samsung Xpress is printing. Remaining toner: 90%
Samsung Xpress is printing. Remaining toner: 80%
Samsung Xpress is printing. Remaining toner: 70%
Samsung Xpress is printing. Remaining toner: 60%
Samsung Xpress is printing. Remaining toner: 50%
Samsung Xpress is printing. Remaining toner: 40%
Samsung Xpress is printing. Remaining toner: 30%
Samsung Xpress is printing. Remaining toner: 20%
Samsung Xpress is printing. Remaining toner: 10%
Samsung Xpress is printing. Remaining toner: 0%
The toner is empty.
Remaining cartridge after refilling: 100%
Remaining toner after refilling: 100%
HERE ARE THE JUNIT TEST CODE FILES
PRINTER
package abstractClass;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/**
* JUnit tests to test class Printer from Lab Abstract.
* This test class should not be changed.
*/
class PrinterTest {
private static InkjetPrinter printer1 = new InkjetPrinter("Canon Pixma");
@Test
void testPrinter_incrementSerialNumbersBy1() {
LaserPrinter printer2 = new LaserPrinter("HB LaserJet Pro");
LaserPrinter printer3 = new LaserPrinter("Lexmark B2338DW");
assertEquals("HB LaserJet Pro", printer2.getModel());
assertEquals("Lexmark B2338DW", printer3.getModel());
assertEquals(12347, printer2.getSerialNumber());
assertEquals(12348, printer3.getSerialNumber());
}
@Test
void getModel_returnsModel() {
assertEquals("Canon Pixma", printer1.getModel());
}
@Test
void getSerialNumber_firstSerialNumber12346() {
assertEquals(12346, printer1.getSerialNumber());
}
@Test
void testToString() {
assertEquals("InkjetPrinter: Canon Pixma #12346", printer1.toString());
}
}
LASERPRINTER: Samsung Xpress #12347
package abstractClass;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* JUnit tests to test class LaserPrinter from Lab Abstract.
* This test class should not be changed.
*/
class LaserPrinterTest {
private LaserPrinter printer;
@BeforeEach
void setUp() throws Exception {
printer = new LaserPrinter("Samsung Xpress");
}
@Test
void testLaserPrinter_full() {
LaserPrinter p = new LaserPrinter("HB LaserJet Pro");
assertEquals(100, p.getRemainingToner());
}
@Test
void print_once_reduceTonerBy10percent() {
printer.print();
assertEquals(90, printer.getRemainingToner());
}
@Test
void print_threeTimes_reduceTonerBy30percent() {
printer.print();
printer.print();
printer.print();
assertEquals(70, printer.getRemainingToner());
}
@Test
void print_elevenTimes_reduceTonerUntil0() {
for(int i = 1; i <= 10; i++) {
printer.print();
assertEquals(100 - i * 10, printer.getRemainingToner());
}
printer.print();
assertEquals(0, printer.getRemainingToner()); // still 0
}
@Test
void refillToner_full_remainsFull() {
printer.refillToner();
assertEquals(100, printer.getRemainingToner());
}
@Test
void refillToner_notFull_fillsUpTo100() {
for(int i = 0; i < 5; i++) {
printer.print();
}
printer.refillToner();
assertEquals(100, printer.getRemainingToner());
}
}
INKJETPRINTER : Canon TS202 #12346
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* JUnit tests to test class InkjetPrinter from Lab Abstract.
* This test class should not be changed.
*/
class InkjetPrinterTest {
private InkjetPrinter printer;
@BeforeEach
void setUp() throws Exception {
printer = new InkjetPrinter("Canon TS202");
}
@Test
void testInkejetPrinter_full() {
InkjetPrinter p = new InkjetPrinter("Canon Pixma");
assertEquals(100, p.getRemainingCartridge());
}
@Test
void print_once_reduceCartridgeBy10percent() {
printer.print();
assertEquals(90, printer.getRemainingCartridge());
}
@Test
void print_threeTimes_reduceCartridgeBy30percent() {
printer.print();
printer.print();
printer.print();
assertEquals(70, printer.getRemainingCartridge());
}
@Test
void print_elevenTimes_reduceCartridgeUntil0() {
for(int i = 1; i <= 10; i++) {
printer.print();
assertEquals(100 - i * 10, printer.getRemainingCartridge());
}
printer.print();
assertEquals(0, printer.getRemainingCartridge()); // still 0
}
@Test
void refillCartridge_full_remainsFull() {
printer.refillCartridge();
assertEquals(100, printer.getRemainingCartridge());
}
@Test
void refillCartridge_notFull_fillsUpTo100() {
for(int i = 0; i < 5; i++) {
printer.print();
}
printer.refillCartridge();
assertEquals(100, printer.getRemainingCartridge());
}
}
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood