Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner tastiera = new Scanner(System.in);
  6. Bookshelf Libreria = new Bookshelf(10);
  7. String tit=new String();
  8. int pag=0;
  9.  
  10.  
  11. for(int i=0;i<Libreria.books.length;i++) {
  12.  
  13. System.out.print("Inserisci il titolo del libro: ");
  14. tit= tastiera.next();
  15. System.out.print("Quante pagine ha? ");
  16. pag = tastiera.nextInt();
  17.  
  18. Libreria.books[i] = new Book(tit,pag);
  19. }
  20. for(int i=0;i<Libreria.books.length;i++) {
  21. if(Libreria.Mtot(10)==true) {
  22. System.out.print(Libreria.books[i].getTitolo() + " - " + Libreria.books[i].getPagine());
  23. }
  24. }
  25. }
  26. }
  27.  
  28.  
  29. class Book {
  30. private String titolo;
  31. private int numPagine;
  32.  
  33. public void setTitolo(String t) {
  34. t=titolo;
  35. }
  36. public void setPagine(int p) {
  37. p=numPagine;
  38. }
  39. public int getPagine() {
  40. return numPagine;
  41. }
  42. public String getTitolo() {
  43. return titolo;
  44. }
  45. Book(String titolo, int numPagine) {
  46. this.titolo=titolo;
  47. this.numPagine=numPagine;
  48. }
  49. Book() {
  50. }
  51. }
  52.  
  53.  
  54. class Bookshelf {
  55. int nBooksIn;
  56. Book books[];
  57. int nMax;
  58.  
  59. Bookshelf (int nMax) {
  60. this.nBooksIn=0;
  61. this.nMax=nMax;
  62. books = new Book[nMax];
  63. }
  64.  
  65. public boolean Mtot(int tot) {
  66. if(books[nBooksIn].getPagine()<tot){
  67. return true;
  68. } else return false;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement