Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package q3;
- public class MyCard {
- String number;
- String type;
- public MyCard(String ctype, String cnumber) {
- this.number = cnumber;
- this.type = ctype;
- }
- public String getCode() {
- type = type.replaceAll("[a-zA-z]", "*");
- String str = "";
- for (int i = 0; i < type.length(); i++) {
- if (i % 3 == 0 && i > 0) {
- str += '-';
- }
- str += type.substring(i, i + 1);
- }
- return str;
- }
- public boolean checkLowerCase() {
- for (int i = 0; i < type.length(); i++) {
- if (!Character.isLowerCase(type.charAt(i))) {
- return false;
- }
- }
- return true;
- }
- public String getCardNumber() {
- if (checkLowerCase()) {
- return number;
- } else {
- return "";
- }
- }
- @Override
- public String toString() {
- return type + " " + number;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement