1 Context An Adapter pattern acts as a connector between two incompatible interfaces that otherwise cannot be connected directly. An Adapter wraps an existing class with a new interface so that it becomes compatible with the client’s interface.
2 Problem description In this work, you will manage a printer room. There are two printers in the printer room, one char printer and the other one for char array. Depending on the printer selected, the job will either be printed in char or according to the limit, such as a char buffer.
3 Measure of success You are expected to implement necessary classes for this example using Facade Pattern. Output should be as in the pictures.
package printer;
import java.util.Scanner;
public class Printer {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
System.out.println("Enter your text");
String text = scan.nextLine();
System.out.println("Enter printer type");
String type = scan.nextLine();
switch(type){
case "char":
System.out.println("Enter printer type");
for(char c: text.toCharArray()){
System.out.println(c);
}
break;
case "buffer":
System.out.println("Enter printer type");
int i = 0;
for(char c: text.toCharArray()){
i++;
System.out.print(c);
if(i%3==0)
System.out.println();
}
break;
default:
System.out.println("Enter valid printer!!!!!!!!!!!!");
}
}
}
Comments
Leave a comment