Используем классы, методы и сеттеры для ввода и вывода значений. Всего класса 3 Author, Title, Content. Их Обрабатывает главный метод Book (он же точка входа программы)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.util.Scanner; public class Book { public static void main(String[] args) { Scanner in = new Scanner(System.in); Author author = new Author(); Title tit = new Title(); Content cont = new Content(); System.out.println("Введите имя автора: "); author.setAuthor(in.next()); System.out.println("Введите заголовок книги: "); tit.setTitle(in.next()); System.out.println("Введите текст вниги: "); cont.setContent(in.nextLine()); author.show(); tit.show(); cont.show(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Author { public String author; //сеттер public void setAuthor(String author) { this.author = author; } void show(){ System.out.println("Имя автора: "+author); } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Title { public String title; //сеттер void setTitle(String title){ this.title = title; } void show(){ System.out.println("Заголовок книги: "+title); } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Content { public String content; //сеттер public void setContent(String content) { this.content = content; } void show(){ System.out.println("Текст книги: "+content); } } |
| Категория: Java