Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import java.util.Scanner; public class Zadaca { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter details for 3 books: "); Library library = new Library(3); for(int i = 0; i < 3; i++) { System.out.println("Enter title: "); String title = sc.nextLine(); System.out.println("Enter author: "); String author = sc.nextLine(); System.out.println("Enter price: "); double price = Double.parseDouble(sc.nextLine()); Book book = new Book(title, author, price); library.addBook(book); } library.displayAllBooks(); } } class Book { String title; String author; double price; public Book(String title, String author, double price) { this.title = title; this.author = author; this.price = price; } public void print() { System.out.println("Title: " + title); System.out.println("Author: " + author); System.out.println("Price: " + price); } } class Library { Book[] books; int at; public Library(int n) { books = new Book[n]; at = 0; } public void addBook(Book book) { books[at] = book; at++; } public void displayAllBooks() { for(int i = 0; i < at; i++) { books[i].print(); } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)