Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner tastiera = new Scanner(System.in);
- Bookshelf Libreria = new Bookshelf(10);
- String tit=new String();
- int pag=0;
- for(int i=0;i<Libreria.books.length;i++) {
- System.out.print("Inserisci il titolo del libro: ");
- tit= tastiera.next();
- System.out.print("Quante pagine ha? ");
- pag = tastiera.nextInt();
- Libreria.books[i] = new Book(tit,pag);
- }
- for(int i=0;i<Libreria.books.length;i++) {
- if(Libreria.Mtot(10)==true) {
- System.out.print(Libreria.books[i].getTitolo() + " - " + Libreria.books[i].getPagine());
- }
- }
- }
- }
- class Book {
- private String titolo;
- private int numPagine;
- public void setTitolo(String t) {
- t=titolo;
- }
- public void setPagine(int p) {
- p=numPagine;
- }
- public int getPagine() {
- return numPagine;
- }
- public String getTitolo() {
- return titolo;
- }
- Book(String titolo, int numPagine) {
- this.titolo=titolo;
- this.numPagine=numPagine;
- }
- Book() {
- }
- }
- class Bookshelf {
- int nBooksIn;
- Book books[];
- int nMax;
- Bookshelf (int nMax) {
- this.nBooksIn=0;
- this.nMax=nMax;
- books = new Book[nMax];
- }
- public boolean Mtot(int tot) {
- if(books[nBooksIn].getPagine()<tot){
- return true;
- } else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement