spacerose

lab2(9/4)

Sep 4th, 2020 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Book {
  6.     String author;
  7.     String title;
  8.     int year;
  9.  
  10.     void setAuthor(String author)
  11.     {
  12.         this.author=author;
  13.     }
  14.  
  15.     void setTitle(String title)
  16.     {
  17.         this.title=title;
  18.     }
  19.     void setYear(int year)
  20.     {
  21.         this.year=year;
  22.     }
  23.  
  24.     public String getAuthor()
  25.     {
  26.         return author;
  27.     }
  28.  
  29.     public String getTitle()
  30.     {
  31.         return title;
  32.     }
  33.  
  34.     public int getYear()
  35.     {
  36.         return year;
  37.     }
  38. }
  39.  
  40. class BookTest
  41. {
  42.     public static void main(String[] args)
  43.     {
  44.         Scanner sc=new Scanner(System.in);
  45.         Book poem=new Book();
  46.         System.out.println("Input: ");
  47.         String author=sc.next();
  48.         String title=sc.next();
  49.         int year=sc.nextInt();
  50.         poem.setAuthor(author);
  51.         poem.setTitle(title);
  52.         poem.setYear(year);
  53.         System.out.println(poem.getAuthor());
  54.         System.out.println(poem.getTitle());
  55.         System.out.println(poem.getYear());
  56.     }
  57. }
Add Comment
Please, Sign In to add comment