Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. class BusinessCard {
  5.  
  6.     private String name;
  7.     private String surname;
  8.     private int tel;
  9.     private String city;
  10.  
  11.     public BusinessCard(String name, String surname, int tel, String city) {
  12.         this.name = name;
  13.         this.surname = surname;
  14.         this.tel = tel;
  15.         this.city = city;
  16.     }
  17.  
  18.     private static void printFrame(int width) {
  19.         for (int i = 0; i < width + 5; i++)
  20.             print("*");
  21.         print("\n");
  22.     }
  23.  
  24.     private static void printLine(String first, String second, int lineWidth, int width) {
  25.         print("*");
  26.         for (int i = 0; i < width - lineWidth; i++)
  27.             print(" ");
  28.         print(" " + first + " " + second + " *\n");
  29.     }
  30.  
  31.     private static void print(Object o) {
  32.         System.out.print(o);
  33.     }
  34.  
  35.     public static void main(String args[]) {
  36.  
  37.         Scanner scanner = new Scanner(System.in);
  38.         String name = scanner.next();
  39.         String surname = scanner.next();
  40.         int tel = scanner.nextInt();
  41.         String city = scanner.next();
  42.  
  43.         new BusinessCard(name, surname, tel, city).showBusinessCard();
  44.     }
  45.  
  46.     public void showBusinessCard() {
  47.         int firstLineWidth = name.length() + surname.length();
  48.         int secondLineWidth = city.length() + String.valueOf(tel).length();
  49.         int width = firstLineWidth > secondLineWidth ? firstLineWidth : secondLineWidth;
  50.  
  51.         printFrame(width);
  52.         printLine(name, surname, firstLineWidth, width);
  53.         printLine(String.valueOf(tel), city, secondLineWidth, width);
  54.         printFrame(width);
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement