├── .gitignore ├── 2012-02-06 ├── Command.java ├── Controller.java ├── Television.java ├── Test.java ├── compito.pdf └── compito.tex ├── 2012-02-24 ├── compito.pdf └── compito.tex ├── 2012-06-18 ├── Main.java ├── Polynomial.java ├── SecondDegreePolynomial.java ├── compito.pdf └── compito.tex ├── 2012-07-06 ├── AlternatePlot.java ├── DuplicatedSampleException.java ├── InconsistentSampleSizeException.java ├── Main.java ├── Plot.java ├── Sample.java ├── SequentialPlot.java ├── compito.pdf └── compito.tex ├── 2012-09-03 ├── ArraySet.java ├── Main.java ├── ModifiableArraySet.java ├── ModifiableSet.java ├── Set.java ├── compito.pdf └── compito.tex ├── 2012-09-24 ├── Alternate.java ├── Concat.java ├── From.java ├── Main.java ├── Numbers.java ├── UpTo.java ├── compito.pdf └── compito.tex ├── 2013-02-04 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── elezioni │ ├── Coalizione.java │ ├── CoalizioneGiàPresenteException.java │ ├── Elezione.java │ ├── Main.java │ ├── Partito.java │ ├── PartitoGiàRegistratoException.java │ └── PartitoMaiRegistratoException.java ├── 2013-02-26 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── calendar │ ├── Calendar.java │ ├── Event.java │ ├── Main.java │ └── Time.java ├── 2013-06-24 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── musica │ ├── AbstractCanzone.java │ ├── Canzone.java │ ├── CanzoneImpl.java │ ├── CanzoneRibasata.java │ ├── Main.java │ ├── Nota.java │ ├── NotaIT.java │ └── NotaUK.java ├── 2013-07-15 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── spreadsheet │ ├── Add.java │ ├── Append.java │ ├── Cell.java │ ├── CyclicEvaluationException.java │ ├── Div.java │ ├── EvaluationException.java │ ├── Exp.java │ ├── Main.java │ ├── NumericConstant.java │ ├── Sheet.java │ └── StringConstant.java ├── 2013-09-02 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── quindici │ ├── FattoriaDiTessere.java │ ├── FattoriaDiTessereAlfabetiche.java │ ├── FattoriaDiTessereNumeriche.java │ ├── Gioco.java │ ├── Main.java │ ├── Tessera.java │ ├── TesseraAlfabetica.java │ └── TesseraNumerica.java ├── 2013-09-27 ├── classi.fig ├── classi.pdf ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── numeri │ ├── AbstractNumero.java │ ├── Main.java │ ├── Numero.java │ ├── NumeroBCD.java │ ├── NumeroInBase.java │ ├── NumeroInBaseDue.java │ └── NumeroInBaseSedici.java ├── 2014-02-07 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── freebay │ ├── Buy2Take3Product.java │ ├── Cart.java │ ├── DiscountedProduct.java │ ├── Main.java │ └── Product.java ├── 2014-02-28 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── cartellone │ ├── Cartellone.java │ ├── CartelloneLimitato.java │ ├── CartelloneModificabile.java │ ├── Main.java │ ├── Time.java │ └── Train.java ├── 2014-07-14 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── identifiers │ ├── AbstractMultiWordsIdentifier.java │ ├── CamelStyleIdentifier.java │ ├── EmptyWordException.java │ ├── Identifier.java │ ├── Main.java │ ├── NegativeProgressiveNumberException.java │ ├── NoWordsProvidedException.java │ ├── ProgressiveIdentifier.java │ ├── SnakeStyleIdentifier.java │ └── WordIsNotAlphabeticalLowercaseException.java ├── 2014-09-15 ├── Main.java ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── tokenizer │ ├── CharacterTokenization.java │ ├── DoubleTokenization.java │ ├── NoDelimitersException.java │ ├── SpaceTokenization.java │ ├── StringTokenization.java │ └── Tokenization.java ├── 2015-02-02 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── paranoid │ ├── App.java │ ├── AppAlreadyInstalledException.java │ ├── AppNotSupportedException.java │ ├── Device.java │ ├── InstallationException.java │ ├── Main.java │ ├── OS.java │ └── Store.java ├── 2015-02-23 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── life │ ├── Blinker.java │ ├── Block.java │ ├── Board.java │ ├── Cell.java │ ├── Figure.java │ ├── Glider.java │ ├── Main.java │ ├── Ship.java │ └── Toad.java ├── 2015-06-18 ├── Main.java ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── charsequence │ ├── AbstractCharSequence.java │ ├── Alphabetical.java │ └── ControlCode.java ├── 2015-09-30 ├── Swing12DateView.png ├── SwingDateView.png ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── date │ ├── Main.java │ ├── controller │ ├── Controller.java │ └── ControllerImpl.java │ ├── model │ ├── Model.java │ └── Time.java │ └── view │ ├── Swing12DateView.java │ ├── SwingDateView.java │ ├── TextDateView.java │ └── View.java ├── 2016-02-03 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── elezioni │ ├── Elezioni.java │ ├── ElezioniIstogramma.java │ ├── Main.java │ ├── Partito.java │ └── VotiPerPartito.java ├── 2016-02-24 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── palestra │ ├── Iscrizione.java │ ├── IscrizioneSovrappostaException.java │ ├── IscrizioneTroppoLungaException.java │ ├── IscrizioneVuotaException.java │ ├── Main.java │ ├── Mese.java │ ├── Registro.java │ └── Utente.java ├── 2016-06-21 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── email │ ├── Email.java │ ├── Mailbox.java │ ├── Main.java │ ├── Server.java │ └── UnknownEmailException.java ├── 2016-09-06 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── phones │ ├── Main.java │ ├── PhoneBook.java │ ├── SexView.java │ ├── SortedView.java │ ├── UnknownEntryException.java │ └── View.java ├── 2017-02-03 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── doodle │ ├── Doodle.java │ ├── Main.java │ ├── Slot.java │ └── WeightedDoodle.java ├── 2017-06-26 ├── Main.java ├── compito.pdf ├── compito.tex ├── hierarchy.png └── it │ └── univr │ └── pizzeria │ ├── AbstractPizza.java │ ├── Formaggi.java │ ├── Funghi.java │ ├── IllegalPizzaModificationException.java │ ├── Margherita.java │ ├── Menu.java │ ├── Order.java │ ├── Pizza.java │ ├── PizzaWith.java │ ├── PizzaWithout.java │ └── ProsciuttoFunghi.java ├── 2017-07-28 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── ecommerce │ ├── Main.java │ ├── MissingProductException.java │ ├── Order.java │ ├── Product.java │ ├── Shipping.java │ ├── Shop.java │ ├── SimpleOrder.java │ └── SplitOrder.java ├── 2017-09-04 ├── compito.pdf ├── compito.tex └── src │ ├── Main.java │ └── it │ └── univr │ ├── airbust │ ├── AirBustBookings.java │ └── AirBustFleet.java │ └── bookings │ ├── Aircraft.java │ ├── BookingException.java │ ├── Bookings.java │ ├── Date.java │ ├── Fleet.java │ ├── FlightSoldOutException.java │ ├── IllegalBookingDatesException.java │ ├── PriceChangedException.java │ └── QuoteException.java ├── 2018-02-07 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── hairbnb │ ├── HairBnB.java │ ├── Main.java │ ├── NoRoomAvailableException.java │ ├── Review.java │ └── Room.java ├── 2018-02-27 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── esami │ ├── Esame.java │ ├── EsamePerEsito.java │ ├── EsamePerMatricola.java │ ├── Esito.java │ ├── Main.java │ ├── Studente.java │ ├── StudenteNonIscrittoException.java │ └── VerbalizzazioneGiàEffettuataException.java ├── 2018-06-21 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── numbers │ ├── AbstractNumber.java │ ├── Base58Number.java │ ├── BinaryNumber.java │ ├── BinaryNumberWithParity.java │ ├── DecimalNumber.java │ ├── HexNumber.java │ ├── Main.java │ ├── Number.java │ └── OctalNumber.java ├── 2018-09-28 ├── compito.pdf ├── compito.tex └── it │ └── univr │ └── music │ ├── EnglishNote.java │ ├── ItalianNote.java │ ├── Main.java │ ├── Note.java │ ├── NoteAtSamePositionException.java │ ├── NoteTest.java │ └── Song.java ├── 2019-01-29 ├── consegna │ ├── Main.java │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── rent │ │ │ ├── AbstractModel.java │ │ │ ├── Agency.java │ │ │ ├── License.java │ │ │ └── Model.java │ └── risultato_main.txt └── soluzione │ ├── Main.java │ └── it │ └── univr │ └── rent │ ├── AbstractModel.java │ ├── Agency.java │ ├── Bus.java │ ├── Car.java │ ├── IllegalLicenseException.java │ ├── License.java │ ├── Model.java │ ├── ModelNotAvailableException.java │ ├── Motorbike.java │ └── Truck.java ├── 2019-02-04 ├── v1 │ ├── consegna │ │ ├── Main.java │ │ ├── compito.pdf │ │ ├── compito.tex │ │ ├── it │ │ │ └── univr │ │ │ │ └── agenda │ │ │ │ ├── AmericanTime.java │ │ │ │ ├── Event.java │ │ │ │ ├── ItalianTime.java │ │ │ │ └── Time.java │ │ └── risultato_main.txt │ └── soluzione │ │ ├── Main.java │ │ └── it │ │ └── univr │ │ └── agenda │ │ ├── AmericanTime.java │ │ ├── Event.java │ │ ├── ItalianTime.java │ │ └── Time.java └── v2 │ ├── consegna │ ├── Main.java │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── agenda │ │ │ ├── Date.java │ │ │ ├── Event.java │ │ │ ├── ItalianDate.java │ │ │ └── QuarterDate.java │ └── risultato_main.txt │ └── soluzione │ ├── Main.java │ └── it │ └── univr │ └── agenda │ ├── Date.java │ ├── Event.java │ ├── ItalianDate.java │ └── QuarterDate.java ├── 2019-02-18 ├── v1 │ ├── consegna │ │ ├── Main.java │ │ ├── compito.pdf │ │ ├── compito.tex │ │ ├── it │ │ │ └── univr │ │ │ │ └── library │ │ │ │ ├── AudioBook.java │ │ │ │ ├── Book.java │ │ │ │ ├── Catalog.java │ │ │ │ ├── CatalogWithStatistics.java │ │ │ │ ├── Genre.java │ │ │ │ └── PaperBook.java │ │ └── risultato_main.txt │ └── soluzione │ │ ├── Main.java │ │ └── it │ │ └── univr │ │ └── library │ │ ├── AudioBook.java │ │ ├── Book.java │ │ ├── Catalog.java │ │ ├── CatalogWithStatistics.java │ │ ├── Genre.java │ │ └── PaperBook.java └── v2 │ ├── consegna │ ├── Main.java │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── library │ │ │ ├── AudioBook.java │ │ │ ├── Book.java │ │ │ ├── Catalog.java │ │ │ ├── CatalogWithStatistics.java │ │ │ ├── Genre.java │ │ │ └── PaperBook.java │ └── risultato_main.txt │ └── soluzione │ ├── Main.java │ └── it │ └── univr │ └── library │ ├── AudioBook.java │ ├── Book.java │ ├── Catalog.java │ ├── CatalogWithStatistics.java │ ├── Genre.java │ └── PaperBook.java ├── 2019-06-24 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── tictactoe │ │ │ ├── Main.java │ │ │ ├── Player.java │ │ │ └── TicTacToe.java │ ├── risultato_main.txt │ ├── tictactoe_draw.png │ ├── tictactoe_grid_linear.png │ └── tictactoe_wins.png └── soluzione │ └── it │ └── univr │ └── tictactoe │ ├── FullTicTacToe.java │ ├── Main.java │ ├── Player.java │ ├── RowsTicTacToe.java │ ├── SimpleTicTacToe.java │ └── TicTacToe.java ├── 2019-07-25 ├── consegna │ ├── 1984.txt │ ├── Main.java │ ├── Words.java │ ├── animal_farm.txt │ ├── compito.pdf │ ├── compito.tex │ ├── project.png │ └── try_this.txt └── soluzione │ ├── Main.java │ └── Words.java ├── 2019-09-26 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── g1.pdf │ ├── g2.pdf │ ├── it │ │ └── univr │ │ │ └── graph │ │ │ ├── Graph.java │ │ │ └── Main.java │ └── output.txt └── soluzione │ └── it │ └── univr │ └── graph │ ├── Graph.java │ └── Main.java ├── 2020-02-05 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── cards │ │ │ ├── Card.java │ │ │ ├── Deck.java │ │ │ ├── Main.java │ │ │ ├── Ranking.java │ │ │ ├── Suit.java │ │ │ └── Value.java │ └── stampa.txt └── soluzione │ └── it │ └── univr │ └── cards │ ├── Card.java │ ├── Deck.java │ ├── Main.java │ ├── Ranking.java │ ├── Suit.java │ └── Value.java ├── 2021-04-30 ├── esame_1 │ ├── it │ │ └── univr │ │ │ └── insurance │ │ │ └── Season.java │ └── module-info.java ├── esame_1_soluzione │ ├── it │ │ └── univr │ │ │ └── insurance │ │ │ └── Season.java │ └── module-info.java ├── esame_2 │ ├── it │ │ └── univr │ │ │ └── insurance │ │ │ └── Insurance.java │ └── module-info.java └── esame_2_soluzione │ ├── it │ └── univr │ │ └── insurance │ │ └── Insurance.java │ └── module-info.java ├── 2021-06-17 ├── consegna │ ├── Book.java │ ├── Library.java │ └── Main.java └── soluzione │ ├── Book.java │ ├── Library.java │ ├── LibraryBySize.java │ ├── LibraryEnglishFirst.java │ └── Main.java ├── 2021-07-20 ├── consegna │ └── Bank.java └── soluzione │ ├── Bank.java │ ├── BankException.java │ ├── BankWithMinimum.java │ └── SimpleBank.java ├── 2021-09-01 ├── consegna │ ├── Date.java │ ├── Dates.java │ └── Main.java └── soluzione │ ├── Date.java │ ├── Dates.java │ └── Main.java ├── 2022-02-02 ├── v1 │ ├── consegna │ │ ├── compito-v1.pdf │ │ ├── compito-v1.tex │ │ └── it │ │ │ └── univr │ │ │ └── identifiers │ │ │ ├── CamelStyleIdentifier.java │ │ │ ├── Identifier.java │ │ │ ├── Main.java │ │ │ ├── MultiWordIdentifier.java │ │ │ └── SnakeStyleIdentifier.java │ └── soluzione │ │ └── it │ │ └── univr │ │ └── identifiers │ │ ├── CamelStyleIdentifier.java │ │ ├── Identifier.java │ │ ├── Main.java │ │ ├── MultiWordIdentifier.java │ │ └── SnakeStyleIdentifier.java ├── v2 │ ├── consegna │ │ ├── compito-v2.pdf │ │ ├── compito-v2.tex │ │ └── it │ │ │ └── univr │ │ │ └── identifiers │ │ │ ├── Identifier.java │ │ │ ├── Main.java │ │ │ ├── MultiWordIdentifier.java │ │ │ ├── SnakeStyleIdentifier.java │ │ │ └── VowelStyleIdentifier.java │ └── soluzione │ │ └── it │ │ └── univr │ │ └── identifiers │ │ ├── Identifier.java │ │ ├── Main.java │ │ ├── MultiWordIdentifier.java │ │ ├── SnakeStyleIdentifier.java │ │ └── VowelStyleIdentifier.java └── v3 │ ├── consegna │ ├── compito-v3.pdf │ ├── compito-v3.tex │ └── it │ │ └── univr │ │ └── identifiers │ │ ├── Identifier.java │ │ ├── Main.java │ │ ├── MultiWordIdentifier.java │ │ ├── SnakeStyleIdentifier.java │ │ └── ThreeStyleIdentifier.java │ └── soluzione │ └── it │ └── univr │ └── identifiers │ ├── Identifier.java │ ├── Main.java │ ├── MultiWordIdentifier.java │ ├── SnakeStyleIdentifier.java │ └── ThreeStyleIdentifier.java ├── 2022-03-04 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── supermarket │ │ │ ├── Main.java │ │ │ ├── Product.java │ │ │ ├── ProductNotExpiring.java │ │ │ ├── ProductWithExpiration.java │ │ │ └── Supermarket.java │ └── stampa.txt └── soluzione │ └── it │ └── univr │ └── supermarket │ ├── Main.java │ ├── Product.java │ ├── ProductNotExpiring.java │ ├── ProductWithExpiration.java │ └── Supermarket.java ├── 2022-06-16 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── dadi │ │ │ ├── Dado.java │ │ │ ├── Lanci.java │ │ │ ├── LanciBarreDiverse.java │ │ │ └── Main.java │ └── stampa.txt └── soluzione │ └── it │ └── univr │ └── dadi │ ├── D10.java │ ├── D6.java │ ├── D8.java │ ├── Dado.java │ ├── Lanci.java │ ├── LanciBarreDiverse.java │ └── Main.java ├── 2022-07-05 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── elezioni │ │ ├── Elezioni.java │ │ ├── ElezioniVincitore.java │ │ ├── Main.java │ │ ├── Partito.java │ │ └── VotiPerPartito.java └── soluzione │ └── it │ └── univr │ └── elezioni │ ├── Elezioni.java │ ├── ElezioniVincitore.java │ ├── Main.java │ ├── Partito.java │ └── VotiPerPartito.java ├── 2022-09-02 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── letters │ │ ├── Letters.java │ │ ├── LowerCase.java │ │ ├── Main.java │ │ └── Vulcanian.java └── soluzione │ └── it │ └── univr │ └── letters │ ├── Letters.java │ ├── LowerCase.java │ ├── Main.java │ └── Vulcanian.java ├── 2023-02-09 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── doodle │ │ ├── Doodle.java │ │ ├── Main.java │ │ ├── Person.java │ │ └── Slot.java └── soluzione │ └── it │ └── univr │ └── doodle │ ├── CEO.java │ ├── CTO.java │ ├── Doodle.java │ ├── Main.java │ ├── Person.java │ ├── Programmer.java │ ├── Secretary.java │ ├── Slot.java │ └── WeightedDoodle.java ├── 2023-02-24 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── quindici │ │ ├── FattoriaDiTessere.java │ │ ├── Gioco.java │ │ ├── Main.java │ │ └── Tessera.java └── soluzione │ └── it │ └── univr │ └── quindici │ ├── FattoriaDiTessere.java │ ├── FattoriaDiTessereAlfabetiche.java │ ├── FattoriaDiTessereNumeriche.java │ ├── Gioco.java │ ├── Main.java │ └── Tessera.java ├── 2023-07-05 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── sets │ │ ├── Main.java │ │ └── PunishableSet.java └── soluzione │ └── it │ └── univr │ └── sets │ ├── Main.java │ └── PunishableSet.java ├── 2023-09-29 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── instructions │ │ ├── Instruction.java │ │ ├── Machine.java │ │ ├── Main.java │ │ ├── POP.java │ │ └── SimpleMachine.java └── soluzione │ └── it │ └── univr │ └── instructions │ ├── ADD.java │ ├── DIV.java │ ├── IllegalProgramException.java │ ├── Instruction.java │ ├── MUL.java │ ├── Machine.java │ ├── Main.java │ ├── POP.java │ ├── PUSH.java │ ├── PrintingMachine.java │ ├── REPEAT.java │ ├── SUB.java │ └── SimpleMachine.java ├── 2024-02-01 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── sudoku │ │ │ ├── Emoji.java │ │ │ ├── Main.java │ │ │ └── Sudoku.java │ ├── print.png │ └── sudoku.png └── soluzione │ └── it │ └── univr │ └── sudoku │ ├── Emoji.java │ ├── Main.java │ └── Sudoku.java ├── 2024-02-16 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ ├── it │ │ └── univr │ │ │ └── prefix │ │ │ ├── Main.java │ │ │ └── PrefixMap.java │ ├── tree.fig │ └── tree.pdf └── soluzione │ └── it │ └── univr │ └── prefix │ ├── Main.java │ └── PrefixMap.java ├── 2024-06-20 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── file │ │ ├── AbstractComponent.java │ │ ├── Component.java │ │ ├── DirectoryComponent.java │ │ ├── FileComponent.java │ │ └── MainFiles.java └── soluzione │ └── it │ └── univr │ └── file │ ├── AbstractComponent.java │ ├── Component.java │ ├── DirectoryComponent.java │ ├── FileComponent.java │ └── MainFiles.java ├── 2024-09-13 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── corso │ │ ├── Corso.java │ │ ├── Esame.java │ │ ├── MainEsame.java │ │ ├── Studente.java │ │ └── StudenteLavoratore.java └── soluzione │ └── it │ └── univr │ └── corso │ ├── Corso.java │ ├── Esame.java │ ├── MainEsame.java │ ├── Studente.java │ ├── StudenteIllegaleException.java │ └── StudenteLavoratore.java ├── 2025-02-05 ├── consegna │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── time │ │ ├── AbstractTime.java │ │ ├── AmericanTime.java │ │ ├── Interval.java │ │ ├── ItalianTime.java │ │ ├── Main.java │ │ └── Time.java └── soluzione │ └── it │ └── univr │ └── time │ ├── AbstractTime.java │ ├── AmericanTime.java │ ├── Interval.java │ ├── ItalianTime.java │ ├── Main.java │ └── Time.java ├── 2025-02-20 ├── consegna │ ├── compito-eng.pdf │ ├── compito-eng.tex │ ├── compito.pdf │ ├── compito.tex │ └── it │ │ └── univr │ │ └── notes │ │ ├── AbstractNote.java │ │ ├── AbstractSong.java │ │ ├── BasicSong.java │ │ ├── EnglishNote.java │ │ ├── ItalianNote.java │ │ ├── Main.java │ │ ├── Note.java │ │ ├── Scale.java │ │ └── Song.java └── soluzione │ └── it │ └── univr │ └── notes │ ├── AbstractNote.java │ ├── AbstractSong.java │ ├── BasicSong.java │ ├── EnglishNote.java │ ├── IllegalNoteException.java │ ├── ItalianNote.java │ ├── Main.java │ ├── Note.java │ ├── Scale.java │ └── Song.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *~ 3 | 4 | # Package Files # 5 | *.jar 6 | *.war 7 | *.ear 8 | -------------------------------------------------------------------------------- /2012-02-06/Command.java: -------------------------------------------------------------------------------- 1 | package it.univr.television; 2 | 3 | public interface Command { 4 | public void execute(); 5 | } -------------------------------------------------------------------------------- /2012-02-06/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-02-06/compito.pdf -------------------------------------------------------------------------------- /2012-02-24/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-02-24/compito.pdf -------------------------------------------------------------------------------- /2012-06-18/SecondDegreePolynomial.java: -------------------------------------------------------------------------------- 1 | // un polinomio del tipo ax^2 + bx + c 2 | public final class SecondDegreePolynomial extends Polynomial { 3 | 4 | public SecondDegreePolynomial(int a, int b, int c) { 5 | super(new int[] { a, b, c}); 6 | 7 | if (a == 0) 8 | throw new IllegalArgumentException("first coefficient cannot be 0"); 9 | } 10 | 11 | public boolean canBe0() { 12 | int[] coefficients = getCoefficients(); 13 | int a = coefficients[0]; 14 | int b = coefficients[1]; 15 | int c = coefficients[2]; 16 | 17 | return b * b - 4 * a * c >= 0; 18 | } 19 | } -------------------------------------------------------------------------------- /2012-06-18/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-06-18/compito.pdf -------------------------------------------------------------------------------- /2012-07-06/DuplicatedSampleException.java: -------------------------------------------------------------------------------- 1 | 2 | public class DuplicatedSampleException extends Exception { 3 | public DuplicatedSampleException(String message) { 4 | super(message); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /2012-07-06/InconsistentSampleSizeException.java: -------------------------------------------------------------------------------- 1 | 2 | public class InconsistentSampleSizeException extends Exception { 3 | public InconsistentSampleSizeException(int size) { 4 | super(String.valueOf(size)); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /2012-07-06/SequentialPlot.java: -------------------------------------------------------------------------------- 1 | 2 | public class SequentialPlot extends Plot { 3 | 4 | @Override 5 | public String toString() { 6 | String result = ""; 7 | String chars = "*@$"; 8 | int choice = 0; 9 | 10 | for (Sample sample: getSamples()) { 11 | result += toStringSample(sample, chars.charAt(choice++)); 12 | choice = choice % chars.length(); 13 | } 14 | 15 | return result; 16 | } 17 | 18 | private String toStringSample(Sample sample, char c) { 19 | String result = sample.getName() + ":\n"; 20 | float max = getMax(); 21 | 22 | for (int pos = 0; pos < sample.getSize(); pos++) { 23 | float value = sample.getValue(pos); 24 | result += "| " + repeat((int) (value / max * 40f), c) + " (" + value + ")\n"; 25 | } 26 | 27 | result += "\n"; 28 | 29 | return result; 30 | } 31 | 32 | private String repeat(int numberOfTime, char c) { 33 | String result = ""; 34 | while (numberOfTime-- > 0) 35 | result += c; 36 | 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /2012-07-06/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-07-06/compito.pdf -------------------------------------------------------------------------------- /2012-09-03/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | Set s1 = new ArraySet("ciao", "amico", "come", "va?"); 5 | Set s2 = new ModifiableArraySet("oggi", "va?", 12, 113); 6 | 7 | System.out.println("1: " + s1.equals(s2)); 8 | System.out.println("2: " + s1.intersects(s2)); 9 | 10 | ModifiableSet s3 = new ModifiableArraySet("amico", "va?", "ciao", "va?"); 11 | s3.add("come"); 12 | s3.add(new String("ciao")); 13 | 14 | System.out.println("3: " + s1.equals(s3)); 15 | System.out.println("4: " + s1.intersects(s3)); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /2012-09-03/ModifiableSet.java: -------------------------------------------------------------------------------- 1 | public interface ModifiableSet extends Set { 2 | boolean add(Object element); 3 | boolean remove(Object element); 4 | boolean addAll(Set set); 5 | boolean removeAll(Set set); 6 | } -------------------------------------------------------------------------------- /2012-09-03/Set.java: -------------------------------------------------------------------------------- 1 | public interface Set extends Iterable { 2 | boolean contains(Object element); 3 | boolean intersects(Set other); 4 | int size(); 5 | } -------------------------------------------------------------------------------- /2012-09-03/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-09-03/compito.pdf -------------------------------------------------------------------------------- /2012-09-24/Concat.java: -------------------------------------------------------------------------------- 1 | import java.util.Iterator; 2 | 3 | // i numeri interi da una costante in poi 4 | public class Concat extends Numbers { 5 | 6 | private final Numbers first, second; 7 | 8 | public Concat(Numbers first, Numbers second) { 9 | this.first = first; 10 | this.second = second; 11 | } 12 | 13 | @Override 14 | public Iterator iterator() { 15 | return new Iterator() { 16 | 17 | private Iterator firstIterator = first.iterator(); 18 | private Iterator secondIterator = second.iterator(); 19 | 20 | @Override 21 | public boolean hasNext() { 22 | return firstIterator.hasNext() || secondIterator.hasNext(); 23 | } 24 | 25 | @Override 26 | public Integer next() { 27 | return firstIterator.hasNext() ? firstIterator.next() : secondIterator.next(); 28 | } 29 | 30 | @Override 31 | public void remove() { 32 | throw new UnsupportedOperationException(); 33 | } 34 | 35 | }; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /2012-09-24/From.java: -------------------------------------------------------------------------------- 1 | import java.util.Iterator; 2 | 3 | // i numeri interi da una costante in poi 4 | public class From extends Numbers { 5 | 6 | private final int start; 7 | 8 | public From(int start) { 9 | this.start = start; 10 | } 11 | 12 | @Override 13 | public Iterator iterator() { 14 | return new Iterator() { 15 | 16 | private int next = start; 17 | 18 | @Override 19 | public boolean hasNext() { 20 | return true; 21 | } 22 | 23 | @Override 24 | public Integer next() { 25 | return next++; 26 | } 27 | 28 | @Override 29 | public void remove() { 30 | throw new UnsupportedOperationException(); 31 | } 32 | 33 | }; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /2012-09-24/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | Numbers from8To25 = new UpTo(25, new From(8)); 6 | System.out.println(from8To25); 7 | Numbers from100To120 = new UpTo(120, new From(100)); 8 | System.out.println(from100To120); 9 | Numbers concat = new Concat(from8To25, from100To120); 10 | System.out.println(concat); 11 | Numbers alternate = new Alternate(from8To25, from100To120); 12 | System.out.println(alternate); 13 | System.out.println(new UpTo(100, alternate)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /2012-09-24/Numbers.java: -------------------------------------------------------------------------------- 1 | 2 | public abstract class Numbers implements Iterable { 3 | 4 | @Override 5 | public final String toString() { 6 | String result = ""; 7 | 8 | for (Integer i: this) 9 | result += i + " "; 10 | 11 | return result; 12 | } 13 | } -------------------------------------------------------------------------------- /2012-09-24/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2012-09-24/compito.pdf -------------------------------------------------------------------------------- /2013-02-04/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-02-04/compito.pdf -------------------------------------------------------------------------------- /2013-02-04/it/univr/elezioni/CoalizioneGiàPresenteException.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class CoalizioneGiàPresenteException extends IllegalArgumentException { 4 | public CoalizioneGiàPresenteException(Coalizione coalizione) { 5 | super(coalizione.getNome()); 6 | } 7 | } -------------------------------------------------------------------------------- /2013-02-04/it/univr/elezioni/Partito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class Partito { 4 | 5 | private final String nome; 6 | 7 | public Partito(String nome) { 8 | this.nome = nome; 9 | } 10 | 11 | public String getNome() { 12 | return nome; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object altro) { 17 | return altro instanceof Partito && ((Partito) altro).nome.equals(nome); 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return nome.hashCode(); 23 | } 24 | } -------------------------------------------------------------------------------- /2013-02-04/it/univr/elezioni/PartitoGiàRegistratoException.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class PartitoGiàRegistratoException extends IllegalArgumentException { 4 | public PartitoGiàRegistratoException(Partito partito) { 5 | super(partito.getNome()); 6 | } 7 | } -------------------------------------------------------------------------------- /2013-02-04/it/univr/elezioni/PartitoMaiRegistratoException.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class PartitoMaiRegistratoException extends IllegalArgumentException { 4 | public PartitoMaiRegistratoException(Partito partito) { 5 | super(partito.getNome()); 6 | } 7 | } -------------------------------------------------------------------------------- /2013-02-26/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-02-26/compito.pdf -------------------------------------------------------------------------------- /2013-02-26/it/univr/calendar/Calendar.java: -------------------------------------------------------------------------------- 1 | package it.univr.calendar; 2 | 3 | import java.util.Iterator; 4 | import java.util.SortedSet; 5 | import java.util.TreeSet; 6 | 7 | public class Calendar implements Iterable { 8 | 9 | private final SortedSet events = new TreeSet(); 10 | 11 | public void addEvent(Time startingTime, String name) { 12 | events.add(new Event(startingTime, name) { 13 | 14 | @Override 15 | public void delete() { 16 | events.remove(this); 17 | } 18 | 19 | }); 20 | } 21 | 22 | @Override 23 | public Iterator iterator() { 24 | // deleghiamo all'insieme degli eventi in calendario 25 | return events.iterator(); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | String result = ""; 31 | 32 | for (Event e: this) 33 | result += e + "\n"; 34 | 35 | return result; 36 | } 37 | } -------------------------------------------------------------------------------- /2013-02-26/it/univr/calendar/Event.java: -------------------------------------------------------------------------------- 1 | package it.univr.calendar; 2 | 3 | public abstract class Event implements Comparable { 4 | 5 | private final Time startingTime; 6 | 7 | private final String name; 8 | 9 | protected Event(Time startingTime, String name) { 10 | this.startingTime = startingTime; 11 | this.name = name; 12 | } 13 | 14 | public abstract void delete(); 15 | 16 | @Override 17 | public final String toString() { 18 | return name + " @ " + startingTime; 19 | } 20 | 21 | @Override 22 | public final int compareTo(Event other) { 23 | int result = startingTime.compareTo(other.startingTime); 24 | if (result == 0) 25 | result = name.compareTo(other.name); 26 | 27 | return result; 28 | } 29 | 30 | @Override 31 | public final boolean equals(Object other) { 32 | return other instanceof Event && ((Event) other).startingTime.equals(startingTime) 33 | && ((Event) other).name.equals(name); 34 | } 35 | 36 | @Override 37 | public final int hashCode() { 38 | return startingTime.hashCode() ^ name.hashCode(); 39 | } 40 | } -------------------------------------------------------------------------------- /2013-06-24/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-06-24/compito.pdf -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/AbstractCanzone.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public abstract class AbstractCanzone implements Canzone { 4 | 5 | @Override 6 | public final String toString() { 7 | String result = getNome() + ":\n"; 8 | for (Nota nota: this) 9 | result += nota + "\n"; 10 | 11 | return result; 12 | } 13 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/Canzone.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public interface Canzone extends Iterable { 4 | public String getNome(); 5 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/CanzoneImpl.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Iterator; 6 | 7 | public class CanzoneImpl extends AbstractCanzone { 8 | private final String nome; 9 | private final List note = new ArrayList(); 10 | 11 | public CanzoneImpl(String nome, Nota... note) { 12 | this.nome = nome; 13 | 14 | for (Nota nota: note) 15 | this.note.add(nota); 16 | } 17 | 18 | @Override 19 | public String getNome() { 20 | return nome; 21 | } 22 | 23 | @Override 24 | public Iterator iterator() { 25 | return note.iterator(); 26 | } 27 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/CanzoneRibasata.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | import java.util.Iterator; 4 | 5 | public class CanzoneRibasata extends AbstractCanzone { 6 | private final Canzone base; 7 | private final int inc; 8 | 9 | public CanzoneRibasata(Canzone base, int inc) { 10 | this.base = base; 11 | this.inc = inc; 12 | } 13 | 14 | @Override 15 | public Iterator iterator() { 16 | return new Iterator() { 17 | 18 | private final Iterator it = base.iterator(); 19 | 20 | @Override 21 | public boolean hasNext() { 22 | return it.hasNext(); 23 | } 24 | 25 | @Override 26 | public Nota next() { 27 | return it.next().incrementa(inc); 28 | } 29 | 30 | @Override 31 | public void remove() { 32 | throw new UnsupportedOperationException(); 33 | } 34 | }; 35 | } 36 | 37 | @Override 38 | public String getNome() { 39 | return base.getNome(); 40 | } 41 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Canzone boccaDiRosa = new CanzoneImpl("Bocca di Rosa", new NotaIT(11), new NotaIT(2), new NotaIT(3), new NotaIT(6)); 6 | Canzone letItBe = new CanzoneImpl("Let it be", new NotaUK(3), new NotaUK(5), new NotaUK(0)); 7 | 8 | System.out.println(boccaDiRosa); 9 | System.out.println(letItBe); 10 | System.out.println(new CanzoneRibasata(boccaDiRosa, 5)); 11 | System.out.println(new CanzoneRibasata(letItBe, 23)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/Nota.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public abstract class Nota { 4 | private final int semitono; 5 | 6 | protected Nota(int semitono) { 7 | if (semitono < 0 || semitono >= 12) 8 | throw new IllegalArgumentException("i semitoni vanno da 0 a 11"); 9 | 10 | this.semitono = semitono; 11 | } 12 | 13 | @Override 14 | public abstract String toString(); 15 | 16 | public abstract Nota incrementa(int inc); 17 | 18 | protected final int getSemitono() { 19 | return semitono; 20 | } 21 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/NotaIT.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public class NotaIT extends Nota { 4 | public NotaIT(int semitono) { 5 | super(semitono); 6 | } 7 | 8 | @Override 9 | public Nota incrementa(int inc) { 10 | return new NotaIT((getSemitono() + inc) % 12); 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return nome[getSemitono()]; 16 | } 17 | 18 | private final static String[] nome = { 19 | "do", "do#", "re", "re#", "mi", "fa", "fa#", "sol", "sol#", "la", "la#", "si" 20 | }; 21 | } -------------------------------------------------------------------------------- /2013-06-24/it/univr/musica/NotaUK.java: -------------------------------------------------------------------------------- 1 | package it.univr.musica; 2 | 3 | public class NotaUK extends Nota { 4 | public NotaUK(int semitono) { 5 | super(semitono); 6 | } 7 | 8 | @Override 9 | public Nota incrementa(int inc) { 10 | return new NotaUK((getSemitono() + inc) % 12); 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return nome[getSemitono()]; 16 | } 17 | 18 | private final static String[] nome = { 19 | "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" 20 | }; 21 | } -------------------------------------------------------------------------------- /2013-07-15/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-07-15/compito.pdf -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/Add.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Add extends Exp { 7 | 8 | private final Exp left, right; 9 | 10 | public Add(Exp left, Exp right) { 11 | this.left = left; 12 | this.right = right; 13 | } 14 | 15 | @Override 16 | protected int getNumericValue(Set seen) throws EvaluationException { 17 | return left.getNumericValue(new HashSet(seen)) + right.getNumericValue(new HashSet(seen)); 18 | } 19 | 20 | @Override 21 | protected String getStringValue(Set seen) throws EvaluationException { 22 | return String.valueOf(getNumericValue(seen)); 23 | } 24 | } -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/Append.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Append extends Exp { 7 | 8 | private final Exp left, right; 9 | 10 | public Append(Exp left, Exp right) { 11 | this.left = left; 12 | this.right = right; 13 | } 14 | 15 | @Override 16 | protected int getNumericValue(Set seen) throws EvaluationException { 17 | throw new EvaluationException("the value of append is not numeric"); 18 | } 19 | 20 | @Override 21 | protected String getStringValue(Set seen) throws EvaluationException { 22 | return left.getStringValue(new HashSet(seen)) + " " + right.getStringValue(new HashSet(seen)); 23 | } 24 | } -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/Cell.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.Set; 4 | 5 | public final class Cell extends Exp { 6 | private Exp exp; 7 | 8 | protected Cell() { 9 | this.exp = new StringConstant(""); 10 | } 11 | 12 | public void setExp(Exp exp) { 13 | this.exp = exp; 14 | } 15 | 16 | @Override 17 | protected int getNumericValue(Set seen) throws EvaluationException { 18 | if (!seen.add(this)) 19 | throw new CyclicEvaluationException(); 20 | 21 | return exp.getNumericValue(seen); 22 | } 23 | 24 | @Override 25 | protected String getStringValue(Set seen) throws EvaluationException { 26 | if (!seen.add(this)) 27 | throw new CyclicEvaluationException(); 28 | 29 | return exp.getStringValue(seen); 30 | } 31 | } -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/CyclicEvaluationException.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | public class CyclicEvaluationException extends EvaluationException { 4 | public CyclicEvaluationException() { 5 | super("the evaluation went into a loop"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/Div.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Div extends Exp { 7 | 8 | private final Exp left, right; 9 | 10 | public Div(Exp left, Exp right) { 11 | this.left = left; 12 | this.right = right; 13 | } 14 | 15 | @Override 16 | protected int getNumericValue(Set seen) throws EvaluationException { 17 | try { 18 | return left.getNumericValue(new HashSet(seen)) / right.getNumericValue(new HashSet(seen)); 19 | } 20 | catch (ArithmeticException e) { 21 | throw new EvaluationException("division by zero"); 22 | } 23 | } 24 | 25 | @Override 26 | protected String getStringValue(Set seen) throws EvaluationException { 27 | return String.valueOf(getNumericValue(seen)); 28 | } 29 | } -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/EvaluationException.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | public class EvaluationException extends RuntimeException { 4 | public EvaluationException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/Exp.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public abstract class Exp { 7 | public final int getNumericValue() throws EvaluationException { 8 | return getNumericValue(new HashSet()); 9 | } 10 | 11 | protected abstract int getNumericValue(Set seen) throws EvaluationException; 12 | 13 | public final String getStringValue() throws EvaluationException { 14 | return getStringValue(new HashSet()); 15 | } 16 | 17 | protected abstract String getStringValue(Set seen) throws EvaluationException; 18 | 19 | @Override 20 | public final String toString() { 21 | try { 22 | return getStringValue(); 23 | } 24 | catch (CyclicEvaluationException e) { 25 | return "@@@"; 26 | } 27 | catch (EvaluationException e) { 28 | return "###"; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/NumericConstant.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.Set; 4 | 5 | public class NumericConstant extends Exp { 6 | 7 | private final int value; 8 | 9 | public NumericConstant(int value) { 10 | this.value = value; 11 | } 12 | 13 | @Override 14 | protected int getNumericValue(Set seen) throws EvaluationException { 15 | return value; 16 | } 17 | 18 | @Override 19 | protected String getStringValue(Set seen) throws EvaluationException { 20 | return String.valueOf(getNumericValue(seen)); 21 | } 22 | } -------------------------------------------------------------------------------- /2013-07-15/it/univr/spreadsheet/StringConstant.java: -------------------------------------------------------------------------------- 1 | package it.univr.spreadsheet; 2 | 3 | import java.util.Set; 4 | 5 | public class StringConstant extends Exp { 6 | 7 | private final String value; 8 | 9 | public StringConstant(String value) { 10 | this.value = value; 11 | } 12 | 13 | @Override 14 | protected int getNumericValue(Set seen) throws EvaluationException { 15 | throw new EvaluationException(value + " is not numeric"); 16 | } 17 | 18 | @Override 19 | protected String getStringValue(Set seen) throws EvaluationException { 20 | return value; 21 | } 22 | } -------------------------------------------------------------------------------- /2013-09-02/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-09-02/compito.pdf -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/FattoriaDiTessere.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public interface FattoriaDiTessere { 4 | public Tessera mkRandom(); 5 | } -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/FattoriaDiTessereAlfabetiche.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | import java.util.Random; 4 | 5 | public class FattoriaDiTessereAlfabetiche implements FattoriaDiTessere { 6 | private final static Random random = new Random(); 7 | 8 | @Override 9 | public Tessera mkRandom() { 10 | return new TesseraAlfabetica(stringaRandom()); 11 | } 12 | 13 | private final static String stringaRandom() { 14 | int len = 1 + random.nextInt(5); 15 | String s = ""; 16 | while (len-- > 0) 17 | s += (char) ('a' + random.nextInt(26)); 18 | 19 | return s; 20 | } 21 | } -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/FattoriaDiTessereNumeriche.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | import java.util.Random; 4 | 5 | public class FattoriaDiTessereNumeriche implements FattoriaDiTessere { 6 | private final static Random random = new Random(); 7 | private final int max; 8 | 9 | public FattoriaDiTessereNumeriche(int max) { 10 | this.max = max; 11 | } 12 | 13 | @Override 14 | public Tessera mkRandom() { 15 | return new TesseraNumerica(1 + random.nextInt(max)); 16 | } 17 | } -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Gioco gioco = new Gioco(new FattoriaDiTessereAlfabetiche(), 4, 4); 6 | System.out.println(gioco); 7 | 8 | FattoriaDiTessere f = new FattoriaDiTessereNumeriche(8); 9 | do { 10 | gioco = new Gioco(f, 3, 2); 11 | System.out.println(gioco); 12 | } 13 | while (!gioco.risolto()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/Tessera.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public abstract class Tessera implements Comparable { 4 | 5 | @Override 6 | public abstract boolean equals(Object other); 7 | 8 | @Override 9 | public abstract int hashCode(); 10 | 11 | @Override 12 | public abstract String toString(); 13 | } -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/TesseraAlfabetica.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public final class TesseraAlfabetica extends Tessera { 4 | 5 | private final String s; 6 | 7 | TesseraAlfabetica(String s) { 8 | this.s = s; 9 | } 10 | 11 | @Override 12 | public boolean equals(Object other) { 13 | return other instanceof TesseraAlfabetica && ((TesseraAlfabetica) other).s.equals(s); 14 | } 15 | 16 | @Override 17 | public int hashCode() { 18 | return s.hashCode(); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return s; 24 | } 25 | 26 | @Override 27 | public int compareTo(Tessera o) { 28 | return s.compareTo(((TesseraAlfabetica) o).s); 29 | } 30 | } -------------------------------------------------------------------------------- /2013-09-02/it/univr/quindici/TesseraNumerica.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public final class TesseraNumerica extends Tessera { 4 | 5 | private final int num; 6 | 7 | TesseraNumerica(int num) { 8 | this.num = num; 9 | } 10 | 11 | @Override 12 | public boolean equals(Object other) { 13 | return other instanceof TesseraNumerica && ((TesseraNumerica) other).num == num; 14 | } 15 | 16 | @Override 17 | public int hashCode() { 18 | return num; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return String.valueOf(num); 24 | } 25 | 26 | @Override 27 | public int compareTo(Tessera o) { 28 | return num - ((TesseraNumerica) o).num; 29 | } 30 | } -------------------------------------------------------------------------------- /2013-09-27/classi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-09-27/classi.pdf -------------------------------------------------------------------------------- /2013-09-27/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2013-09-27/compito.pdf -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/AbstractNumero.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public abstract class AbstractNumero implements Numero { 4 | 5 | private int value; 6 | 7 | protected AbstractNumero(int value) { 8 | if (value < 0) 9 | throw new ArithmeticException("valore negativo"); 10 | 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public final int getValue() { 16 | return value; 17 | } 18 | 19 | @Override 20 | public final void aggiungi(Numero n) { 21 | value += n.getValue(); 22 | } 23 | 24 | @Override 25 | public final void sottrai(Numero n) { 26 | if (value >= n.getValue()) 27 | value -= n.getValue(); 28 | else 29 | throw new ArithmeticException("risultato negativo"); 30 | } 31 | 32 | @Override 33 | public final int compareTo(Numero o) { 34 | return value - o.getValue(); 35 | } 36 | 37 | @Override 38 | public final boolean equals(Object other) { 39 | return other instanceof Numero && value == ((Numero) other).getValue(); 40 | } 41 | 42 | @Override 43 | public final int hashCode() { 44 | return value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/Numero.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public interface Numero extends Comparable { 4 | public int getValue(); 5 | public void aggiungi(Numero n); 6 | public void sottrai(Numero n); 7 | } 8 | -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/NumeroBCD.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public class NumeroBCD extends AbstractNumero { 4 | 5 | public NumeroBCD(int value) { 6 | super(value); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | String s = ""; 12 | int value = getValue(); 13 | 14 | do { 15 | for (int i = 0, cifra = value % 10; i < 4; i++, cifra /= 2) 16 | s = cifra % 2 + s; 17 | 18 | value /= 10; 19 | } 20 | while (value > 0); 21 | 22 | return s; 23 | } 24 | } -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/NumeroInBase.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public abstract class NumeroInBase extends AbstractNumero { 4 | private final int base; 5 | 6 | protected NumeroInBase(int value, int base) { 7 | super(value); 8 | 9 | if (base < 2 || base > 16) 10 | throw new ArithmeticException("La base deve essere fra 2 e 16"); 11 | 12 | this.base = base; 13 | } 14 | 15 | public final int getBase() { 16 | return base; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/NumeroInBaseDue.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public class NumeroInBaseDue extends NumeroInBase { 4 | 5 | public NumeroInBaseDue(int value) { 6 | super(value, 2); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | String s = ""; 12 | int value = getValue(); 13 | 14 | do { 15 | s = value % 2 + s; 16 | value /= 2; 17 | } 18 | while (value > 0); 19 | 20 | return s; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2013-09-27/it/univr/numeri/NumeroInBaseSedici.java: -------------------------------------------------------------------------------- 1 | package it.univr.numeri; 2 | 3 | public class NumeroInBaseSedici extends NumeroInBase { 4 | 5 | public NumeroInBaseSedici(int value) { 6 | super(value, 16); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | String s = ""; 12 | int value = getValue(); 13 | 14 | do { 15 | s = cifra(value % 16) + s; 16 | value /= 16; 17 | } 18 | while (value > 0); 19 | 20 | return s; 21 | } 22 | 23 | private static char cifra(int n) { 24 | if (n < 10) 25 | return (char) ('0' + n); 26 | else 27 | return (char) ('a' + n - 10); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2014-02-07/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2014-02-07/compito.pdf -------------------------------------------------------------------------------- /2014-02-07/it/univr/freebay/Buy2Take3Product.java: -------------------------------------------------------------------------------- 1 | package it.univr.freebay; 2 | 3 | public class Buy2Take3Product extends Product { 4 | 5 | private final Product original; 6 | 7 | public Buy2Take3Product(Product original) { 8 | super(original); 9 | 10 | if (!original.canBeReduced()) 11 | throw new IllegalArgumentException("cannot reduce the price of " + original); 12 | 13 | this.original = original; 14 | } 15 | 16 | @Override 17 | public boolean canBeReduced() { 18 | // non ammettiamo sconti su queste offerte! 19 | return false; 20 | } 21 | 22 | @Override 23 | public double getPrice(Cart cart) { 24 | // contiamo quanti prodotti uguali a questo ci sono nel carrello 25 | int count = 0; 26 | for (Product product: cart) 27 | if (product == this) 28 | count++; 29 | 30 | // uno gratis ogni tre 31 | int gratis = count / 3; 32 | 33 | // ne paghiamo (count - gratis) e ne otteniamo count. Quindi ognuno costa: 34 | return original.getPrice(cart) * (count - gratis) / count; 35 | } 36 | } -------------------------------------------------------------------------------- /2014-02-07/it/univr/freebay/Cart.java: -------------------------------------------------------------------------------- 1 | package it.univr.freebay; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | public class Cart implements Iterable { 8 | 9 | private final List products = new ArrayList(); 10 | 11 | public void addProduct(Product product) { 12 | products.add(product); 13 | } 14 | 15 | public void addProducts(Product... products) { 16 | for (Product product: products) 17 | addProduct(product); 18 | } 19 | 20 | public void addProduct(Product product, int howManyTimes) { 21 | for (int counter = 1; counter <= howManyTimes; counter++) 22 | addProduct(product); 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | String result = ""; 28 | 29 | for (Product product: this) 30 | result += product + " " + String.format("%.2f euro", product.getPrice(this)) + ". Venduto da " + product.getSeller() + "\n"; 31 | 32 | return result; 33 | } 34 | 35 | @Override 36 | public Iterator iterator() { 37 | return products.iterator(); 38 | } 39 | } -------------------------------------------------------------------------------- /2014-02-07/it/univr/freebay/DiscountedProduct.java: -------------------------------------------------------------------------------- 1 | package it.univr.freebay; 2 | 3 | public class DiscountedProduct extends Product { 4 | 5 | private final Product original; 6 | 7 | private final double discount; 8 | 9 | public DiscountedProduct(Product original, double discount) { 10 | super(original); 11 | 12 | if (!original.canBeReduced()) 13 | throw new IllegalArgumentException("cannot reduce the price of " + original); 14 | 15 | this.discount = discount; 16 | this.original = original; 17 | } 18 | 19 | @Override 20 | public double getPrice(Cart cart) { 21 | return original.getPrice(cart) * (100 - discount) / 100; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return original.toString() + String.format(" [scontato del %.2f%%]", discount); 27 | } 28 | } -------------------------------------------------------------------------------- /2014-02-07/it/univr/freebay/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.freebay; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Cart cart = new Cart(); 7 | 8 | Product tv = new Product("Super Baffo", "TV al plasma", 589.99); 9 | Product cd = new Product("Roberto Malandrino", "CD di Laura Masini", 0.89); 10 | Product modem = new Product("Giorgio Rubacchioni", "modem ADSL", 30.40); 11 | 12 | cart.addProduct(tv); 13 | cart.addProducts(modem, cd); 14 | cart.addProduct(new DiscountedProduct(tv, 13.5)); 15 | cart.addProduct(new DiscountedProduct(new DiscountedProduct(modem, 11.6), 15.9)); 16 | cart.addProduct(tv, 2); 17 | 18 | // un cd offerto come prendi due e paghi tre! 19 | Product specialOffer = new Buy2Take3Product(cd); 20 | // ne compriamo sette esemplari 21 | cart.addProduct(specialOffer, 7); 22 | 23 | System.out.println(cart); 24 | 25 | // non possono scontare un 3 per 2: otterro' un'eccezione a questo punto 26 | cart.addProduct(new DiscountedProduct(specialOffer, 21.00)); 27 | } 28 | } -------------------------------------------------------------------------------- /2014-02-07/it/univr/freebay/Product.java: -------------------------------------------------------------------------------- 1 | package it.univr.freebay; 2 | 3 | public class Product { 4 | 5 | private final String seller; 6 | 7 | private final String name; 8 | 9 | private final double price; 10 | 11 | public Product(String seller, String name, double price) { 12 | this.seller = seller; 13 | this.name = name; 14 | this.price = price; 15 | } 16 | 17 | protected Product(Product original) { 18 | this(original.seller, original.name, original.price); 19 | } 20 | 21 | public final String getSeller() { 22 | return seller; 23 | } 24 | 25 | public final String getName() { 26 | return name; 27 | } 28 | 29 | public double getPrice(Cart cart) { 30 | return price; 31 | } 32 | 33 | public boolean canBeReduced() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return getName(); 40 | } 41 | } -------------------------------------------------------------------------------- /2014-02-28/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2014-02-28/compito.pdf -------------------------------------------------------------------------------- /2014-02-28/it/univr/cartellone/Cartellone.java: -------------------------------------------------------------------------------- 1 | package it.univr.cartellone; 2 | 3 | public abstract class Cartellone implements Iterable { 4 | 5 | @Override 6 | public final String toString() { 7 | String result = ""; 8 | 9 | for (Train train: this) 10 | result += train + "\n"; 11 | 12 | return result; 13 | } 14 | } -------------------------------------------------------------------------------- /2014-02-28/it/univr/cartellone/CartelloneLimitato.java: -------------------------------------------------------------------------------- 1 | package it.univr.cartellone; 2 | 3 | import java.util.Iterator; 4 | 5 | public class CartelloneLimitato extends Cartellone { 6 | 7 | private final Cartellone original; 8 | private final int max; 9 | 10 | public CartelloneLimitato(Cartellone original, int max) { 11 | this.original = original; 12 | this.max = max; 13 | } 14 | 15 | @Override 16 | public Iterator iterator() { 17 | return new Iterator() { 18 | 19 | private int count; 20 | private final Iterator originalIterator = original.iterator(); 21 | 22 | @Override 23 | public boolean hasNext() { 24 | return count < max && originalIterator.hasNext(); 25 | } 26 | 27 | @Override 28 | public Train next() { 29 | count++; 30 | return originalIterator.next(); 31 | } 32 | 33 | @Override 34 | public void remove() {} // non usata 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /2014-02-28/it/univr/cartellone/CartelloneModificabile.java: -------------------------------------------------------------------------------- 1 | package it.univr.cartellone; 2 | 3 | import java.util.Iterator; 4 | import java.util.SortedSet; 5 | import java.util.TreeSet; 6 | 7 | public class CartelloneModificabile extends Cartellone { 8 | 9 | private final SortedSet trains = new TreeSet(); 10 | 11 | public CartelloneModificabile() { 12 | } 13 | 14 | public void add(Train train) { 15 | trains.add(train); 16 | } 17 | 18 | public void add(Iterable trains) { 19 | for (Train train: trains) 20 | add(train); 21 | } 22 | 23 | public void add(Train... trains) { 24 | for (Train train: trains) 25 | add(train); 26 | } 27 | 28 | @Override 29 | public Iterator iterator() { 30 | return trains.iterator(); 31 | } 32 | } -------------------------------------------------------------------------------- /2014-02-28/it/univr/cartellone/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.cartellone; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | CartelloneModificabile c = new CartelloneModificabile(); 7 | 8 | // treno 1549 per Venezia delle 10:30 del 28/2/2014 9 | c.add(new Train(new Time(2014, 28, 2, 10, 30), 1549, "Venezia")); 10 | 11 | // treno 1804 per Bologna delle 11:45 del 28/2/2014 12 | c.add(new Train(new Time(2014, 28, 2, 11, 45), 1804, "Bologna")); 13 | 14 | // treno 1802 per Milano delle 11:45 del 28/2/2014 15 | c.add(new Train(new Time(2014, 28, 2, 11, 45), 1802, "Milano")); 16 | 17 | // treno 211 per Trieste delle 12:01 del 28/2/2014 18 | c.add(new Train(new Time(2014, 28, 2, 12, 01), 211, "Trieste")); 19 | 20 | // treno 1561 per Venezia delle 11:59 del 28/2/2014 21 | c.add(new Train(new Time(2014, 28, 2, 11, 59), 1561, "Venezia")); 22 | 23 | System.out.println(c); 24 | 25 | Cartellone lim = new CartelloneLimitato(c, 3); 26 | 27 | System.out.println("\nI prossimi 3 treni"); 28 | System.out.println(lim); 29 | } 30 | } -------------------------------------------------------------------------------- /2014-02-28/it/univr/cartellone/Train.java: -------------------------------------------------------------------------------- 1 | package it.univr.cartellone; 2 | 3 | public class Train implements Comparable { 4 | private final Time time; 5 | private final int number; 6 | private final String destination; 7 | 8 | public Train(Time time, int number, String destination) { 9 | this.time = time; 10 | this.number = number; 11 | this.destination = destination; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.format("%s : treno %d per %s", time.toStringOnlyHour(), number, destination); 17 | } 18 | 19 | @Override 20 | public int compareTo(Train other) { 21 | int diff = time.compareTo(other.time); 22 | if (diff != 0) 23 | return diff; 24 | 25 | // a parità di orario di partenza, li ordiniamo per numero di treno crescente 26 | return number - other.number; 27 | } 28 | } -------------------------------------------------------------------------------- /2014-07-14/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2014-07-14/compito.pdf -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/CamelStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class CamelStyleIdentifier extends AbstractMultiWordsIdentifier { 4 | 5 | public CamelStyleIdentifier(String... words) throws NoWordsProvidedException, WordIsNotAlphabeticalLowercaseException, EmptyWordException { 6 | super(words); 7 | } 8 | 9 | public CamelStyleIdentifier(Iterable words) throws NoWordsProvidedException, WordIsNotAlphabeticalLowercaseException, EmptyWordException { 10 | super(words); 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | String result = ""; 16 | for (String word: getWords()) 17 | result += Character.toUpperCase(word.charAt(0)) + word.substring(1); 18 | 19 | return result; 20 | } 21 | } -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/EmptyWordException.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class EmptyWordException extends IllegalArgumentException { 4 | 5 | public EmptyWordException() { 6 | super("An empty word has been provided"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | @Override 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/NegativeProgressiveNumberException.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class NegativeProgressiveNumberException extends IllegalArgumentException { 4 | 5 | public NegativeProgressiveNumberException(int num) { 6 | super("Negative progressive nmber provided: " + num); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/NoWordsProvidedException.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class NoWordsProvidedException extends IllegalArgumentException { 4 | 5 | public NoWordsProvidedException() { 6 | super("No word has been specified"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/ProgressiveIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class ProgressiveIdentifier implements Identifier { 4 | 5 | private final Identifier base; 6 | private final int num; 7 | 8 | public ProgressiveIdentifier(Identifier base, int num) throws NegativeProgressiveNumberException { 9 | if (num < 0) 10 | throw new NegativeProgressiveNumberException(num); 11 | 12 | this.base = base; 13 | this.num = num; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return base + "_" + num; 19 | } 20 | } -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class SnakeStyleIdentifier extends AbstractMultiWordsIdentifier { 4 | 5 | public SnakeStyleIdentifier(String... words) throws NoWordsProvidedException, WordIsNotAlphabeticalLowercaseException, EmptyWordException { 6 | super(words); 7 | } 8 | 9 | public SnakeStyleIdentifier(Iterable words) throws NoWordsProvidedException, WordIsNotAlphabeticalLowercaseException, EmptyWordException { 10 | super(words); 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | String result = ""; 16 | for (String word: getWords()) 17 | result += word + "_"; 18 | 19 | return result.substring(0, result.length() - 1); 20 | } 21 | } -------------------------------------------------------------------------------- /2014-07-14/it/univr/identifiers/WordIsNotAlphabeticalLowercaseException.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class WordIsNotAlphabeticalLowercaseException extends IllegalArgumentException { 4 | 5 | public WordIsNotAlphabeticalLowercaseException(String word) { 6 | super("Word " + word + " contains a non-lowercase or non-alphabetical word"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2014-09-15/Main.java: -------------------------------------------------------------------------------- 1 | import it.univr.tokenizer.DoubleTokenization; 2 | import it.univr.tokenizer.StringTokenization; 3 | import it.univr.tokenizer.Tokenization; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Tokenization tok = new StringTokenization("Questa$e'&una&prova!", "$&"); 9 | for (String s: tok) 10 | System.out.println(s); 11 | 12 | Tokenization tok2 = new DoubleTokenization(tok, "ou"); 13 | for (String s: tok2) 14 | System.out.println(s); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2014-09-15/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2014-09-15/compito.pdf -------------------------------------------------------------------------------- /2014-09-15/it/univr/tokenizer/CharacterTokenization.java: -------------------------------------------------------------------------------- 1 | package it.univr.tokenizer; 2 | 3 | public class CharacterTokenization extends StringTokenization { 4 | 5 | public CharacterTokenization(String s, char c) { 6 | super(s, String.valueOf(c)); 7 | } 8 | } -------------------------------------------------------------------------------- /2014-09-15/it/univr/tokenizer/NoDelimitersException.java: -------------------------------------------------------------------------------- 1 | package it.univr.tokenizer; 2 | 3 | public class NoDelimitersException extends RuntimeException { 4 | public NoDelimitersException() { 5 | super("no delimiters specified"); 6 | } 7 | } -------------------------------------------------------------------------------- /2014-09-15/it/univr/tokenizer/SpaceTokenization.java: -------------------------------------------------------------------------------- 1 | package it.univr.tokenizer; 2 | 3 | public class SpaceTokenization extends CharacterTokenization { 4 | 5 | public SpaceTokenization(String s) { 6 | super(s, ' '); 7 | } 8 | } -------------------------------------------------------------------------------- /2014-09-15/it/univr/tokenizer/Tokenization.java: -------------------------------------------------------------------------------- 1 | package it.univr.tokenizer; 2 | 3 | public interface Tokenization extends Iterable { 4 | } -------------------------------------------------------------------------------- /2015-02-02/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-02-02/compito.pdf -------------------------------------------------------------------------------- /2015-02-02/it/univr/paranoid/AppAlreadyInstalledException.java: -------------------------------------------------------------------------------- 1 | package it.univr.paranoid; 2 | 3 | public class AppAlreadyInstalledException extends RuntimeException { 4 | 5 | public AppAlreadyInstalledException() { 6 | super("This app is already installed"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2015-02-02/it/univr/paranoid/AppNotSupportedException.java: -------------------------------------------------------------------------------- 1 | package it.univr.paranoid; 2 | 3 | public class AppNotSupportedException extends RuntimeException { 4 | 5 | public AppNotSupportedException() { 6 | super("This app requires a newer OS version"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2015-02-02/it/univr/paranoid/InstallationException.java: -------------------------------------------------------------------------------- 1 | package it.univr.paranoid; 2 | 3 | public abstract class InstallationException extends RuntimeException { 4 | 5 | protected InstallationException(String msg) { 6 | super(msg); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2015-02-02/it/univr/paranoid/OS.java: -------------------------------------------------------------------------------- 1 | package it.univr.paranoid; 2 | 3 | /** 4 | * I sistemi operativi Paranoid, in ordine crescente di versione. 5 | */ 6 | public enum OS { 7 | LITTLE_LION, 8 | RUNNING_TIGER, 9 | ACKWARD_BEAR, 10 | FLOATING_HIPPO 11 | } 12 | -------------------------------------------------------------------------------- /2015-02-23/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-02-23/compito.pdf -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Blinker.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Blinker extends Figure { 4 | 5 | public Blinker(int startX, int startY) { 6 | super(startX, startY); 7 | } 8 | 9 | @Override 10 | public Cell mkAliveCellAt(int x, int y) { 11 | x = x - startX; 12 | y = y - startY; 13 | 14 | return 0 <= x && x <= 2 && y == 0 ? new Cell(true) : null; 15 | } 16 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Block.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Block extends Figure { 4 | 5 | public Block(int startX, int startY) { 6 | super(startX, startY); 7 | } 8 | 9 | @Override 10 | public Cell mkAliveCellAt(int x, int y) { 11 | x = x - startX; 12 | y = y - startY; 13 | 14 | return 0 <= x && x <= 1 && 0 <= y && y <= 1 ? new Cell(true) : null; 15 | } 16 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Cell.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Cell { 4 | private final boolean alive; 5 | 6 | public Cell(boolean alive) { 7 | this.alive = alive; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return alive ? "*" : " "; 13 | } 14 | 15 | public Cell next(Iterable neighbors) { 16 | int numberOfAliveNeighbors = 0; 17 | for (Cell neightbor: neighbors) 18 | if (neightbor.alive) 19 | numberOfAliveNeighbors++; 20 | 21 | if (!alive && numberOfAliveNeighbors == 3) 22 | return new Cell(true); 23 | else if (alive && numberOfAliveNeighbors != 2 && numberOfAliveNeighbors != 3) 24 | return new Cell(false); 25 | 26 | return this; 27 | } 28 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Figure.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public abstract class Figure { 4 | protected final int startX; 5 | protected final int startY; 6 | 7 | protected Figure(int startX, int startY) { 8 | this.startX = startX; 9 | this.startY = startY; 10 | } 11 | 12 | public abstract Cell mkAliveCellAt(int x, int y); 13 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Glider.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Glider extends Figure { 4 | 5 | public Glider(int startX, int startY) { 6 | super(startX, startY); 7 | } 8 | 9 | @Override 10 | public Cell mkAliveCellAt(int x, int y) { 11 | x = x - startX; 12 | y = y - startY; 13 | 14 | if ((x >= 0 && x <= 2 && y == 0) || 15 | (x == 0 && y == 1) || 16 | (x == 1 && y == 2)) 17 | return new Cell(true); 18 | else 19 | return null; 20 | } 21 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Board board = new Board(40, 30, new Blinker(5, 7), new Toad(20, 15), new Block(2, 2), new Ship(35, 20), new Glider(30, 8)); 7 | 8 | for (int num = 1; num <= 100; num++) { 9 | System.out.println("iteration #" + num); 10 | System.out.println(board); 11 | System.out.println(); 12 | 13 | // aspetta un secondo prima della prossima iterazione 14 | try { 15 | Thread.sleep(1000); 16 | } 17 | catch (InterruptedException e) {} 18 | 19 | board.recomputeCells(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Ship.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Ship extends Figure { 4 | 5 | public Ship(int startX, int startY) { 6 | super(startX, startY); 7 | } 8 | 9 | @Override 10 | public Cell mkAliveCellAt(int x, int y) { 11 | x = x - startX; 12 | y = y - startY; 13 | 14 | if ((x == 0 && y == 0) || 15 | (x == 1 && y == 0) || 16 | (x == 0 && y == 1) || 17 | (x == 2 && y == 1) || 18 | (x == 1 && y == 2)) 19 | return new Cell(true); 20 | else 21 | return null; 22 | } 23 | } -------------------------------------------------------------------------------- /2015-02-23/it/univr/life/Toad.java: -------------------------------------------------------------------------------- 1 | package it.univr.life; 2 | 3 | public class Toad extends Figure { 4 | 5 | public Toad(int startX, int startY) { 6 | super(startX, startY); 7 | } 8 | 9 | @Override 10 | public Cell mkAliveCellAt(int x, int y) { 11 | x = x - startX; 12 | y = y - startY; 13 | 14 | return (1 <= x && x <= 3 && y == 0) || (0 <= x && x <= 2 && y == 1) ? new Cell(true) : null; 15 | } 16 | } -------------------------------------------------------------------------------- /2015-06-18/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-06-18/compito.pdf -------------------------------------------------------------------------------- /2015-06-18/it/univr/charsequence/AbstractCharSequence.java: -------------------------------------------------------------------------------- 1 | package it.univr.charsequence; 2 | 3 | public abstract class AbstractCharSequence implements CharSequence { 4 | 5 | @Override 6 | public final String toString() { 7 | String result = ""; 8 | for (int index = 0; index < length(); index++) 9 | result += charAt(index); 10 | 11 | return result; 12 | } 13 | } -------------------------------------------------------------------------------- /2015-09-30/Swing12DateView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-09-30/Swing12DateView.png -------------------------------------------------------------------------------- /2015-09-30/SwingDateView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-09-30/SwingDateView.png -------------------------------------------------------------------------------- /2015-09-30/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2015-09-30/compito.pdf -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.date; 2 | 3 | import it.univr.date.controller.Controller; 4 | import it.univr.date.controller.ControllerImpl; 5 | import it.univr.date.model.Model; 6 | import it.univr.date.model.Time; 7 | import it.univr.date.view.Swing12DateView; 8 | import it.univr.date.view.SwingDateView; 9 | import it.univr.date.view.TextDateView; 10 | 11 | public class Main { 12 | 13 | public static void main(String[] args) { 14 | Model model = new Time(); 15 | Controller controller = new ControllerImpl(model); 16 | model.linkToView(new TextDateView()); 17 | model.linkToView(new SwingDateView(controller)); 18 | model.linkToView(new Swing12DateView(controller)); 19 | } 20 | } -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/controller/Controller.java: -------------------------------------------------------------------------------- 1 | package it.univr.date.controller; 2 | 3 | public interface Controller { 4 | void onIncreaseHours(); 5 | void onDecreaseHours(); 6 | void onIncreaseMinutes(); 7 | void onDecreaseMinutes(); 8 | void onIncreaseSeconds(); 9 | void onDecreaseSeconds(); 10 | void onResetTime(); 11 | } -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/model/Model.java: -------------------------------------------------------------------------------- 1 | package it.univr.date.model; 2 | 3 | import it.univr.date.view.View; 4 | 5 | public interface Model { 6 | void linkToView(View view); 7 | void set(int hours, int minutes, int seconds) throws IllegalArgumentException; 8 | int getHours(); 9 | int getMinutes(); 10 | int getSeconds(); 11 | } -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/view/Swing12DateView.java: -------------------------------------------------------------------------------- 1 | package it.univr.date.view; 2 | 3 | import it.univr.date.controller.Controller; 4 | 5 | import javax.swing.JLabel; 6 | import javax.swing.JPanel; 7 | 8 | @SuppressWarnings("serial") 9 | public class Swing12DateView extends SwingDateView { 10 | 11 | private JLabel ampm; 12 | 13 | public Swing12DateView(Controller controller) { 14 | super(controller); 15 | } 16 | 17 | @Override 18 | protected JPanel buildClockPanel(Controller controller) { 19 | JPanel clock = super.buildClockPanel(controller); 20 | ampm = new JLabel(); 21 | clock.add(ampm); 22 | 23 | return clock; 24 | } 25 | 26 | @Override 27 | public void onTimeChanged(int hours, int minutes, int seconds) { 28 | super.onTimeChanged(hours % 12 == 0 ? 12 : hours % 12, minutes, seconds); 29 | 30 | ampm.setText(hours < 12 ? "am" : "pm"); 31 | } 32 | } -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/view/TextDateView.java: -------------------------------------------------------------------------------- 1 | package it.univr.date.view; 2 | 3 | public class TextDateView implements View { 4 | 5 | @Override 6 | public void onTimeChanged(int hours, int minutes, int seconds) { 7 | System.out.printf("%d:%02d:%02d\n", hours, minutes, seconds); 8 | } 9 | } -------------------------------------------------------------------------------- /2015-09-30/it/univr/date/view/View.java: -------------------------------------------------------------------------------- 1 | package it.univr.date.view; 2 | 3 | public interface View { 4 | void onTimeChanged(int hours, int minutes, int seconds); 5 | } -------------------------------------------------------------------------------- /2016-02-03/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2016-02-03/compito.pdf -------------------------------------------------------------------------------- /2016-02-03/it/univr/elezioni/ElezioniIstogramma.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class ElezioniIstogramma extends Elezioni { 4 | 5 | @Override 6 | public String toString() { 7 | String result = super.toString() + "\n"; 8 | int numeroVotiEspressi = numeroVotiEspressi(); 9 | 10 | int num = 1; 11 | for (Partito partito: Partito.elementi()) 12 | result += ripeti(num++, votiPer(partito) * 50 / numeroVotiEspressi); 13 | 14 | result += "\n"; 15 | 16 | return result; 17 | } 18 | 19 | private String ripeti(int num, int numeroRipetizioni) { 20 | String res = ""; 21 | while (numeroRipetizioni-- > 0) 22 | res += num; 23 | 24 | return res; 25 | } 26 | } -------------------------------------------------------------------------------- /2016-02-03/it/univr/elezioni/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | import java.util.Random; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Random random = new Random(); 9 | Partito[] partiti = Partito.values(); 10 | Elezioni elezioni = new ElezioniIstogramma(); 11 | 12 | for (Partito partito: partiti) { 13 | int voti = random.nextInt(10000); 14 | for (int i = 0; i < voti; i++) 15 | elezioni.vota(partito); 16 | } 17 | 18 | System.out.println(elezioni); 19 | 20 | for (VotiPerPartito vpp: elezioni) 21 | System.out.println(vpp); 22 | } 23 | } -------------------------------------------------------------------------------- /2016-02-03/it/univr/elezioni/Partito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public enum Partito { 4 | PENSIONATI, 5 | FELICE, 6 | FLOREALE, 7 | CAOTICO, 8 | BASSOTTI; 9 | 10 | public final static int NUMERO_PARTITI = elementi().length; 11 | 12 | public static Partito[] elementi() { 13 | return values(); 14 | } 15 | 16 | public int indice() { 17 | for (int pos = 0; pos < NUMERO_PARTITI; pos++) 18 | if (elementi()[pos] == this) 19 | return pos; 20 | 21 | throw new RuntimeException("impossibile"); 22 | } 23 | } -------------------------------------------------------------------------------- /2016-02-03/it/univr/elezioni/VotiPerPartito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | public class VotiPerPartito { 4 | private final Partito partito; 5 | private final int voti; 6 | 7 | public VotiPerPartito(Partito partito, int voti) { 8 | this.partito = partito; 9 | this.voti = voti; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return partito + ": " + voti; 15 | } 16 | } -------------------------------------------------------------------------------- /2016-02-24/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2016-02-24/compito.pdf -------------------------------------------------------------------------------- /2016-02-24/it/univr/palestra/IscrizioneSovrappostaException.java: -------------------------------------------------------------------------------- 1 | package it.univr.palestra; 2 | 3 | public class IscrizioneSovrappostaException extends Exception { 4 | public IscrizioneSovrappostaException() { 5 | super("l'iscrizione è sovrapposta a un'altra già esistente"); 6 | } 7 | } -------------------------------------------------------------------------------- /2016-02-24/it/univr/palestra/IscrizioneTroppoLungaException.java: -------------------------------------------------------------------------------- 1 | package it.univr.palestra; 2 | 3 | public class IscrizioneTroppoLungaException extends Exception { 4 | public IscrizioneTroppoLungaException() { 5 | super("l'iscrizione deve essere di al massimo un anno"); 6 | } 7 | } -------------------------------------------------------------------------------- /2016-02-24/it/univr/palestra/IscrizioneVuotaException.java: -------------------------------------------------------------------------------- 1 | package it.univr.palestra; 2 | 3 | public class IscrizioneVuotaException extends Exception { 4 | public IscrizioneVuotaException() { 5 | super("l'inizio dell'iscrizione deve precederne la fine"); 6 | } 7 | } -------------------------------------------------------------------------------- /2016-02-24/it/univr/palestra/Mese.java: -------------------------------------------------------------------------------- 1 | package it.univr.palestra; 2 | 3 | public enum Mese { 4 | GENNAIO, 5 | FEBBRAIO, 6 | MARZO, 7 | APRILE, 8 | MAGGIO, 9 | GIUGNO, 10 | LUGLIO, 11 | AGOSTO, 12 | SETTEMBRE, 13 | OTTOBRE, 14 | NOVEMBRE, 15 | DICEMBRE 16 | } 17 | -------------------------------------------------------------------------------- /2016-02-24/it/univr/palestra/Utente.java: -------------------------------------------------------------------------------- 1 | package it.univr.palestra; 2 | 3 | public class Utente implements Comparable { 4 | private final String nome; 5 | private final String cognome; 6 | 7 | public Utente(String nome, String cognome) { 8 | this.nome = nome; 9 | this.cognome = cognome; 10 | } 11 | 12 | @Override 13 | public boolean equals(Object other) { 14 | return other instanceof Utente && 15 | ((Utente) other).nome.equals(nome) && 16 | ((Utente) other).cognome.equals(cognome); 17 | } 18 | 19 | @Override 20 | public int hashCode() { 21 | return nome.hashCode() ^ cognome.hashCode(); 22 | } 23 | 24 | @Override 25 | public int compareTo(Utente other) { 26 | int diff = cognome.compareTo(other.cognome); 27 | if (diff != 0) 28 | return diff; 29 | else 30 | return nome.compareTo(other.nome); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return nome + " " + cognome; 36 | } 37 | } -------------------------------------------------------------------------------- /2016-06-21/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2016-06-21/compito.pdf -------------------------------------------------------------------------------- /2016-06-21/it/univr/email/Email.java: -------------------------------------------------------------------------------- 1 | package it.univr.email; 2 | 3 | import java.util.Set; 4 | 5 | public interface Email { 6 | Mailbox getSender(); 7 | Set getRecipients(); 8 | String getSubject(); 9 | String getBody(); 10 | String toString(); 11 | } -------------------------------------------------------------------------------- /2016-06-21/it/univr/email/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.email; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) throws UnknownEmailException { 6 | Server gmail = new Server(); 7 | Mailbox fausto = new Mailbox(gmail, "fausto.spoto@gmail.com"); 8 | Mailbox scarlett = new Mailbox(gmail, "scarlett.johansson@gmail.com"); 9 | Mailbox jennifer = new Mailbox(gmail, "jennifer.lawrence@gmail.com"); 10 | Mailbox tim = new Mailbox(gmail, "tim.cook@gmail.com"); 11 | 12 | // fausto -> { scarlett, jennifer } 13 | Email e1 = fausto.post("new programming language", "I will soon move to Ruby!", scarlett, jennifer); 14 | 15 | // scarlett -> { fausto, jennifer } 16 | Email e2 = scarlett.replyToAll(e1, "I think Python is much better!"); 17 | 18 | // jennifer -> tim 19 | Email e3 = jennifer.forward(e2, "Hey Tim, look what these people are saying!", tim); 20 | 21 | // tim -> jennifer 22 | tim.replyToAll(e3, "Thank you Jennifer!\nI will investigate this issue better"); 23 | 24 | System.out.println(jennifer); 25 | } 26 | } -------------------------------------------------------------------------------- /2016-06-21/it/univr/email/Server.java: -------------------------------------------------------------------------------- 1 | package it.univr.email; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Server { 7 | private final Set emails = new HashSet<>(); 8 | 9 | public void post(Email email) { 10 | this.emails.add(email); 11 | } 12 | 13 | public Set getEmailsTo(Mailbox recipient) { 14 | Set result = new HashSet<>(); 15 | for (Email email: emails) 16 | if (email.getRecipients().contains(recipient)) 17 | result.add(email); 18 | 19 | return result; 20 | } 21 | } -------------------------------------------------------------------------------- /2016-06-21/it/univr/email/UnknownEmailException.java: -------------------------------------------------------------------------------- 1 | package it.univr.email; 2 | 3 | public class UnknownEmailException extends Exception { 4 | public UnknownEmailException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2016-09-06/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2016-09-06/compito.pdf -------------------------------------------------------------------------------- /2016-09-06/it/univr/phones/UnknownEntryException.java: -------------------------------------------------------------------------------- 1 | package it.univr.phones; 2 | 3 | public class UnknownEntryException extends RuntimeException { 4 | 5 | public UnknownEntryException() { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2016-09-06/it/univr/phones/View.java: -------------------------------------------------------------------------------- 1 | package it.univr.phones; 2 | 3 | import it.univr.phones.PhoneBook.Entry; 4 | 5 | public abstract class View implements Iterable { 6 | 7 | protected View() { 8 | } 9 | 10 | @Override 11 | public final String toString() { 12 | String result = ""; 13 | for (Entry entry: this) 14 | result += entry.toString() + "\n"; 15 | 16 | return result; 17 | } 18 | } -------------------------------------------------------------------------------- /2017-02-03/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2017-02-03/compito.pdf -------------------------------------------------------------------------------- /2017-02-03/it/univr/doodle/WeightedDoodle.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class WeightedDoodle extends Doodle { 7 | private final Map weights = new HashMap<>(); 8 | 9 | @Override 10 | public void available(String name, Slot... when) { 11 | available(name, 1.0, when); 12 | } 13 | 14 | @Override 15 | public void available(String name, Iterable when) { 16 | available(name, 1.0, when); 17 | } 18 | 19 | public void available(String name, double weight, Slot... when) { 20 | super.available(name, when); 21 | weights.put(name, weight); 22 | } 23 | 24 | public void available(String name, double weight, Iterable when) { 25 | super.available(name, when); 26 | weights.put(name, weight); 27 | } 28 | 29 | @Override 30 | protected double weightOf(String name) { 31 | return weights.get(name); 32 | } 33 | } -------------------------------------------------------------------------------- /2017-06-26/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2017-06-26/compito.pdf -------------------------------------------------------------------------------- /2017-06-26/hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2017-06-26/hierarchy.png -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/AbstractPizza.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | public abstract class AbstractPizza implements Pizza { 4 | 5 | @Override 6 | public final boolean equals(Object other) { 7 | return other instanceof Pizza && getIngredients().equals(((Pizza) other).getIngredients()); 8 | } 9 | 10 | @Override 11 | public final int hashCode() { 12 | return getIngredients().hashCode(); 13 | } 14 | 15 | @Override 16 | public final 17 | int compareTo(Pizza other) { 18 | // sfruttiamo il fatto che il toString() degli insiemi ritorna la conctenazione degli elementi 19 | return getIngredients().toString().compareTo(((Pizza) other).getIngredients().toString()); 20 | } 21 | 22 | public abstract String toString(); 23 | } 24 | -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Formaggi.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | import java.util.SortedSet; 4 | import java.util.TreeSet; 5 | 6 | public final class Formaggi extends AbstractPizza { 7 | final static Formaggi INSTANCE = new Formaggi(); 8 | private Formaggi() {} 9 | 10 | @Override 11 | public String toString() { 12 | return "Quattro Formaggi"; 13 | } 14 | 15 | @Override 16 | public SortedSet getIngredients() { 17 | SortedSet result = new TreeSet<>(); 18 | result.add("mozzarella"); 19 | result.add("parmesan"); 20 | result.add("gorgonzola"); 21 | 22 | return result; 23 | } 24 | 25 | @Override 26 | public int getPrice() { 27 | return 8; 28 | } 29 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Funghi.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | import java.util.SortedSet; 4 | import java.util.TreeSet; 5 | 6 | public final class Funghi extends AbstractPizza { 7 | final static Funghi INSTANCE = new Funghi(); 8 | private Funghi() {} 9 | 10 | @Override 11 | public String toString() { 12 | return "Funghi"; 13 | } 14 | 15 | @Override 16 | public SortedSet getIngredients() { 17 | SortedSet result = new TreeSet<>(); 18 | result.add("tomato"); 19 | result.add("mozzarella"); 20 | result.add("mushrooms"); 21 | 22 | return result; 23 | } 24 | 25 | @Override 26 | public int getPrice() { 27 | return 7; 28 | } 29 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/IllegalPizzaModificationException.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | public class IllegalPizzaModificationException extends RuntimeException { 4 | public IllegalPizzaModificationException(String message) { 5 | super(message); 6 | } 7 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Margherita.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | import java.util.SortedSet; 4 | import java.util.TreeSet; 5 | 6 | public final class Margherita extends AbstractPizza { 7 | final static Margherita INSTANCE = new Margherita(); 8 | private Margherita() {} 9 | 10 | @Override 11 | public String toString() { 12 | return "Margherita"; 13 | } 14 | 15 | @Override 16 | public SortedSet getIngredients() { 17 | SortedSet result = new TreeSet<>(); 18 | result.add("tomato"); 19 | result.add("mozzarella"); 20 | 21 | return result; 22 | } 23 | 24 | @Override 25 | public int getPrice() { 26 | return 5; 27 | } 28 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Menu.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | public class Menu { 4 | public final static Pizza MARGHERITA = Margherita.INSTANCE; 5 | public final static Pizza FUNGHI = Funghi.INSTANCE; 6 | public final static Pizza FORMAGGI = Formaggi.INSTANCE; 7 | public final static Pizza PROSCIUTTO_FUNGHI = ProsciuttoFunghi.INSTANCE; 8 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Order.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | public class Order { 4 | private final Pizza[] pizzas; 5 | 6 | public Order(Pizza... pizzas) { 7 | this.pizzas = pizzas; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | String result = "----------------------\n"; 13 | 14 | for (Pizza pizza: pizzas) 15 | result += pizza + " (" + pizza.getPrice() + " euros)\n"; 16 | 17 | result += "----------------------\n"; 18 | result += "Total price: " + getPrice() + " euros"; 19 | 20 | return result; 21 | } 22 | 23 | public int getPrice() { 24 | int price = 0; 25 | for (Pizza pizza: pizzas) 26 | price += pizza.getPrice(); 27 | 28 | return price; 29 | } 30 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/Pizza.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | import java.util.SortedSet; 4 | 5 | public interface Pizza extends Comparable { 6 | public SortedSet getIngredients(); 7 | public int getPrice(); 8 | } -------------------------------------------------------------------------------- /2017-06-26/it/univr/pizzeria/ProsciuttoFunghi.java: -------------------------------------------------------------------------------- 1 | package it.univr.pizzeria; 2 | 3 | import java.util.SortedSet; 4 | import java.util.TreeSet; 5 | 6 | public class ProsciuttoFunghi extends AbstractPizza { 7 | final static ProsciuttoFunghi INSTANCE = new ProsciuttoFunghi(); 8 | private ProsciuttoFunghi() {} 9 | 10 | @Override 11 | public String toString() { 12 | return "Prosciutto & Funghi"; 13 | } 14 | 15 | @Override 16 | public SortedSet getIngredients() { 17 | SortedSet result = new TreeSet<>(); 18 | result.add("tomato"); 19 | result.add("mozzarella"); 20 | result.add("mushrooms"); 21 | result.add("ham"); 22 | 23 | return result; 24 | } 25 | 26 | @Override 27 | public int getPrice() { 28 | return 8; 29 | } 30 | } -------------------------------------------------------------------------------- /2017-07-28/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2017-07-28/compito.pdf -------------------------------------------------------------------------------- /2017-07-28/it/univr/ecommerce/MissingProductException.java: -------------------------------------------------------------------------------- 1 | package it.univr.ecommerce; 2 | 3 | public class MissingProductException extends Exception { 4 | } -------------------------------------------------------------------------------- /2017-07-28/it/univr/ecommerce/Order.java: -------------------------------------------------------------------------------- 1 | package it.univr.ecommerce; 2 | 3 | public abstract class Order { 4 | private final Shop shop; 5 | private final Product[] products; 6 | 7 | protected Order(Shop shop, Product... products) { 8 | this.shop = shop; 9 | this.products = products; 10 | } 11 | 12 | protected final Product[] getProducts() { 13 | return products; 14 | } 15 | 16 | protected final void buy() throws MissingProductException { 17 | shop.buy(products); 18 | } 19 | 20 | public abstract Iterable ship() throws MissingProductException; 21 | } -------------------------------------------------------------------------------- /2017-07-28/it/univr/ecommerce/Shipping.java: -------------------------------------------------------------------------------- 1 | package it.univr.ecommerce; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Shipping { 7 | private final List products = new ArrayList<>(); 8 | 9 | Shipping(Iterable products) { 10 | for (Product product: products) 11 | this.products.add(product); 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | StringBuilder sb = new StringBuilder(); 17 | for (Product product: products) { 18 | sb.append(product.toString()); 19 | sb.append('\n'); 20 | } 21 | 22 | return sb.toString(); 23 | } 24 | } -------------------------------------------------------------------------------- /2017-07-28/it/univr/ecommerce/SimpleOrder.java: -------------------------------------------------------------------------------- 1 | package it.univr.ecommerce; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class SimpleOrder extends Order { 8 | 9 | public SimpleOrder(Shop shop, Product... products) { 10 | super(shop, products); 11 | } 12 | 13 | @Override 14 | public Iterable ship() throws MissingProductException { 15 | buy(); 16 | List result = new ArrayList<>(); 17 | result.add(new Shipping(Arrays.asList(getProducts()))); 18 | 19 | return result; 20 | } 21 | } -------------------------------------------------------------------------------- /2017-07-28/it/univr/ecommerce/SplitOrder.java: -------------------------------------------------------------------------------- 1 | package it.univr.ecommerce; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class SplitOrder extends Order { 9 | 10 | public SplitOrder(Shop shop, Product... products) { 11 | super(shop, products); 12 | } 13 | 14 | @Override 15 | public Iterable ship() throws MissingProductException { 16 | buy(); 17 | 18 | Map> buckets = new HashMap<>(); 19 | for (Product product: getProducts()) { 20 | int days = product.getDaysBeforeShipping(); 21 | buckets.putIfAbsent(days, new ArrayList<>()); 22 | buckets.get(days).add(product); 23 | 24 | // oppure: 25 | //buckets.computeIfAbsent(days, _days -> new ArrayList<>()).add(product); 26 | } 27 | 28 | List result = new ArrayList<>(); 29 | for (List bucket: buckets.values()) 30 | result.add(new Shipping(bucket)); 31 | 32 | return result; 33 | } 34 | } -------------------------------------------------------------------------------- /2017-09-04/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2017-09-04/compito.pdf -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/airbust/AirBustBookings.java: -------------------------------------------------------------------------------- 1 | package it.univr.airbust; 2 | import it.univr.bookings.Bookings; 3 | import it.univr.bookings.Date; 4 | 5 | public class AirBustBookings extends Bookings { 6 | 7 | public AirBustBookings(int year) { 8 | super(new Date(1, 1, year), new Date(31, 12, year), 100, 500, new AirBustFleet()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/airbust/AirBustFleet.java: -------------------------------------------------------------------------------- 1 | package it.univr.airbust; 2 | import it.univr.bookings.Aircraft; 3 | import it.univr.bookings.Date; 4 | import it.univr.bookings.Fleet; 5 | 6 | public class AirBustFleet implements Fleet { 7 | private final static Aircraft a320 = new Aircraft("A320", 200); 8 | private final static Aircraft a330 = new Aircraft("A330", 277); 9 | private final static Aircraft a380 = new Aircraft("A380", 388); 10 | 11 | @Override 12 | public Aircraft getAircraftFor(Date when) { 13 | if (when.isXmas() || when.isThanksgiving() || when.isNewYearsEve()) 14 | return a380; 15 | else if (when.isColumbusDay()) 16 | return a330; 17 | else 18 | return a320; 19 | } 20 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/Aircraft.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public class Aircraft { 4 | private final String name; 5 | private final int capacity; 6 | 7 | public Aircraft(String name, int capacity) { 8 | this.name = name; 9 | this.capacity = capacity; 10 | } 11 | 12 | public int getCapacity() { 13 | return capacity; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return name; 19 | } 20 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/BookingException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public abstract class BookingException extends Exception { 4 | protected BookingException(String message) { 5 | super(message); 6 | } 7 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/Fleet.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public interface Fleet { 4 | Aircraft getAircraftFor(Date when); 5 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/FlightSoldOutException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public class FlightSoldOutException extends QuoteException { 4 | public FlightSoldOutException() { 5 | super("flight soldout"); 6 | } 7 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/IllegalBookingDatesException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public class IllegalBookingDatesException extends QuoteException { 4 | public IllegalBookingDatesException() { 5 | super("illegal booking dates"); 6 | } 7 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/PriceChangedException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public class PriceChangedException extends BookingException { 4 | public PriceChangedException() { 5 | super("flight price has changed"); 6 | } 7 | } -------------------------------------------------------------------------------- /2017-09-04/src/it/univr/bookings/QuoteException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bookings; 2 | 3 | public abstract class QuoteException extends BookingException { 4 | protected QuoteException(String message) { 5 | super(message); 6 | } 7 | } -------------------------------------------------------------------------------- /2018-02-07/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2018-02-07/compito.pdf -------------------------------------------------------------------------------- /2018-02-07/it/univr/hairbnb/NoRoomAvailableException.java: -------------------------------------------------------------------------------- 1 | package it.univr.hairbnb; 2 | 3 | public class NoRoomAvailableException extends RuntimeException { 4 | public NoRoomAvailableException() { 5 | super("No room is available for the selected criteria"); 6 | } 7 | } -------------------------------------------------------------------------------- /2018-02-07/it/univr/hairbnb/Review.java: -------------------------------------------------------------------------------- 1 | package it.univr.hairbnb; 2 | 3 | public class Review { 4 | 5 | public enum Stars { 6 | ONE, 7 | TWO, 8 | THREE, 9 | FOUR, 10 | FIVE 11 | } 12 | 13 | private final String author; 14 | private final String text; 15 | private final Stars stars; 16 | 17 | public Review(String author, String text, Stars stars) { 18 | this.author = author; 19 | this.text = text; 20 | this.stars = stars; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return author + " (" + stars() + ")\n" + text + "\n"; 26 | } 27 | 28 | private String stars() { 29 | switch (stars) { 30 | case ONE: return "*"; 31 | case TWO: return "**"; 32 | case THREE: return "***"; 33 | case FOUR: return "****"; 34 | default: return "*****"; 35 | } 36 | } 37 | 38 | public int howManyStars() { 39 | switch (stars) { 40 | case ONE: return 1; 41 | case TWO: return 2; 42 | case THREE: return 3; 43 | case FOUR: return 4; 44 | default: return 5; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /2018-02-27/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2018-02-27/compito.pdf -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/EsamePerEsito.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | import java.util.Comparator; 4 | 5 | public class EsamePerEsito extends Esame { 6 | 7 | @Override 8 | protected Comparator getComparator() { 9 | return new Comparator() { 10 | 11 | @Override 12 | public int compare(Verbalizzazione v1, Verbalizzazione v2) { 13 | int diff = v1.getEsito().compareTo(v2.getEsito()); 14 | if (diff != 0) 15 | return diff; 16 | else 17 | return v1.getStudente().matricola - v2.getStudente().matricola; 18 | } 19 | }; 20 | } 21 | } -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/EsamePerMatricola.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | import java.util.Comparator; 4 | 5 | public class EsamePerMatricola extends Esame { 6 | 7 | @Override 8 | protected Comparator getComparator() { 9 | return new Comparator() { 10 | 11 | @Override 12 | public int compare(Verbalizzazione v1, Verbalizzazione v2) { 13 | return v1.getStudente().matricola - v2.getStudente().matricola; 14 | } 15 | }; 16 | } 17 | } -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/Esito.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | public enum Esito { 4 | RITIRATO("rit"), INSUFFICIENTE("ins"), DICIOTTO("18"), DICIANNOVE("19"), 5 | VENTI("20"), VENTUNO("21"), VENTIDUE("22"), VENTITRE("23"), VENTIQUATTRO("24"), 6 | VENTICINQUE("25"), VENTISEI("26"), VENTISETTE("27"), VENTOTTO("28"), 7 | VENTINOVE("29"), TRENTA("30"), TRENTAELODE("30L"); 8 | 9 | private final String name; 10 | 11 | private Esito(String name) { 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return name; 18 | } 19 | } -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | public class Main { 4 | public static void main(String[] args) throws VerbalizzazioneGiàEffettuataException, StudenteNonIscrittoException { 5 | Esame esame = new EsamePerEsito(); 6 | Studente s1 = new Studente(151535, "Giorgio", "Levi"); 7 | Studente s2 = new Studente(200345, "Fausto", "Spoto"); 8 | Studente s3 = new Studente(324422, "Albert", "Einstein"); 9 | Studente s4 = new Studente(145066, "Camilla", "De Sanctis"); 10 | Studente s5 = new Studente(111044, "Eleonora", "Botticelli"); 11 | 12 | esame.iscrivi(s1, s2, s4, s5); 13 | esame.verbalizza(s1, Esito.VENTI); 14 | esame.verbalizza(s4, Esito.TRENTAELODE); 15 | esame.verbalizza(s2, Esito.RITIRATO); 16 | esame.verbalizza(s5, Esito.VENTI); 17 | 18 | System.out.println(esame); 19 | 20 | esame.verbalizza(s3, Esito.TRENTA); 21 | } 22 | } -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/Studente.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | public class Studente { 4 | public final int matricola; 5 | public final String nome; 6 | public final String cognome; 7 | 8 | public Studente(int matricola, String nome, String cognome) { 9 | this.matricola = matricola; 10 | this.nome = nome; 11 | this.cognome = cognome; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object other) { 16 | return other instanceof Studente && ((Studente) other).matricola == matricola; 17 | } 18 | 19 | @Override 20 | public int hashCode() { 21 | return matricola; 22 | } 23 | } -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/StudenteNonIscrittoException.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | public class StudenteNonIscrittoException extends Exception { 4 | public StudenteNonIscrittoException(Studente studente) { 5 | super("Lo studente " + studente.nome + " " + studente.cognome + " non è iscritto all'esame"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2018-02-27/it/univr/esami/VerbalizzazioneGiàEffettuataException.java: -------------------------------------------------------------------------------- 1 | package it.univr.esami; 2 | 3 | public class VerbalizzazioneGiàEffettuataException extends Exception { 4 | public VerbalizzazioneGiàEffettuataException(Studente studente) { 5 | super("Lo studente " + studente.nome + " " + studente.cognome + " ha già verbalizzato"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2018-06-21/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2018-06-21/compito.pdf -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/AbstractNumber.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public abstract class AbstractNumber implements Number { 4 | private final int value; 5 | 6 | protected AbstractNumber(int value) { 7 | if (value < 0) 8 | throw new IllegalArgumentException("negative numbers are not allowed"); 9 | 10 | this.value = value; 11 | } 12 | 13 | @Override 14 | public final int getValue() { 15 | return value; 16 | } 17 | 18 | protected abstract int getBase(); 19 | 20 | protected abstract char getCharForDigit(int digit); 21 | 22 | @Override 23 | public String toString() { 24 | String result = ""; 25 | 26 | int v = value, base = getBase(); 27 | do { 28 | result = getCharForDigit(v % base) + result; 29 | v /= base; 30 | } 31 | while (v > 0); 32 | 33 | return result; 34 | } 35 | 36 | @Override 37 | public final boolean equals(Object other) { 38 | return other instanceof Number && ((Number) other).getValue() == value; 39 | } 40 | 41 | @Override 42 | public final int hashCode() { 43 | return value; 44 | } 45 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/Base58Number.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class Base58Number extends AbstractNumber { 4 | public Base58Number(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | protected int getBase() { 10 | return 58; 11 | } 12 | 13 | private final static String digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 14 | 15 | @Override 16 | protected char getCharForDigit(int digit) { 17 | return digits.charAt(digit); 18 | } 19 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/BinaryNumber.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class BinaryNumber extends AbstractNumber { 4 | public BinaryNumber(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | protected int getBase() { 10 | return 2; 11 | } 12 | 13 | @Override 14 | protected char getCharForDigit(int digit) { 15 | return digit == 0 ? '0' : '1'; 16 | } 17 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/BinaryNumberWithParity.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class BinaryNumberWithParity extends BinaryNumber { 4 | public BinaryNumberWithParity(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | public String toString() { 10 | String result = super.toString(); 11 | boolean even = true; 12 | for (int pos = result.length() - 1; pos >= 0; pos--) 13 | if (result.charAt(pos) == '1') 14 | even = !even; 15 | 16 | return result + (even ? '0' : '1'); 17 | } 18 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/DecimalNumber.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class DecimalNumber extends AbstractNumber { 4 | public DecimalNumber(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | protected int getBase() { 10 | return 10; 11 | } 12 | 13 | @Override 14 | protected char getCharForDigit(int digit) { 15 | return (char) ('0' + digit); 16 | } 17 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/HexNumber.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class HexNumber extends AbstractNumber { 4 | public HexNumber(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | protected int getBase() { 10 | return 16; 11 | } 12 | 13 | private final static String digits = "0123456789ABCDEF"; 14 | 15 | @Override 16 | protected char getCharForDigit(int digit) { 17 | return digits.charAt(digit); 18 | } 19 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/Number.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public interface Number { 4 | int getValue(); 5 | } -------------------------------------------------------------------------------- /2018-06-21/it/univr/numbers/OctalNumber.java: -------------------------------------------------------------------------------- 1 | package it.univr.numbers; 2 | 3 | public class OctalNumber extends AbstractNumber { 4 | public OctalNumber(int value) { 5 | super(value); 6 | } 7 | 8 | @Override 9 | protected int getBase() { 10 | return 8; 11 | } 12 | 13 | @Override 14 | protected char getCharForDigit(int digit) { 15 | return (char) ('0' + digit); 16 | } 17 | } -------------------------------------------------------------------------------- /2018-09-28/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2018-09-28/compito.pdf -------------------------------------------------------------------------------- /2018-09-28/it/univr/music/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.music; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Song yellowSubmarine = new Song("In the town where I was born lived a man who sailed the sea"); 7 | yellowSubmarine.add(EnglishNote.C_SHARP, 7); // C# su "town" 8 | yellowSubmarine.add(EnglishNote.C_SHARP, 56); // C# su "sea" 9 | yellowSubmarine.add(EnglishNote.F_SHARP, 24); // F# su "born" 10 | yellowSubmarine.add(EnglishNote.G_SHARP, 37); // G# su "man" 11 | // yellowSubmarine.add(EnglishNote.A, 24); // questo genenerebbe una NoteAtSamePositionException 12 | 13 | System.out.println(yellowSubmarine); 14 | } 15 | } -------------------------------------------------------------------------------- /2018-09-28/it/univr/music/Note.java: -------------------------------------------------------------------------------- 1 | package it.univr.music; 2 | 3 | public abstract class Note implements Comparable { 4 | protected final int semitone; 5 | 6 | protected Note(int semitone) { 7 | if (semitone < 0 || semitone > 11) 8 | throw new IllegalArgumentException(); 9 | 10 | this.semitone = semitone; 11 | } 12 | 13 | @Override 14 | public abstract String toString(); 15 | 16 | @Override 17 | public final boolean equals(Object other) { 18 | return other instanceof Note && ((Note) other).semitone == semitone; 19 | } 20 | 21 | @Override 22 | public final int hashCode() { 23 | return semitone; 24 | } 25 | 26 | @Override 27 | public final int compareTo(Note other) { 28 | return semitone - other.semitone; 29 | } 30 | } -------------------------------------------------------------------------------- /2018-09-28/it/univr/music/NoteAtSamePositionException.java: -------------------------------------------------------------------------------- 1 | package it.univr.music; 2 | 3 | public class NoteAtSamePositionException extends RuntimeException { 4 | } -------------------------------------------------------------------------------- /2018-09-28/it/univr/music/NoteTest.java: -------------------------------------------------------------------------------- 1 | package it.univr.music; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | public class NoteTest { 7 | 8 | @Test 9 | public void testToString() { 10 | assertEquals(ItalianNote.DO.toString(), "do"); 11 | } 12 | 13 | @Test 14 | public void testEquals() { 15 | assertEquals(ItalianNote.RE_DIESIS, EnglishNote.D_SHARP); 16 | } 17 | 18 | @Test 19 | public void testHashCode() { 20 | assertTrue(ItalianNote.RE_DIESIS.hashCode() == EnglishNote.D_SHARP.hashCode()); 21 | } 22 | 23 | @Test 24 | public void testHashCodeNonTrivial() { 25 | assertTrue(ItalianNote.RE_DIESIS.hashCode() != EnglishNote.E.hashCode()); 26 | } 27 | 28 | @Test 29 | public void testCompareTo() { 30 | assertTrue(ItalianNote.DO.compareTo(EnglishNote.D) < 0); 31 | } 32 | } -------------------------------------------------------------------------------- /2019-01-29/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-01-29/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-01-29/consegna/it/univr/rent/License.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public enum License { 4 | A, // per moto (Motorbike) 5 | B, // per moto e automobili (Car) 6 | C, // per moto, automobili e camion (Truck) 7 | D // per moto, automobili e autobus (Bus) 8 | } -------------------------------------------------------------------------------- /2019-01-29/consegna/it/univr/rent/Model.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | /** 4 | * I modelli sono ordinati per prezzo di noleggio giornaliero. 5 | * A parita' di prezzo di noleggio, sono ordinati alfabeticamente per nome. 6 | */ 7 | public interface Model extends Comparable { 8 | // restituisce il nome del modello 9 | public String getName(); 10 | 11 | // determina se il modello puo' essere guidato 12 | // con la patente (license) indicata 13 | public boolean canBeDrivenWith(License license); 14 | 15 | // restituisce il prezzo giornaliero di noleggio del modello 16 | public int pricePerDay(); 17 | } -------------------------------------------------------------------------------- /2019-01-29/consegna/risultato_main.txt: -------------------------------------------------------------------------------- 1 | Agency Hartz. Available models: 2 | ------------------------------- 3 | Fiat Panda 28 euros per day 4 | Fiat Panda plus 30 euros per day 5 | HD Pan American 75 euros per day 6 | Renault Captur 75 euros per day 7 | Renault Iliade 500 euros per day 8 | 9 | Models available with license A 10 | [HD Pan American] 11 | Models available with license B 12 | [HD Pan American, Fiat Panda plus, Fiat Panda, Renault Captur] 13 | Models available with license C 14 | [HD Pan American, Fiat Panda plus, Fiat Panda, Renault Captur] 15 | Models available with license D 16 | [HD Pan American, Fiat Panda plus, Fiat Panda, Renault Captur, Renault Iliade] 17 | 18 | Most rented model: Fiat Panda plus 19 | Cannot rent Renault Iliade with license B 20 | -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/AbstractModel.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public abstract class AbstractModel implements Model { 4 | private final String name; 5 | private final int pricePerDay; 6 | 7 | protected AbstractModel(String name, int pricePerDay) { 8 | this.name = name; 9 | this.pricePerDay = pricePerDay; 10 | } 11 | 12 | @Override 13 | public final String getName() { 14 | return name; 15 | } 16 | 17 | @Override 18 | public final int pricePerDay() { 19 | return pricePerDay; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return name; 25 | } 26 | 27 | @Override 28 | public final int compareTo(Model other) { 29 | int diff = pricePerDay - other.pricePerDay(); 30 | if (diff != 0) 31 | return diff; 32 | else 33 | return name.compareTo(other.getName()); 34 | } 35 | 36 | public abstract boolean equals(Object other); 37 | 38 | @Override 39 | public int hashCode() { 40 | return name.hashCode() ^ pricePerDay; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/Bus.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class Bus extends AbstractModel { 4 | 5 | public Bus(String name, int pricePerDay) { 6 | super(name, pricePerDay); 7 | } 8 | 9 | @Override 10 | public boolean canBeDrivenWith(License license) { 11 | return license == License.D; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object other) { 16 | return other instanceof Bus && 17 | getName().equals(((Bus) other).getName()) && 18 | pricePerDay() == ((Bus) other).pricePerDay(); 19 | } 20 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/Car.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class Car extends AbstractModel { 4 | 5 | public Car(String name, int pricePerDay) { 6 | super(name, pricePerDay); 7 | } 8 | 9 | @Override 10 | public boolean canBeDrivenWith(License license) { 11 | return license != License.A; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object other) { 16 | return other instanceof Car && 17 | getName().equals(((Car) other).getName()) && 18 | pricePerDay() == ((Car) other).pricePerDay(); 19 | } 20 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/IllegalLicenseException.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class IllegalLicenseException extends IllegalArgumentException { 4 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/License.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public enum License { 4 | A, // per moto 5 | B, // per moto e automobili 6 | C, // per moto, automobili e camion 7 | D // per moto, automobili e autobus 8 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/Model.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public interface Model extends Comparable { 4 | public String getName(); 5 | public boolean canBeDrivenWith(License license); 6 | public int pricePerDay(); 7 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/ModelNotAvailableException.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class ModelNotAvailableException extends IllegalArgumentException { 4 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/Motorbike.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class Motorbike extends AbstractModel { 4 | 5 | public Motorbike(String name, int pricePerDay) { 6 | super(name, pricePerDay); 7 | } 8 | 9 | @Override 10 | public boolean canBeDrivenWith(License license) { 11 | return true; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object other) { 16 | return other instanceof Motorbike && 17 | getName().equals(((Motorbike) other).getName()) && 18 | pricePerDay() == ((Motorbike) other).pricePerDay(); 19 | } 20 | } -------------------------------------------------------------------------------- /2019-01-29/soluzione/it/univr/rent/Truck.java: -------------------------------------------------------------------------------- 1 | package it.univr.rent; 2 | 3 | public class Truck extends AbstractModel { 4 | 5 | public Truck(String name, int pricePerDay) { 6 | super(name, pricePerDay); 7 | } 8 | 9 | @Override 10 | public boolean canBeDrivenWith(License license) { 11 | return license == License.C; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object other) { 16 | return other instanceof Truck && 17 | getName().equals(((Truck) other).getName()) && 18 | pricePerDay() == ((Truck) other).pricePerDay(); 19 | } 20 | } -------------------------------------------------------------------------------- /2019-02-04/v1/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-02-04/v1/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-02-04/v1/consegna/it/univr/agenda/AmericanTime.java: -------------------------------------------------------------------------------- 1 | package it.univr.agenda; 2 | 3 | // Ci sono 3 TODO 4 | 5 | public class AmericanTime extends Time { 6 | public enum Period { 7 | AM, PM 8 | } 9 | 10 | /** 11 | * Costruisce un istante con notazione americana. 12 | * 13 | * @param hours le ore, tra 1 e 12 14 | * @param minutes i minuti, tra 0 e 59 15 | * @param seconds i secondi, tra 0 e 59 16 | * @param period il periodo del giorno 17 | * @throws IllegalArgumentException se i parametri non fossero validi 18 | */ 19 | public AmericanTime(int hours, int minutes, int seconds, Period period) { 20 | super(0); //TODO 21 | } 22 | 23 | /** 24 | * @return una stringa nel formato hh:mm:ssPP, dove PP e' il periodo 25 | * e quindi puo' essere AM oppure PM (ore, minuti e secondi sempre su due cifre!) 26 | */ 27 | @Override 28 | public String toString() { 29 | return ""; // TODO 30 | } 31 | 32 | @Override 33 | public AmericanTime after(int minutes) { 34 | return null; // TODO 35 | } 36 | } -------------------------------------------------------------------------------- /2019-02-04/v1/consegna/it/univr/agenda/ItalianTime.java: -------------------------------------------------------------------------------- 1 | package it.univr.agenda; 2 | 3 | // Ci sono 3 TODO 4 | 5 | public class ItalianTime extends Time { 6 | 7 | /** 8 | * Costruisce un istante con notazione italiana. 9 | * 10 | * @param hours le ore, tra 0 e 23 11 | * @param minutes i minuti, tra 0 e 59 12 | * @param seconds i secondi, tra 0 e 59 13 | * @throws IllegalArgumentException se i parametri non fossero validi 14 | */ 15 | public ItalianTime(int hours, int minutes, int seconds) { 16 | super(0); //TODO 17 | } 18 | 19 | /** 20 | * @return una stringa nel formato hh:mm:ss (ore, minuti e secondi sempre su due cifre!) 21 | */ 22 | @Override 23 | public String toString() { 24 | return ""; // TODO 25 | } 26 | 27 | @Override 28 | public ItalianTime after(int minutes) { 29 | return null; // TODO 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2019-02-04/v1/consegna/risultato_main.txt: -------------------------------------------------------------------------------- 1 | 12:01:05 and 12:01:05PM are equals? true 2 | 00:01:05 and 12:01:05AM are equals? true 3 | 23:20:35 and 11:20:35PM are equals? true 4 | 00:20:35 and 12:20:35PM are equals? false 5 | illegale 6 | legale 7 | 11:59:30PM after one minute becomes 12:00:30AM 8 | 23:59:30 after one minute becomes 00:00:30 9 | shopping@15:10:00 for 60 minutes and exam@04:00:00PM for 120 minutes overlap: true 10 | dentist@15:00:00 for 60 minutes and exam@04:00:00PM for 120 minutes overlap: false 11 | -------------------------------------------------------------------------------- /2019-02-04/v2/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-02-04/v2/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-02-04/v2/consegna/risultato_main.txt: -------------------------------------------------------------------------------- 1 | 04/02/2019 and 35Q1 2019 are equals? true 2 | 04/02/2019 and 35Q2 2019 are equals? false 3 | 29/02/2020 and 60Q1 2020 are equals? true 4 | 31/12/2020 and 92Q4 2020 are equals? true 5 | illegale 6 | legale 7 | 28/02/2011 after one day becomes 01/03/2011 8 | 28/02/2012 after one day becomes 29/02/2012 9 | 31/12/2019 after one day becomes 01/01/2020 10 | 90Q1 2019 after one day becomes 01Q2 2019 11 | Lezioni di Programmazione I@01/10/2018 for 100 days and Christmas Vacation@83Q4 2018 for 12 days overlap: true 12 | Lezioni di Ingegneria del Software@60Q1 2019 for 100 days and Christmas Vacation@83Q4 2018 for 12 days overlap: false 13 | -------------------------------------------------------------------------------- /2019-02-18/v1/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-02-18/v1/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-02-18/v1/consegna/it/univr/library/CatalogWithStatistics.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * Un catalogo che stampa anche statistiche sui libri contenuti. 5 | */ 6 | public class CatalogWithStatistics extends Catalog { 7 | 8 | /** 9 | * Costruisce un catalogo con statistiche. L'ordinamento sara' quello del 10 | * compareTo definito in Book. 11 | * 12 | * @param books i libri contenuti nel catalogo. Anche se ci fossero ripetizioni, 13 | * il catalogo dovra' contenere una sola istanza del libro ripetuto 14 | */ 15 | public CatalogWithStatistics(Book... books) { 16 | //TODO 17 | } 18 | 19 | /** 20 | * Si comprta come il toString() di Catalog, ma alla fine aggiunge una riga del tipo: 21 | * "This catalog contains paper books for a total of XXX pages and audiobooks for a total of YYY minutes" 22 | */ 23 | @Override 24 | public String toString() { 25 | return ""; //TODO 26 | } 27 | } -------------------------------------------------------------------------------- /2019-02-18/v1/consegna/it/univr/library/Genre.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * I generi dei libri. 5 | */ 6 | public enum Genre { 7 | COMPUTING, 8 | FICTION, 9 | GUIDE, 10 | HISTORY 11 | } -------------------------------------------------------------------------------- /2019-02-18/v1/soluzione/it/univr/library/Genre.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * I generi dei libri. 5 | */ 6 | public enum Genre { 7 | COMPUTING, 8 | FICTION, 9 | GUIDE, 10 | HISTORY 11 | } -------------------------------------------------------------------------------- /2019-02-18/v2/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-02-18/v2/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-02-18/v2/consegna/it/univr/library/CatalogWithStatistics.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * Un catalogo che stampa anche statistiche sui libri contenuti. 5 | */ 6 | public class CatalogWithStatistics extends Catalog { 7 | 8 | /** 9 | * Costruisce un catalogo con statistiche. L'ordinamento sara' quello del 10 | * compareTo definito in Book. 11 | * 12 | * @param books i libri contenuti nel catalogo. Anche se ci fossero ripetizioni, 13 | * il catalogo dovra' contenere una sola istanza del libro ripetuto 14 | */ 15 | public CatalogWithStatistics(Book... books) { 16 | //TODO 17 | } 18 | 19 | /** 20 | * Si comprta come il toString() di Catalog, ma alla fine aggiunge una riga del tipo: 21 | * "This catalog contains paper books for a total of XXX pages and audiobooks for a total of YYY minutes" 22 | */ 23 | @Override 24 | public String toString() { 25 | return ""; //TODO 26 | } 27 | } -------------------------------------------------------------------------------- /2019-02-18/v2/consegna/it/univr/library/Genre.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * I generi dei libri. 5 | */ 6 | public enum Genre { 7 | COMPUTING, 8 | FICTION, 9 | GUIDE, 10 | HISTORY 11 | } -------------------------------------------------------------------------------- /2019-02-18/v2/soluzione/it/univr/library/Genre.java: -------------------------------------------------------------------------------- 1 | package it.univr.library; 2 | 3 | /** 4 | * I generi dei libri. 5 | */ 6 | public enum Genre { 7 | COMPUTING, 8 | FICTION, 9 | GUIDE, 10 | HISTORY 11 | } -------------------------------------------------------------------------------- /2019-06-24/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-06-24/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-06-24/consegna/it/univr/tictactoe/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Player alessandra = new Player("Alessandra"); 6 | Player giovanni = new Player("Giovanni"); 7 | //TODO 8 | } 9 | } -------------------------------------------------------------------------------- /2019-06-24/consegna/it/univr/tictactoe/Player.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | public class Player { 4 | private final String name; 5 | 6 | public Player(String name) { 7 | this.name = name; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return name; 13 | } 14 | } -------------------------------------------------------------------------------- /2019-06-24/consegna/risultato_main.txt: -------------------------------------------------------------------------------- 1 | | | 2 | ----- 3 | | | 4 | ----- 5 | | | 6 | Gioca Alessandra 7 | x: 2 8 | y: 2 9 | 10 | | | 11 | ----- 12 | |X| 13 | ----- 14 | | | 15 | Gioca Giovanni 16 | x: 4 17 | y: 3 18 | coordinates must be between 1 and 3 19 | Gioca Giovanni 20 | x: 1 21 | y: 1 22 | 23 | O| | 24 | ----- 25 | |X| 26 | ----- 27 | | | 28 | Gioca Alessandra 29 | x: 2 30 | y: 1 31 | 32 | O|X| 33 | ----- 34 | |X| 35 | ----- 36 | | | 37 | Gioca Giovanni 38 | x: 2 39 | y: 1 40 | the selected tile is not empty 41 | Gioca Giovanni 42 | x: 1 43 | y: 2 44 | 45 | O|X| 46 | ----- 47 | O|X| 48 | ----- 49 | | | 50 | Gioca Alessandra 51 | x: 2 52 | y: 3 53 | 54 | O|X| 55 | ----- 56 | O|X| 57 | ----- 58 | |X| 59 | -------------------------------------------------------------------------------- /2019-06-24/consegna/tictactoe_draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-06-24/consegna/tictactoe_draw.png -------------------------------------------------------------------------------- /2019-06-24/consegna/tictactoe_grid_linear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-06-24/consegna/tictactoe_grid_linear.png -------------------------------------------------------------------------------- /2019-06-24/consegna/tictactoe_wins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-06-24/consegna/tictactoe_wins.png -------------------------------------------------------------------------------- /2019-06-24/soluzione/it/univr/tictactoe/FullTicTacToe.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | /** 4 | * Un gioco del tris, in cui il gioco termina quando tutte le caselle 5 | * sono state riempite oppure quando un giocatore ha piazzato tre 6 | * simboli uguali su una riga o su una colonna o su una diagonale. 7 | */ 8 | public class FullTicTacToe extends RowsTicTacToe { 9 | 10 | @Override 11 | public boolean isGameOver() { 12 | // prima diagonale 13 | if (at(1, 1) != Tile.EMPTY && at(1, 1) == at(2, 2) && at(2, 2) == at(3, 3)) 14 | return true; 15 | 16 | // seconda diagonale 17 | if (at(3, 1) != Tile.EMPTY && at(3, 1) == at(2, 2) && at(2, 2) == at(1, 3)) 18 | return true; 19 | 20 | // oppure righe, colonne o tutte le caselle sono riempite 21 | return super.isGameOver(); 22 | } 23 | } -------------------------------------------------------------------------------- /2019-06-24/soluzione/it/univr/tictactoe/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Player alessandra = new Player("Alessandra"); 8 | Player giovanni = new Player("Giovanni"); 9 | 10 | TicTacToe tictactoe = new FullTicTacToe(); 11 | Player currentPlayer = alessandra; 12 | System.out.println(tictactoe); 13 | 14 | try (Scanner keyboard = new Scanner(System.in)) { 15 | do { 16 | int x, y; 17 | 18 | System.out.println("Gioca " + currentPlayer); 19 | System.out.print("x: "); x = keyboard.nextInt(); 20 | System.out.print("y: "); y = keyboard.nextInt(); 21 | 22 | try { 23 | tictactoe.play(currentPlayer, x, y); 24 | currentPlayer = currentPlayer == alessandra ? giovanni : alessandra; 25 | System.out.println("\n" + tictactoe); 26 | } 27 | catch (IllegalArgumentException | IllegalStateException e) { 28 | System.out.println(e.getMessage()); 29 | } 30 | } 31 | while (!tictactoe.isGameOver()); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /2019-06-24/soluzione/it/univr/tictactoe/Player.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | public class Player { 4 | private final String name; 5 | 6 | public Player(String name) { 7 | this.name = name; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return name; 13 | } 14 | } -------------------------------------------------------------------------------- /2019-06-24/soluzione/it/univr/tictactoe/RowsTicTacToe.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | /** 4 | * Un gioco del tris, in cui il gioco termina quando tutte le caselle 5 | * sono state riempite oppure quando un giocatore ha piazzato tre 6 | * simboli uguali su una riga o su una colonna. 7 | */ 8 | public class RowsTicTacToe extends SimpleTicTacToe { 9 | 10 | @Override 11 | public boolean isGameOver() { 12 | // righe 13 | for (int y = 1; y <= 3; y++) 14 | if (at(1, y) != Tile.EMPTY && at(1, y) == at(2, y) && at(2, y) == at(3, y)) 15 | return true; 16 | 17 | // colonne 18 | for (int x = 1; x <= 3; x++) 19 | if (at(x, 1) != Tile.EMPTY && at(x, 1) == at(x, 2) && at(x, 2) == at(x, 3)) 20 | return true; 21 | 22 | // oppure tutte le caselle sono riempite 23 | return super.isGameOver(); 24 | } 25 | } -------------------------------------------------------------------------------- /2019-06-24/soluzione/it/univr/tictactoe/SimpleTicTacToe.java: -------------------------------------------------------------------------------- 1 | package it.univr.tictactoe; 2 | 3 | /** 4 | * Un gioco del tris, in cui il gioco termina solo quando tutte le caselle 5 | * sono state riempite. 6 | */ 7 | public class SimpleTicTacToe extends TicTacToe { 8 | 9 | @Override 10 | public boolean isGameOver() { 11 | for (int x = 1; x <= 3; x++) 12 | for (int y = 1; y <= 3; y++) 13 | if (at(x, y) == Tile.EMPTY) 14 | return false; 15 | 16 | return true; 17 | } 18 | } -------------------------------------------------------------------------------- /2019-07-25/consegna/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | // TODO 4 | } 5 | } -------------------------------------------------------------------------------- /2019-07-25/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-07-25/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-07-25/consegna/project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-07-25/consegna/project.png -------------------------------------------------------------------------------- /2019-07-25/consegna/try_this.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-07-25/consegna/try_this.txt -------------------------------------------------------------------------------- /2019-09-26/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-09-26/consegna/compito.pdf -------------------------------------------------------------------------------- /2019-09-26/consegna/g1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-09-26/consegna/g1.pdf -------------------------------------------------------------------------------- /2019-09-26/consegna/g2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2019-09-26/consegna/g2.pdf -------------------------------------------------------------------------------- /2019-09-26/consegna/it/univr/graph/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.graph; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // un grafo di stringhe 6 | //TODO 7 | // un grafo di interi 8 | //TODO 9 | // un altro grafo di stringhe, con un unico nodo legato a un nodo del primo grafo 10 | //TODO 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2019-09-26/consegna/output.txt: -------------------------------------------------------------------------------- 1 | digraph { 2 | node0 [label="hello"] 3 | node0 -> node0 4 | node0 -> node2 5 | node0 -> node4 6 | node1 [label="how", style="filled", fillcolor="red"] 7 | node2 [label="are", style="filled", fillcolor="red"] 8 | node2 -> node2 9 | node2 -> node4 10 | node3 [label="you?"] 11 | node4 [label="hello"] 12 | node4 -> node0 13 | } 14 | 15 | digraph { 16 | node0 [label="17", style="filled", fillcolor="red"] 17 | node0 -> node1 18 | node1 [label="42"] 19 | node1 -> node0 20 | } 21 | 22 | Exception in thread "main" java.lang.IllegalArgumentException: Cannot link nodes from distinct graphs 23 | at it.univr.graph.Graph$Node.linkTo(Graph.java:62) 24 | at it.univr.graph.Main.main(Main.java:32) 25 | -------------------------------------------------------------------------------- /2020-02-05/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2020-02-05/consegna/compito.pdf -------------------------------------------------------------------------------- /2020-02-05/consegna/it/univr/cards/Ranking.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | public enum Ranking { 4 | // in ordine di ranking crescente 5 | NONE 6 | // TODO: aggiungete gli altri ranking dopo NONE 7 | } 8 | -------------------------------------------------------------------------------- /2020-02-05/consegna/it/univr/cards/Suit.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | /** 4 | * I quattro semi possibili per una carta. 5 | */ 6 | public enum Suit { 7 | SPADES, // picche 8 | CLUBS, // fiori 9 | DIAMONDS, // quadri 10 | HEARTS // cuori 11 | } -------------------------------------------------------------------------------- /2020-02-05/consegna/it/univr/cards/Value.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | /** 4 | * I valori possibili per una carta, dal due all'asso. 5 | */ 6 | public enum Value { 7 | TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE 8 | } -------------------------------------------------------------------------------- /2020-02-05/soluzione/it/univr/cards/Ranking.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | public enum Ranking { 4 | // in ordine di ranking crescente 5 | NONE, 6 | THREE_OF_KIND, 7 | STRAIGHT, 8 | FLUSH, 9 | FULL_HOUSE, 10 | FOUR_OF_KIND, 11 | STRAIGHT_FLUSH 12 | } 13 | -------------------------------------------------------------------------------- /2020-02-05/soluzione/it/univr/cards/Suit.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | /** 4 | * I quattro semi possibili per una carta. 5 | */ 6 | public enum Suit { 7 | SPADES, // picche 8 | CLUBS, // fiori 9 | DIAMONDS, // quadri 10 | HEARTS // cuori 11 | } -------------------------------------------------------------------------------- /2020-02-05/soluzione/it/univr/cards/Value.java: -------------------------------------------------------------------------------- 1 | package it.univr.cards; 2 | 3 | /** 4 | * I valori possibili per una carta, dal due all'asso. 5 | */ 6 | public enum Value { 7 | TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE 8 | } -------------------------------------------------------------------------------- /2021-04-30/esame_1/module-info.java: -------------------------------------------------------------------------------- 1 | module esame_1 { 2 | } -------------------------------------------------------------------------------- /2021-04-30/esame_1_soluzione/module-info.java: -------------------------------------------------------------------------------- 1 | module esame_1 { 2 | } -------------------------------------------------------------------------------- /2021-04-30/esame_2/module-info.java: -------------------------------------------------------------------------------- 1 | module esame_2 { 2 | } -------------------------------------------------------------------------------- /2021-04-30/esame_2_soluzione/module-info.java: -------------------------------------------------------------------------------- 1 | module esame_2 { 2 | } -------------------------------------------------------------------------------- /2021-06-17/consegna/Book.java: -------------------------------------------------------------------------------- 1 | package it.univr.books; 2 | 3 | public class Book { 4 | public final String title; 5 | public final int pages; 6 | public final int height; 7 | public final LANGUAGE language; 8 | 9 | public enum LANGUAGE { 10 | ITALIAN, 11 | ENGLISH, 12 | FRENCH 13 | } 14 | 15 | public Book(String title, int pages, int height, LANGUAGE language) { 16 | this.title = title; 17 | this.pages = pages; 18 | this.height = height; 19 | this.language = language; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return title; 25 | } 26 | } -------------------------------------------------------------------------------- /2021-06-17/soluzione/Book.java: -------------------------------------------------------------------------------- 1 | package it.univr.books; 2 | 3 | public class Book { 4 | public final String title; 5 | public final int pages; 6 | public final int height; 7 | public final LANGUAGE language; 8 | 9 | public enum LANGUAGE { 10 | ITALIAN, 11 | ENGLISH, 12 | FRENCH 13 | } 14 | 15 | public Book(String title, int pages, int height, LANGUAGE language) { 16 | this.title = title; 17 | this.pages = pages; 18 | this.height = height; 19 | this.language = language; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return title; 25 | } 26 | } -------------------------------------------------------------------------------- /2021-06-17/soluzione/LibraryBySize.java: -------------------------------------------------------------------------------- 1 | package it.univr.books; 2 | 3 | import java.util.Set; 4 | import java.util.TreeSet; 5 | 6 | public class LibraryBySize extends Library { 7 | 8 | public LibraryBySize(int height) { 9 | super(height); 10 | } 11 | 12 | @Override 13 | protected Set makeSet() { 14 | // oppure usando una classe interna che implementa Comparator 15 | return new TreeSet<>(this::compare); 16 | } 17 | 18 | private int compare(Book book1, Book book2) { 19 | int diff = book1.height - book2.height; 20 | if (diff != 0) 21 | return diff; 22 | else 23 | return book1.title.compareTo(book2.title); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2021-06-17/soluzione/LibraryEnglishFirst.java: -------------------------------------------------------------------------------- 1 | package it.univr.books; 2 | 3 | import java.util.Set; 4 | import java.util.TreeSet; 5 | 6 | public class LibraryEnglishFirst extends Library { 7 | 8 | public LibraryEnglishFirst(int height) { 9 | super(height); 10 | } 11 | 12 | @Override 13 | protected Set makeSet() { 14 | // oppure usando una classe interna che implementa Comparator 15 | return new TreeSet<>(this::compare); 16 | } 17 | 18 | private int compare(Book book1, Book book2) { 19 | if (book1.language == Book.LANGUAGE.ENGLISH && book2.language != Book.LANGUAGE.ENGLISH) 20 | return -1; 21 | else if (book2.language == Book.LANGUAGE.ENGLISH && book1.language != Book.LANGUAGE.ENGLISH) 22 | return 1; 23 | else 24 | return book1.title.compareTo(book2.title); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2021-07-20/soluzione/BankException.java: -------------------------------------------------------------------------------- 1 | package it.univr.bank; 2 | 3 | public class BankException extends Exception { 4 | } -------------------------------------------------------------------------------- /2021-09-01/consegna/Main.java: -------------------------------------------------------------------------------- 1 | // MAIN DI PROVA: NON DOVETE MODIFICARE NULLA 2 | 3 | package it.univr.dates; 4 | 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | System.out.println("Ecco le date del 2021:"); 11 | for (Date date: Dates.of(2021)) 12 | System.out.println(date); 13 | 14 | System.out.println("Ecco 5 date casuali tra il 2000 e il 2100:"); 15 | for (Date date: Dates.random(5)) 16 | System.out.println(date); 17 | 18 | try (Scanner keyboard = new Scanner(System.in)) { 19 | System.out.print("Quante date vuoi stampare? "); 20 | int howMany = keyboard.nextInt(); 21 | System.out.println("Ecco le prime " + howMany + " date a partire dal 2021:"); 22 | for (Date date: Dates.from(2021)) { 23 | if (howMany-- <= 0) 24 | break; 25 | 26 | System.out.println(date); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /2021-09-01/soluzione/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.dates; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("Ecco le date del 2021:"); 9 | for (Date date: Dates.of(2021)) 10 | System.out.println(date); 11 | 12 | System.out.println("Ecco 5 date casuali tra il 2000 e il 2100:"); 13 | for (Date date: Dates.random(5)) 14 | System.out.println(date); 15 | 16 | try (Scanner keyboard = new Scanner(System.in)) { 17 | System.out.print("Quante date vuoi stampare? "); 18 | int howMany = keyboard.nextInt(); 19 | System.out.println("Ecco le prime " + howMany + " date a partire dal 2021:"); 20 | for (Date date: Dates.from(2021)) { 21 | if (howMany-- <= 0) 22 | break; 23 | 24 | System.out.println(date); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2022-02-02/v1/consegna/compito-v1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-02-02/v1/consegna/compito-v1.pdf -------------------------------------------------------------------------------- /2022-02-02/v1/consegna/it/univr/identifiers/CamelStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | // TODO: fate compilare questa classe 4 | 5 | public class CamelStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore camel-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public CamelStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public CamelStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore camel-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public CamelStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore snake-style con le stesse parole di this 25 | public SnakeStyleIdentifier toSnakeStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v1/consegna/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v1/consegna/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | //TODO: fate compilare questa classe 4 | 5 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public SnakeStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public SnakeStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore snake-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore camel-style con le stesse parole di this 25 | public CamelStyleIdentifier toCamelStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v1/soluzione/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v1/soluzione/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 4 | 5 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 6 | // fallisce nelle stesse condizioni del costruttore della superclasse 7 | public SnakeStyleIdentifier(String... words) { 8 | super(words); 9 | } 10 | 11 | // come sopra 12 | public SnakeStyleIdentifier(Iterable words) { 13 | super(words); 14 | } 15 | 16 | // costruisce un identificatore snake-style le cui parole componenti 17 | // sono la concatenazione delle parole degli ids 18 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 19 | super(concat(ids)); 20 | } 21 | 22 | // restituisce un identificatore camel-style con le stesse parole di this 23 | public CamelStyleIdentifier toCamelStyle() { 24 | return new CamelStyleIdentifier(this); 25 | } 26 | 27 | @Override 28 | protected String toString(int pos, String word) { 29 | return pos == 0 ? word : ("_" + word); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-02-02/v2/consegna/compito-v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-02-02/v2/consegna/compito-v2.pdf -------------------------------------------------------------------------------- /2022-02-02/v2/consegna/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v2/consegna/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | //TODO: fate compilare questa classe 4 | 5 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public SnakeStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public SnakeStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore snake-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore vowel-style con le stesse parole di this 25 | public VowelStyleIdentifier toVowelStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v2/consegna/it/univr/identifiers/VowelStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | // TODO: fate compilare questa classe 4 | 5 | public class VowelStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore vowel-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public VowelStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public VowelStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore vowel-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public VowelStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore snake-style con le stesse parole di this 25 | public SnakeStyleIdentifier toSnakeStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v2/soluzione/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v2/soluzione/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 4 | 5 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 6 | // fallisce nelle stesse condizioni del costruttore della superclasse 7 | public SnakeStyleIdentifier(String... words) { 8 | super(words); 9 | } 10 | 11 | // come sopra 12 | public SnakeStyleIdentifier(Iterable words) { 13 | super(words); 14 | } 15 | 16 | // costruisce un identificatore snake-style le cui parole componenti 17 | // sono la concatenazione delle parole degli ids 18 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 19 | super(concat(ids)); 20 | } 21 | 22 | // restituisce un identificatore vowel-style con le stesse parole di this 23 | public VowelStyleIdentifier toVowelStyle() { 24 | return new VowelStyleIdentifier(this); 25 | } 26 | 27 | @Override 28 | protected String toString(int pos, String word) { 29 | return pos == 0 ? word : ("_" + word); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-02-02/v3/consegna/compito-v3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-02-02/v3/consegna/compito-v3.pdf -------------------------------------------------------------------------------- /2022-02-02/v3/consegna/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v3/consegna/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | //TODO: fate compilare questa classe 4 | 5 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public SnakeStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public SnakeStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore snake-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore three-style con le stesse parole di this 25 | public ThreeStyleIdentifier toThreeStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v3/consegna/it/univr/identifiers/ThreeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | // TODO: fate compilare questa classe 4 | 5 | public class ThreeStyleIdentifier extends MultiWordIdentifier { 6 | 7 | // costruisce un identicatore three-style le cui parole sono quelle indicate; 8 | // fallisce nelle stesse condizioni del costruttore della superclasse 9 | public ThreeStyleIdentifier(String... words) { 10 | // TODO 11 | } 12 | 13 | // come sopra 14 | public ThreeStyleIdentifier(Iterable words) { 15 | // TODO 16 | } 17 | 18 | // costruisce un identificatore three-style le cui parole componenti 19 | // sono la concatenazione delle parole degli ids 20 | public ThreeStyleIdentifier(MultiWordIdentifier... ids) { 21 | // TODO 22 | } 23 | 24 | // restituisce un identificatore snake-style con le stesse parole di this 25 | public SnakeStyleIdentifier toSnakeStyle() { 26 | // TODO 27 | return null; 28 | } 29 | } -------------------------------------------------------------------------------- /2022-02-02/v3/soluzione/it/univr/identifiers/Identifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public interface Identifier { 4 | 5 | // Restituisce la stringa che si ottiene stampando l'identificatore. 6 | public String toString(); 7 | } -------------------------------------------------------------------------------- /2022-02-02/v3/soluzione/it/univr/identifiers/SnakeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class SnakeStyleIdentifier extends MultiWordIdentifier { 4 | 5 | // costruisce un identicatore snake-style le cui parole sono quelle indicate; 6 | // fallisce nelle stesse condizioni del costruttore della superclasse 7 | public SnakeStyleIdentifier(String... words) { 8 | super(words); 9 | } 10 | 11 | // come sopra 12 | public SnakeStyleIdentifier(Iterable words) { 13 | super(words); 14 | } 15 | 16 | // costruisce un identificatore snake-style le cui parole componenti 17 | // sono la concatenazione delle parole degli ids 18 | public SnakeStyleIdentifier(MultiWordIdentifier... ids) { 19 | super(concat(ids)); 20 | } 21 | 22 | // restituisce un identificatore three-style con le stesse parole di this 23 | public ThreeStyleIdentifier toThreeStyle() { 24 | return new ThreeStyleIdentifier(this); 25 | } 26 | 27 | @Override 28 | protected String toString(int pos, String word) { 29 | return pos == 0 ? word : ("_" + word); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-02-02/v3/soluzione/it/univr/identifiers/ThreeStyleIdentifier.java: -------------------------------------------------------------------------------- 1 | package it.univr.identifiers; 2 | 3 | public class ThreeStyleIdentifier extends MultiWordIdentifier { 4 | 5 | // costruisce un identicatore three-style le cui parole sono quelle indicate; 6 | // fallisce nelle stesse condizioni del costruttore della superclasse 7 | public ThreeStyleIdentifier(String... words) { 8 | super(words); 9 | } 10 | 11 | // come sopra 12 | public ThreeStyleIdentifier(Iterable words) { 13 | super(words); 14 | } 15 | 16 | // costruisce un identificatore three-style le cui parole componenti 17 | // sono la concatenazione delle parole degli ids 18 | public ThreeStyleIdentifier(MultiWordIdentifier... ids) { 19 | super(concat(ids)); 20 | } 21 | 22 | // restituisce un identificatore snake-style con le stesse parole di this 23 | public SnakeStyleIdentifier toSnakeStyle() { 24 | return new SnakeStyleIdentifier(this); 25 | } 26 | 27 | @Override 28 | protected String toString(int pos, String word) { 29 | return word.substring(0, Math.min(3, word.length())); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-03-04/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-03-04/consegna/compito.pdf -------------------------------------------------------------------------------- /2022-03-04/consegna/it/univr/supermarket/ProductNotExpiring.java: -------------------------------------------------------------------------------- 1 | package it.univr.supermarket; 2 | 3 | /** 4 | * Un prodotto che non scade mai. 5 | */ 6 | public class ProductNotExpiring extends Product { 7 | 8 | // TODO: campi? 9 | 10 | /** 11 | * Costruisce un prodotto senza scadenza. 12 | * 13 | * @param name il nome del prodotto 14 | * @param price il prezzo in euro del prodotto 15 | * @throws IllegalArgumentException se name e' null oppure vuota oppure se price e' negativo 16 | */ 17 | public ProductNotExpiring(String name, double price) { 18 | // TODO 19 | } 20 | 21 | // TODO 22 | } 23 | -------------------------------------------------------------------------------- /2022-03-04/consegna/it/univr/supermarket/ProductWithExpiration.java: -------------------------------------------------------------------------------- 1 | package it.univr.supermarket; 2 | 3 | /** 4 | * Un prodotto con un momento di scadenza. 5 | */ 6 | public class ProductWithExpiration extends Product { 7 | 8 | // TODO: campi? 9 | 10 | /** 11 | * Costruisce un prodotto con una scadenza. 12 | * 13 | * @param name il nome del prodotto 14 | * @param price il prezzo in euro del prodotto 15 | * @param whenProduced il momento di produzione (millisecondi da 1/1/1970) 16 | * @param duration il numero di giorni, successivi all produzione, dopo i quali il prodotto scade 17 | * @throws IllegalArgumentException se name e' null oppure vuota oppure se price e' negativo 18 | * oppure se whenProduced e' negativo oppure su duration e' negativo 19 | */ 20 | public ProductWithExpiration(String name, double price, long whenProduced, int duration) { 21 | // TODO 22 | } 23 | 24 | // TODO 25 | } 26 | -------------------------------------------------------------------------------- /2022-03-04/soluzione/it/univr/supermarket/ProductNotExpiring.java: -------------------------------------------------------------------------------- 1 | package it.univr.supermarket; 2 | 3 | /** 4 | * Un prodotto che non scade mai. 5 | */ 6 | public class ProductNotExpiring extends Product { 7 | 8 | /** 9 | * Costruisce un prodotto senza scadenza. 10 | * 11 | * @param name il nome del prodotto 12 | * @param price il prezzo in euro del prodotto 13 | * @throws IllegalArgumentException se name e' null oppure vuota oppure se price e' negativo 14 | */ 15 | public ProductNotExpiring(String name, double price) { 16 | super(name, price); 17 | } 18 | 19 | @Override 20 | public boolean hasExpired(long whenChecked) { 21 | return false; 22 | } 23 | 24 | @Override 25 | protected int compareExpiration(Product other) { 26 | return other instanceof ProductWithExpiration ? 1 : 0; 27 | } 28 | } -------------------------------------------------------------------------------- /2022-06-16/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-06-16/consegna/compito.pdf -------------------------------------------------------------------------------- /2022-06-16/consegna/it/univr/dadi/Dado.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un dado ha un numero prefissato di facce e può essere lanciato. 5 | */ 6 | public abstract class Dado { 7 | 8 | /** 9 | * Il numero di facce del dado. Si noti che e' pubblico. 10 | */ 11 | public final int facce; 12 | 13 | /** 14 | * Costruisce un dado con un numero prefissato di facce. 15 | * Lancia IllegalArgumentException il numero di facce non e' positivo. 16 | */ 17 | protected Dado(int facce) { 18 | // completare 19 | } 20 | 21 | /** 22 | * Restituisce un numero casuale fra 1 (incluso) e il numero di facce del dado (incluso). 23 | */ 24 | public final int lancio() { 25 | // completare 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2022-06-16/consegna/it/univr/dadi/LanciBarreDiverse.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un tipo speciale di classe Lanci dove le barre degli istogrammi 5 | * sono stampate usando alternativamente i caratteri *, @ e + 6 | * (la prima barra usa *, la second @, la terza + e cosi' via 7 | * ciclicamente). 8 | */ 9 | public class LanciBarreDiverse extends Lanci { 10 | 11 | public LanciBarreDiverse(int quanti, Dado... dadi) { 12 | // completare 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2022-06-16/soluzione/it/univr/dadi/D10.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un dado a dieci facce. 5 | */ 6 | public class D10 extends Dado { 7 | 8 | public D10() { 9 | super(10); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022-06-16/soluzione/it/univr/dadi/D6.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un dado a sei facce. 5 | */ 6 | public class D6 extends Dado { 7 | 8 | public D6() { 9 | super(6); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022-06-16/soluzione/it/univr/dadi/D8.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un dado a otto facce. 5 | */ 6 | public class D8 extends Dado { 7 | 8 | public D8() { 9 | super(8); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022-06-16/soluzione/it/univr/dadi/Dado.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Un dado ha un numero prefissato di facce e può essere lanciato. 7 | */ 8 | public abstract class Dado { 9 | private final static Random random = new Random(); 10 | 11 | /** 12 | * Il numero di facce del dado. Si noti che e' pubblico. 13 | */ 14 | public final int facce; 15 | 16 | /** 17 | * Costruisce un dado con un numero prefissato di facce. 18 | * Lancia IllegalArgumentException il numero di facce non e' positivo. 19 | */ 20 | protected Dado(int facce) { 21 | if (facce <= 0) 22 | throw new IllegalArgumentException("Un dado deve avere almeno una faccia"); 23 | 24 | this.facce = facce; 25 | } 26 | 27 | /** 28 | * Restituisce un numero casuale fra 1 (incluso) e il numero di facce del dado (incluso). 29 | */ 30 | public final int lancio() { 31 | return random.nextInt(facce) + 1; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /2022-06-16/soluzione/it/univr/dadi/LanciBarreDiverse.java: -------------------------------------------------------------------------------- 1 | package it.univr.dadi; 2 | 3 | /** 4 | * Un tipo speciale di classe Lanci dove le barre degli istogrammi 5 | * sono stampate usando alternativamente i caratteri *, @ e + 6 | * (la prima barra usa *, la second @, la terza + e cosi' via 7 | * ciclicamente). 8 | */ 9 | public class LanciBarreDiverse extends Lanci { 10 | 11 | public LanciBarreDiverse(int quanti, Dado... dadi) { 12 | super(quanti, dadi); 13 | } 14 | 15 | @Override 16 | protected String barra(int i, double frequenza) { 17 | String barra = ""; 18 | for (int j = 1; j <= frequenza; j++) 19 | barra += "*@+".charAt(i % 3); 20 | 21 | return barra; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /2022-07-05/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-07-05/consegna/compito.pdf -------------------------------------------------------------------------------- /2022-07-05/consegna/it/univr/elezioni/ElezioniVincitore.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | /** 4 | * Un tipo di elezione la cui stampa aggiunge l'indicazione 5 | * di quale partito ha vinto le elezioni. 6 | */ 7 | public class ElezioniVincitore extends Elezioni { 8 | 9 | /** 10 | * Si comporta come il toString() della superclasse, ma in piu' 11 | * aggiunge in fondo l'indicazione del partito che ha vinto le elezioni, 12 | * del tipo "Vince X". 13 | * In particolare, vince l'elezione il partito che ha ottenuto piu' voti. 14 | * A parita' di voti, vince il partito che viene prima in ordine alfabetico. 15 | * Se non ci fossero partiti (elezione vuota), aggiunge l'indicazione 16 | * "Non ci sono vincitori". 17 | */ 18 | @Override 19 | public String toString() { 20 | return ""; // modificare 21 | } 22 | } -------------------------------------------------------------------------------- /2022-07-05/consegna/it/univr/elezioni/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | import java.util.Random; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | // creo cinque partiti 9 | Partito[] partiti = new Partito[] { 10 | new Partito("Pensionati"), 11 | new Partito("Felice"), 12 | new Partito("Floreale"), 13 | new Partito("Caotico"), 14 | new Partito("Bassotti") 15 | }; 16 | 17 | // elezioni inizialmente vuote 18 | Elezioni elezioni = new ElezioniVincitore(); 19 | 20 | // aggiungo dei voti casuali per i partiti 21 | Random random = new Random(); 22 | for (Partito partito: partiti) { 23 | int voti = random.nextInt(10000); 24 | for (int i = 0; i < voti; i++) 25 | elezioni.vota(partito); 26 | } 27 | 28 | // stampo le elezioni con indicazione di vincitore 29 | System.out.println(elezioni); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-07-05/consegna/it/univr/elezioni/Partito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | /** 4 | * Un partito ha un nome, passato al momento della costruzione. 5 | */ 6 | public class Partito implements Comparable { 7 | 8 | public Partito(String nome) { 9 | // completare 10 | } 11 | 12 | /** 13 | * Determina chi fra this e other viene prima in ordine alfabetico per nome. 14 | */ 15 | @Override 16 | public int compareTo(Partito other) { 17 | return 0; // modificare 18 | } 19 | 20 | // due partiti sono uguali se e solo se hanno nome uguale 21 | @Override 22 | public boolean equals(Object other) { 23 | return false; // modificare 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return 0; // modificare in modo che sia non banale 29 | } 30 | 31 | /** 32 | * Restituisce il nome del partito. 33 | */ 34 | @Override 35 | public String toString() { 36 | return ""; // modificare 37 | } 38 | } -------------------------------------------------------------------------------- /2022-07-05/consegna/it/univr/elezioni/VotiPerPartito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | /** 4 | * Una coppia partito/voti ottenuti. 5 | */ 6 | public class VotiPerPartito { 7 | public final Partito partito; 8 | public final int voti; 9 | 10 | public VotiPerPartito(Partito partito, int voti) { 11 | this.partito = partito; 12 | this.voti = voti; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return partito + ": " + voti; 18 | } 19 | } -------------------------------------------------------------------------------- /2022-07-05/soluzione/it/univr/elezioni/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | import java.util.Random; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | // creo cinque partiti 9 | Partito[] partiti = new Partito[] { 10 | new Partito("Pensionati"), 11 | new Partito("Felice"), 12 | new Partito("Floreale"), 13 | new Partito("Caotico"), 14 | new Partito("Bassotti") 15 | }; 16 | 17 | // elezioni inizialmente vuote 18 | Elezioni elezioni = new ElezioniVincitore(); 19 | 20 | // aggiungo dei voti casuali per i partiti 21 | Random random = new Random(); 22 | for (Partito partito: partiti) { 23 | int voti = random.nextInt(10000); 24 | for (int i = 0; i < voti; i++) 25 | elezioni.vota(partito); 26 | } 27 | 28 | // stampo le elezioni con indicazione di vincitore 29 | System.out.println(elezioni); 30 | } 31 | } -------------------------------------------------------------------------------- /2022-07-05/soluzione/it/univr/elezioni/Partito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | /** 4 | * Un partito ha un nome, passato al momento della costruzione. 5 | */ 6 | public class Partito implements Comparable { 7 | private final String nome; 8 | 9 | public Partito(String nome) { 10 | this.nome = nome; 11 | } 12 | 13 | /** 14 | * Determina chi fra this e other viene prima in ordine alfabetico per nome. 15 | */ 16 | @Override 17 | public int compareTo(Partito other) { 18 | return nome.compareTo(other.nome); 19 | } 20 | 21 | // due partiti sono uguali se e solo se hanno nome uguale 22 | @Override 23 | public boolean equals(Object other) { 24 | return other instanceof Partito && nome.equals(((Partito) other).nome); 25 | } 26 | 27 | // non banale 28 | @Override 29 | public int hashCode() { 30 | return nome.hashCode(); 31 | } 32 | 33 | /** 34 | * Restituisce il nome del partito. 35 | */ 36 | @Override 37 | public String toString() { 38 | return nome; 39 | } 40 | } -------------------------------------------------------------------------------- /2022-07-05/soluzione/it/univr/elezioni/VotiPerPartito.java: -------------------------------------------------------------------------------- 1 | package it.univr.elezioni; 2 | 3 | /** 4 | * Una coppia partito/voti ottenuti. 5 | */ 6 | public class VotiPerPartito { 7 | public final Partito partito; 8 | public final int voti; 9 | 10 | public VotiPerPartito(Partito partito, int voti) { 11 | this.partito = partito; 12 | this.voti = voti; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return partito + ": " + voti; 18 | } 19 | } -------------------------------------------------------------------------------- /2022-09-02/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2022-09-02/consegna/compito.pdf -------------------------------------------------------------------------------- /2022-09-02/consegna/it/univr/letters/Letters.java: -------------------------------------------------------------------------------- 1 | package it.univr.letters; 2 | 3 | import java.util.function.Consumer; 4 | 5 | /** 6 | * Una sequenza di lettere (cioe' caratteri alfabetici). 7 | */ 8 | public interface Letters { 9 | 10 | /** 11 | * Restituisce la lunghezza della sequenza. 12 | */ 13 | int length(); 14 | 15 | /** 16 | * Restituisce la concatenazione delle lettere della sequenza. 17 | */ 18 | String toString(); 19 | 20 | /** 21 | * Applica il comando indicato alle lettere della sequenza 22 | * (dalla prima all'ultima). 23 | */ 24 | void forEach(Consumer command); 25 | } -------------------------------------------------------------------------------- /2022-09-02/soluzione/it/univr/letters/Letters.java: -------------------------------------------------------------------------------- 1 | package it.univr.letters; 2 | 3 | import java.util.function.Consumer; 4 | 5 | /** 6 | * Una sequenza di lettere (cioe' caratteri alfabetici). 7 | */ 8 | public interface Letters { 9 | 10 | /** 11 | * Restituisce la lunghezza della sequenza. 12 | */ 13 | int length(); 14 | 15 | /** 16 | * Restituisce la concatenazione delle lettere della sequenza. 17 | */ 18 | String toString(); 19 | 20 | /** 21 | * Applica il comando indicato alle lettere della sequenza 22 | * (dalla prima all'ultima). 23 | */ 24 | void forEach(Consumer command); 25 | } -------------------------------------------------------------------------------- /2023-02-09/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2023-02-09/consegna/compito.pdf -------------------------------------------------------------------------------- /2023-02-09/consegna/it/univr/doodle/Person.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | // si renda questa classe comparabile con un'altra Person: 4 | // ordinando prima per priorita' crescente e poi alfabeticamente per nome 5 | // nota: dovrete aggiungere un metodo public: quale? 6 | public abstract class Person { 7 | private final String name; 8 | 9 | protected Person(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return ""; // deve restituire il nome 16 | } 17 | 18 | public abstract int priority(); 19 | 20 | public boolean equals(Object other) { 21 | return false; // devono avere stesso nome e stessa priorità 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/CEO.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public class CEO extends Person { 4 | 5 | public CEO(String name) { 6 | super(name); 7 | } 8 | 9 | public int priority() { 10 | return 4; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/CTO.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public class CTO extends Person { 4 | 5 | public CTO(String name) { 6 | super(name); 7 | } 8 | 9 | public int priority() { 10 | return 3; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/Person.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public abstract class Person implements Comparable { 4 | private final String name; 5 | 6 | protected Person(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String toString() { 11 | return name; 12 | } 13 | 14 | public abstract int priority(); 15 | 16 | public int compareTo(Person other) { 17 | int diff = priority() - other.priority(); 18 | if (diff != 0) 19 | return diff; 20 | else 21 | return name.compareTo(other.name); 22 | } 23 | 24 | public boolean equals(Object other) { 25 | return other instanceof Person && 26 | name.equals(((Person) other).name) && 27 | priority() == ((Person) other).priority(); 28 | } 29 | } -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/Programmer.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public class Programmer extends Person { 4 | 5 | public Programmer(String name) { 6 | super(name); 7 | } 8 | 9 | public int priority() { 10 | return 2; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/Secretary.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public class Secretary extends Person { 4 | 5 | public Secretary(String name) { 6 | super(name); 7 | } 8 | 9 | public int priority() { 10 | return 1; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2023-02-09/soluzione/it/univr/doodle/WeightedDoodle.java: -------------------------------------------------------------------------------- 1 | package it.univr.doodle; 2 | 3 | public class WeightedDoodle extends Doodle { 4 | 5 | protected int priority(Person person) { 6 | return person.priority(); 7 | } 8 | } -------------------------------------------------------------------------------- /2023-02-24/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2023-02-24/consegna/compito.pdf -------------------------------------------------------------------------------- /2023-02-24/consegna/it/univr/quindici/FattoriaDiTessere.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | import java.util.Random; 4 | import java.util.function.Supplier; 5 | 6 | // Una fattoria di tessere e' un oggetto capace di generare una nuova 7 | // tessera ogni volta che si chiama il suo metodo get() (definito in Supplier). 8 | // Al suo interno mettiamo un oggetto Random che può essere usato nelle sottoclassi 9 | // per fare scelte casuali 10 | 11 | // non modificate 12 | public abstract class FattoriaDiTessere> implements Supplier> { 13 | protected final static Random random = new Random(); 14 | } -------------------------------------------------------------------------------- /2023-02-24/consegna/it/univr/quindici/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // gioco 4x4 con tessere alfabetiche di lunghezza da 1 a 5 inclusi 6 | System.out.println(new Gioco<>(new FattoriaDiTessereAlfabetiche(), 4, 4)); 7 | 8 | FattoriaDiTessere f = new FattoriaDiTessereNumeriche(8); 9 | Gioco gioco; 10 | do { 11 | // gioco 3x2 con tessere numeriche da 1 a 8 inclusi 12 | gioco = new Gioco<>(f, 3, 2); 13 | System.out.println(gioco); 14 | } 15 | while (!gioco.risolto()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2023-02-24/soluzione/it/univr/quindici/FattoriaDiTessere.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | import java.util.Random; 4 | import java.util.function.Supplier; 5 | 6 | // Una fattoria di tessere e' un oggetto capace di generare una nuova 7 | // tessera ogni volta che si chiama il suo metodo get() (definito in Supplier). 8 | // Al suo interno mettiamo un oggetto Random che può essere usato nelle sottoclassi 9 | // per fare scelte casuali 10 | public abstract class FattoriaDiTessere> implements Supplier> { 11 | protected final static Random random = new Random(); 12 | } -------------------------------------------------------------------------------- /2023-02-24/soluzione/it/univr/quindici/FattoriaDiTessereAlfabetiche.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public class FattoriaDiTessereAlfabetiche extends FattoriaDiTessere { 4 | 5 | public Tessera get() { 6 | // generiamo una stringa casuale lunga da 1 a 5 caratteri 7 | int len = 1 + random.nextInt(5); 8 | String s = ""; 9 | while (len-- > 0) 10 | s += (char) ('a' + random.nextInt(26)); 11 | 12 | return new Tessera<>(s); 13 | } 14 | } -------------------------------------------------------------------------------- /2023-02-24/soluzione/it/univr/quindici/FattoriaDiTessereNumeriche.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public class FattoriaDiTessereNumeriche extends FattoriaDiTessere { 4 | private final int max; 5 | 6 | public FattoriaDiTessereNumeriche(int max) { 7 | this.max = max; 8 | } 9 | 10 | // generiamo una tessera numerica contenente un numero casuale tra 1 e max inclusi 11 | public Tessera get() { 12 | return new Tessera<>(1 + random.nextInt(max)); 13 | } 14 | } -------------------------------------------------------------------------------- /2023-02-24/soluzione/it/univr/quindici/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.quindici; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // gioco 4x4 con tessere alfabetiche di lunghezza da 1 a 5 inclusi 6 | System.out.println(new Gioco<>(new FattoriaDiTessereAlfabetiche(), 4, 4)); 7 | 8 | FattoriaDiTessere f = new FattoriaDiTessereNumeriche(8); 9 | Gioco gioco; 10 | do { 11 | // gioco 3x2 con tessere numeriche da 1 a 8 inclusi 12 | gioco = new Gioco<>(f, 3, 2); 13 | System.out.println(gioco); 14 | } 15 | while (!gioco.risolto()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2023-07-05/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2023-07-05/consegna/compito.pdf -------------------------------------------------------------------------------- /2023-09-29/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2023-09-29/consegna/compito.pdf -------------------------------------------------------------------------------- /2023-09-29/consegna/it/univr/instructions/Instruction.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public interface Instruction { 6 | 7 | /** 8 | * Esegue questa istruzione con lo stack indicato. 9 | * Tipicamente, l'esecuzione modifichera' lo stack. 10 | * 11 | * @param stack lo stack su cui si esegue l'istruzione 12 | * @throws IllegalProgramException se l'esecuzione dell'istruzione fallisce 13 | */ 14 | void execute(List stack) throws IllegalProgramException; 15 | 16 | /** 17 | * Restituisce una descrizione stringa dell'istruzione. 18 | */ 19 | String toString(); 20 | } -------------------------------------------------------------------------------- /2023-09-29/consegna/it/univr/instructions/Machine.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | public interface Machine { 4 | int getResult(); 5 | } -------------------------------------------------------------------------------- /2023-09-29/consegna/it/univr/instructions/POP.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class POP implements Instruction { 6 | 7 | public POP() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size == 0) 14 | // lo stack non deve essere vuoto, altrimenti non c'e' una cima da rimuovere 15 | throw new IllegalProgramException("Pop da uno stack vuoto"); 16 | 17 | stack.remove(size - 1); // elimina l'elemento in cima allo stack 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "pop"; 23 | } 24 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/ADD.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class ADD implements Instruction { 6 | 7 | public ADD() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size < 2) 14 | throw new IllegalProgramException("Operandi insufficienti per un'operazione binaria"); 15 | 16 | int top = stack.remove(size - 1); 17 | int underTop = stack.remove(size - 2); 18 | stack.add(top + underTop); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "add"; 24 | } 25 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/DIV.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class DIV implements Instruction { 6 | 7 | public DIV() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size < 2) 14 | throw new IllegalProgramException("Operandi insufficienti per un'operazione binaria"); 15 | 16 | int top = stack.remove(size - 1); 17 | int underTop = stack.remove(size - 2); 18 | if (top == 0) 19 | throw new IllegalProgramException("Divisione per zero"); 20 | 21 | stack.add(underTop / top); 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "div"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/IllegalProgramException.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | public class IllegalProgramException extends Exception { 4 | public IllegalProgramException(String message) { 5 | super(message); 6 | } 7 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/Instruction.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public interface Instruction { 6 | 7 | /** 8 | * Esegue questa istruzione con lo stack indicato. 9 | * Tipicamente, l'esecuzione modifichera' lo stack. 10 | * 11 | * @param stack lo stack su cui si esegue l'istruzione 12 | * @throws IllegalProgramException se l'esecuzione dell'istruzione fallisce 13 | */ 14 | void execute(List stack) throws IllegalProgramException; 15 | 16 | /** 17 | * Restituisce una descrizione stringa dell'istruzione. 18 | */ 19 | String toString(); 20 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/MUL.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class MUL implements Instruction { 6 | 7 | public MUL() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size < 2) 14 | throw new IllegalProgramException("Operandi insufficienti per un'operazione binaria"); 15 | 16 | int top = stack.remove(size - 1); 17 | int underTop = stack.remove(size - 2); 18 | stack.add(top * underTop); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "mul"; 24 | } 25 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/Machine.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | public interface Machine { 4 | int getResult(); 5 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/POP.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class POP implements Instruction { 6 | 7 | public POP() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size == 0) 14 | throw new IllegalProgramException("Pop da uno stack vuoto"); 15 | 16 | stack.remove(size - 1); 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "pop"; 22 | } 23 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/PUSH.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class PUSH implements Instruction { 6 | private final int constant; 7 | 8 | public PUSH(int constant) { 9 | this.constant = constant; 10 | } 11 | 12 | @Override 13 | public void execute(List stack) throws IllegalProgramException { 14 | stack.add(constant); 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "push(" + constant + ")"; 20 | } 21 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/PrintingMachine.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class PrintingMachine extends SimpleMachine { 6 | 7 | public PrintingMachine(List program) throws IllegalProgramException { 8 | super(program); 9 | } 10 | 11 | @Override 12 | protected void execute(Instruction ins, List stack) throws IllegalProgramException { 13 | System.out.print(ins + ": "); 14 | super.execute(ins, stack); 15 | System.out.println(stack); 16 | } 17 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/REPEAT.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class REPEAT implements Instruction { 6 | private final int howManyTimes; 7 | private final Instruction ins; 8 | 9 | public REPEAT(int howManyTimes, Instruction ins) { 10 | if (howManyTimes < 0) 11 | throw new IllegalArgumentException(); 12 | 13 | this.howManyTimes = howManyTimes; 14 | this.ins = ins; 15 | } 16 | 17 | @Override 18 | public void execute(List stack) throws IllegalProgramException { 19 | for (int count = 0; count < howManyTimes; count++) 20 | ins.execute(stack); 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "repeat(" + howManyTimes + ", " + ins + ")"; 26 | } 27 | } -------------------------------------------------------------------------------- /2023-09-29/soluzione/it/univr/instructions/SUB.java: -------------------------------------------------------------------------------- 1 | package it.univr.instructions; 2 | 3 | import java.util.List; 4 | 5 | public class SUB implements Instruction { 6 | 7 | public SUB() { 8 | } 9 | 10 | @Override 11 | public void execute(List stack) throws IllegalProgramException { 12 | int size = stack.size(); 13 | if (size < 2) 14 | throw new IllegalProgramException("Operandi insufficienti per un'operazione binaria"); 15 | 16 | int top = stack.remove(size - 1); 17 | int underTop = stack.remove(size - 2); 18 | stack.add(top - underTop); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "sub"; 24 | } 25 | } -------------------------------------------------------------------------------- /2024-02-01/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-02-01/consegna/compito.pdf -------------------------------------------------------------------------------- /2024-02-01/consegna/it/univr/sudoku/Emoji.java: -------------------------------------------------------------------------------- 1 | package it.univr.sudoku; 2 | 3 | // enumerazione di 9 emoji: non modificate 4 | public enum Emoji { 5 | GRINNING("😀"), 6 | MONEY("🤑"), 7 | THINKING("🤔"), 8 | LAUGHING("🤣"), 9 | TONGUE("😛"), 10 | HEARTS("😍"), 11 | MELTING("🫠"), 12 | HALO("😇"), 13 | UPSIDE_DOWN("🙃"); 14 | 15 | private final String s; 16 | 17 | private Emoji(String s) { 18 | this.s = s; 19 | } 20 | 21 | public String toString() { 22 | return s; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2024-02-01/consegna/it/univr/sudoku/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.sudoku; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("Un sudoku di interi (1-9) con 61 caselle nascoste"); 9 | System.out.println(????); // completare 10 | System.out.println("Un sudoku di interi (1-9) con 0 caselle nascoste"); 11 | System.out.println(????); // completare 12 | System.out.println("Un sudoku di caratteri (A-I) con 30 caselle nascoste"); 13 | System.out.println(????); // completare 14 | System.out.println("Un sudoku di emoji " + Arrays.toString(Emoji.values()) + " con 20 caselle nascoste"); 15 | System.out.println(????); // completare 16 | System.out.println("Un sudoku di interi (1-9) con 62 caselle nascoste"); 17 | System.out.println(????); // completare, va in eccezione 18 | } 19 | } -------------------------------------------------------------------------------- /2024-02-01/consegna/print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-02-01/consegna/print.png -------------------------------------------------------------------------------- /2024-02-01/consegna/sudoku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-02-01/consegna/sudoku.png -------------------------------------------------------------------------------- /2024-02-01/soluzione/it/univr/sudoku/Emoji.java: -------------------------------------------------------------------------------- 1 | package it.univr.sudoku; 2 | 3 | // enumerazione di 9 emoji: non modificate 4 | public enum Emoji { 5 | GRINNING("😀"), 6 | MONEY("🤑"), 7 | THINKING("🤔"), 8 | LAUGHING("🤣"), 9 | TONGUE("😛"), 10 | HEARTS("😍"), 11 | MELTING("🫠"), 12 | HALO("😇"), 13 | UPSIDE_DOWN("🙃"); 14 | 15 | private final String s; 16 | 17 | private Emoji(String s) { 18 | this.s = s; 19 | } 20 | 21 | public String toString() { 22 | return s; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2024-02-01/soluzione/it/univr/sudoku/Main.java: -------------------------------------------------------------------------------- 1 | package it.univr.sudoku; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | System.out.println("Un sudoku di interi (1-9) con 61 caselle nascoste"); 9 | System.out.println(new Sudoku(61, Integer::valueOf)); 10 | System.out.println("Un sudoku di interi (1-9) con 0 caselle nascoste"); 11 | System.out.println(new Sudoku(0, Integer::valueOf)); 12 | System.out.println("Un sudoku di caratteri (A-I) con 30 caselle nascoste"); 13 | System.out.println(new Sudoku(30, n -> (char) ('A' + n - 1))); 14 | System.out.println("Un sudoku di emoji " + Arrays.toString(Emoji.values()) + " con 20 caselle nascoste"); 15 | System.out.println(new Sudoku(20, n -> Emoji.values()[n - 1])); 16 | System.out.println("Un sudoku di interi (1-9) con 62 caselle nascoste"); 17 | System.out.println(new Sudoku(62, Integer::valueOf)); // va in eccezione 18 | } 19 | } -------------------------------------------------------------------------------- /2024-02-16/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-02-16/consegna/compito.pdf -------------------------------------------------------------------------------- /2024-02-16/consegna/tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-02-16/consegna/tree.pdf -------------------------------------------------------------------------------- /2024-06-20/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-06-20/consegna/compito.pdf -------------------------------------------------------------------------------- /2024-06-20/consegna/it/univr/file/AbstractComponent.java: -------------------------------------------------------------------------------- 1 | package it.univr.file; 2 | 3 | public abstract class AbstractComponent implements Component { 4 | private final String name; 5 | 6 | /** 7 | * Costruisce una componente con il nome indicato. 8 | */ 9 | protected AbstractComponent(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public final String getName() { 15 | return name; 16 | } 17 | 18 | @Override 19 | public final String toString() { 20 | // completate 21 | } 22 | 23 | // sotto potete aggiungere solo cose private, se servissero; 24 | // quindi non aggiungete metodi public sotto 25 | } -------------------------------------------------------------------------------- /2024-06-20/consegna/it/univr/file/DirectoryComponent.java: -------------------------------------------------------------------------------- 1 | package it.univr.file; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class DirectoryComponent extends AbstractComponent { 9 | // aggiungete campi, se servissero 10 | 11 | /** 12 | * Costruisce una componente di tipo directory con il nome indicato 13 | * e le sottocomponenti (figli) indicate. 14 | */ 15 | public DirectoryComponent(String name, Component... children) { 16 | // completate 17 | } 18 | 19 | // implementate sotto i metodi public ancora astratti 20 | } -------------------------------------------------------------------------------- /2024-06-20/consegna/it/univr/file/FileComponent.java: -------------------------------------------------------------------------------- 1 | package it.univr.file; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class FileComponent extends AbstractComponent { 8 | // aggiungete campi, se servissero 9 | 10 | /** 11 | * Costruisce una componente di tipo file con il nome indicato 12 | * e la dimensione in byte indicata. 13 | */ 14 | public FileComponent(String name, int size) { 15 | // completate 16 | } 17 | 18 | // implementate sotto i metodi public ancora astratti 19 | } -------------------------------------------------------------------------------- /2024-06-20/soluzione/it/univr/file/AbstractComponent.java: -------------------------------------------------------------------------------- 1 | package it.univr.file; 2 | 3 | public abstract class AbstractComponent implements Component { 4 | private final String name; 5 | 6 | /** 7 | * Costruisce una componente con il nome indicato. 8 | */ 9 | protected AbstractComponent(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public final String getName() { 15 | return name; 16 | } 17 | 18 | @Override 19 | public final String toString() { 20 | return toString(""); 21 | } 22 | } -------------------------------------------------------------------------------- /2024-06-20/soluzione/it/univr/file/FileComponent.java: -------------------------------------------------------------------------------- 1 | package it.univr.file; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class FileComponent extends AbstractComponent { 8 | private final int size; 9 | 10 | /** 11 | * Costruisce una componente di tipo file con il nome indicato 12 | * e la dimensione in byte indicata. 13 | */ 14 | public FileComponent(String name, int size) { 15 | super(name); 16 | 17 | this.size = size; 18 | } 19 | 20 | @Override 21 | public String toString(String nesting) { 22 | return nesting + getName(); 23 | } 24 | 25 | @Override 26 | public int size() { 27 | return size; 28 | } 29 | 30 | @Override 31 | public List getFiles() { 32 | List result = new ArrayList<>(); 33 | result.add(this); 34 | return result; 35 | } 36 | 37 | @Override 38 | public String find(String name) throws FileNotFoundException { 39 | if (name.equals(getName())) 40 | return name; 41 | else 42 | throw new FileNotFoundException(name); 43 | } 44 | } -------------------------------------------------------------------------------- /2024-09-13/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2024-09-13/consegna/compito.pdf -------------------------------------------------------------------------------- /2024-09-13/consegna/it/univr/corso/Corso.java: -------------------------------------------------------------------------------- 1 | package it.univr.corso; 2 | 3 | /** 4 | * Un corso di laurea (per esempio, informatica), con nome e durata in anni. 5 | */ 6 | public class Corso { 7 | // aggiungete campi se servissero 8 | 9 | public Corso(String nome, int durata) { 10 | // completare 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | // completare, restituisce il nome del corso 16 | } 17 | 18 | // aggiungete i metodi accessori pubblici getNome() e getDurata() 19 | } -------------------------------------------------------------------------------- /2024-09-13/consegna/it/univr/corso/StudenteLavoratore.java: -------------------------------------------------------------------------------- 1 | package it.univr.corso; 2 | 3 | import java.time.Year; 4 | 5 | /** 6 | * Uno studente lavoratore è identico a uno studente ma finisce fuori corso 7 | * nel doppio di anni rispetto a uno studente non lavoratore. 8 | */ 9 | public class StudenteLavoratore extends Studente { 10 | // aggiungete campi se servissero 11 | 12 | public StudenteLavoratore(String nome, String cognome, int matricola, int annoDiImmatricolazione) throws StudenteIllegaleException { 13 | // completare 14 | } 15 | 16 | // forse dovete ridefinire qualcosa? 17 | } 18 | -------------------------------------------------------------------------------- /2024-09-13/soluzione/it/univr/corso/Corso.java: -------------------------------------------------------------------------------- 1 | package it.univr.corso; 2 | 3 | /** 4 | * Un corso di laurea (per esempio, informatica), con nome e durata in anni. 5 | */ 6 | public class Corso { 7 | private final String nome; 8 | private final int durata; 9 | 10 | public Corso(String nome, int durata) { 11 | this.nome = nome; 12 | this.durata = durata; 13 | } 14 | 15 | @Override 16 | public String toString() { // restituisce il nome del corso 17 | return nome; 18 | } 19 | 20 | public String getNome() { 21 | return nome; 22 | } 23 | 24 | public int getDurata() { 25 | return durata; 26 | } 27 | } -------------------------------------------------------------------------------- /2024-09-13/soluzione/it/univr/corso/StudenteIllegaleException.java: -------------------------------------------------------------------------------- 1 | package it.univr.corso; 2 | 3 | public class StudenteIllegaleException extends Exception { 4 | 5 | public StudenteIllegaleException(String message) { 6 | super(message); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2024-09-13/soluzione/it/univr/corso/StudenteLavoratore.java: -------------------------------------------------------------------------------- 1 | package it.univr.corso; 2 | 3 | import java.time.Year; 4 | 5 | /** 6 | * Uno studente lavoratore e' identico a uno studente ma finisce fuori corso 7 | * nel doppio di anni rispetto a uno studente non lavoratore. 8 | */ 9 | public class StudenteLavoratore extends Studente { 10 | 11 | public StudenteLavoratore(String nome, String cognome, int matricola, int annoDiImmatricolazione) throws StudenteIllegaleException { 12 | super(nome, cognome, matricola, annoDiImmatricolazione); 13 | } 14 | 15 | @Override 16 | public boolean fuoriCorso(Corso corso) { 17 | int annoCorrente = Year.now().getValue(); 18 | return getAnnoDiImmatricolazione() < annoCorrente - corso.getDurata() * 2; 19 | } 20 | } -------------------------------------------------------------------------------- /2025-02-05/consegna/compito.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spoto/ProgrammazioneJava/83d0c4612a3f613399cb11253171180f17b1699b/2025-02-05/consegna/compito.pdf -------------------------------------------------------------------------------- /2025-02-05/consegna/it/univr/time/AmericanTime.java: -------------------------------------------------------------------------------- 1 | package it.univr.time; 2 | 3 | public class AmericanTime extends AbstractTime { 4 | 5 | public AmericanTime(int secondsFromStartOfDay) { 6 | super(secondsFromStartOfDay); 7 | } 8 | 9 | public final Time next() { 10 | // completate 11 | } 12 | 13 | // restituisce una stringa che rappresenta un Time all'americana (am/pm) 14 | public String toString() { 15 | // completate 16 | } 17 | } -------------------------------------------------------------------------------- /2025-02-05/consegna/it/univr/time/Interval.java: -------------------------------------------------------------------------------- 1 | package it.univr.time; 2 | 3 | import java.util.Iterator; 4 | 5 | // un intervallo di tempo, da un istante iniziale 6 | // in avanti, per un certo numero di secondi 7 | public class Interval implements Iterable