Answer to Question #268457 in Java | JSP | JSF for hatipo

Question #268457

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.


1
Expert's answer
2021-11-20T06:45:40-0500
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!!!!!!!!!!!!");
               
               
               
       }
       
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS