"HR30 Day 13: Abstract Classes/Java"의 두 판 사이의 차이

(새 문서: ==개요== * HR30 Day 13: Abstract Classes <source lang='java'> import java.util.*; abstract class Book { String title; String author; Book(String title, String...)
 
1번째 줄: 1번째 줄:
[[분류: 30 Days of Code]]
==개요==
==개요==
* [[HR30 Day 13: Abstract Classes]]
* [[HR30 Day 13: Abstract Classes]]

2018년 8월 10일 (금) 02:13 판

개요

import java.util.*;

abstract class Book {
    String title;
    String author;
    
    Book(String title, String author) {
        this.title = title;
        this.author = author;
    }
    
    abstract void display();
}
class MyBook extends Book {
    int price;
    /**   
    *   Class Constructor
    *   
    *   @param title The book's title.
    *   @param author The book's author.
    *   @param price The book's price.
    **/
    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    /**   
    *   Method Name: display
    *   
    *   Print the title, author, and price in the specified format.
    **/
    public void display() {
        System.out.printf("Title: %s\n", this.title);
        System.out.printf("Author: %s\n", this.author);
        System.out.printf("Price: %d\n", this.price);
    }
}
public class Solution {
   
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String title = scanner.nextLine();
        String author = scanner.nextLine();
        int price = scanner.nextInt();
        scanner.close();

        Book book = new MyBook(title, author, price);
        book.display();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}