Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package edu.lp2.opencm.application.cli;
  2.  
  3. import java.io.PrintStream;
  4. import java.math.BigDecimal;
  5. import java.util.Scanner;
  6.  
  7. import edu.lp2.opencm.application.Bootstrap;
  8. import edu.lp2.opencm.application.service.PlanoSaudeService;
  9. import edu.lp2.opencm.domain.model.PlanoSaude;
  10.  
  11. public final class CadastrarPlanoSaude {
  12.  
  13.     private final PrintStream out;
  14.     private final Scanner in;
  15.     private final PlanoSaudeService planoSaudeService;
  16.  
  17.     public CadastrarPlanoSaude(PrintStream out, Scanner in, PlanoSaudeService service) {
  18.         this.out = out;
  19.         this.in = in;
  20.         this.planoSaudeService = service;
  21.     }
  22.  
  23.     public void doMain() {
  24.         PlanoSaude planoSaude = new PlanoSaude();
  25.        
  26.         while(true) {
  27.             out.printf("Nome do Plano: ");
  28.             try {
  29.                 planoSaude.setNome(in.nextLine());
  30.                 break;
  31.             } catch (IllegalArgumentException e) {
  32.                 out.printf("%s%n", e.getMessage());
  33.             }
  34.         }
  35.        
  36.         while(true) {
  37.             out.printf("Fone Contato (ex: \"(81)1234-5678\"): ");
  38.             try {
  39.                 planoSaude.setContato(in.nextLine());
  40.                 break;
  41.             } catch (IllegalArgumentException e) {
  42.                 out.printf("%s%n", e.getMessage());
  43.             }
  44.         }
  45.        
  46.         while(true) {
  47.             out.printf("Preço Padrão da Consulta: ");
  48.             try {
  49.                 planoSaude.setPrecoPadrao(new BigDecimal(in.nextLine()));
  50.                 break;
  51.             } catch (NumberFormatException e) {
  52.                 out.printf("Formato inválido.%n");
  53.             } catch (IllegalArgumentException e) {
  54.                 out.printf("%s%n", e.getMessage());
  55.             }
  56.         }
  57.        
  58.         planoSaudeService.add(planoSaude);
  59.     }
  60.    
  61.     public static void main(String args[]) {
  62.         Bootstrap app = new Bootstrap();
  63.        
  64.         try {
  65.             app.startCli();
  66.             app.pico.getComponent(CadastrarPlanoSaude.class).doMain();
  67.         } finally {
  68.             app.stop();
  69.         }
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement