Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class BusinessCard {
- private String name;
- private String surname;
- private int tel;
- private String city;
- public BusinessCard(String name, String surname, int tel, String city) {
- this.name = name;
- this.surname = surname;
- this.tel = tel;
- this.city = city;
- }
- private static void printFrame(int width) {
- for (int i = 0; i < width + 5; i++)
- print("*");
- print("\n");
- }
- private static void printLine(String first, String second, int lineWidth, int width) {
- print("*");
- for (int i = 0; i < width - lineWidth; i++)
- print(" ");
- print(" " + first + " " + second + " *\n");
- }
- private static void print(Object o) {
- System.out.print(o);
- }
- public static void main(String args[]) {
- Scanner scanner = new Scanner(System.in);
- String name = scanner.next();
- String surname = scanner.next();
- int tel = scanner.nextInt();
- String city = scanner.next();
- new BusinessCard(name, surname, tel, city).showBusinessCard();
- }
- public void showBusinessCard() {
- int firstLineWidth = name.length() + surname.length();
- int secondLineWidth = city.length() + String.valueOf(tel).length();
- int width = firstLineWidth > secondLineWidth ? firstLineWidth : secondLineWidth;
- printFrame(width);
- printLine(name, surname, firstLineWidth, width);
- printLine(String.valueOf(tel), city, secondLineWidth, width);
- printFrame(width);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement