Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package q3;
  7.  
  8. public class MyCard {
  9.  
  10. String number;
  11. String type;
  12.  
  13. public MyCard(String ctype, String cnumber) {
  14. this.number = cnumber;
  15. this.type = ctype;
  16. }
  17.  
  18. public String getCode() {
  19. type = type.replaceAll("[a-zA-z]", "*");
  20. String str = "";
  21. for (int i = 0; i < type.length(); i++) {
  22. if (i % 3 == 0 && i > 0) {
  23. str += '-';
  24. }
  25. str += type.substring(i, i + 1);
  26. }
  27. return str;
  28. }
  29.  
  30. public boolean checkLowerCase() {
  31. for (int i = 0; i < type.length(); i++) {
  32. if (!Character.isLowerCase(type.charAt(i))) {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38.  
  39. public String getCardNumber() {
  40. if (checkLowerCase()) {
  41. return number;
  42. } else {
  43. return "";
  44. }
  45. }
  46.  
  47. @Override
  48. public String toString() {
  49. return type + " " + number;
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement