forked from Klagarge/MSE-AdvProg-MicroProject
		
	fix: feedback ex2
This commit is contained in:
		| @@ -1,10 +1,10 @@ | ||||
| package TopSongs | ||||
| import scala.io.Source | ||||
| import java.io.File | ||||
| import com.github.tototoshi.csv._ | ||||
|  | ||||
| trait Person: | ||||
| trait Person { | ||||
|   val name: String | ||||
| } | ||||
|  | ||||
| case class Artist(name: String) extends Person | ||||
| case class Writer(name: String) extends Person | ||||
| @@ -45,10 +45,9 @@ class Song( | ||||
| ) | ||||
|  | ||||
|  | ||||
| object TopSongs { | ||||
|   var songs: List[Song] = List() | ||||
|   def addSong(song: Song): Unit = { | ||||
|     songs = song :: songs | ||||
| case class TopSongs(songs: List[Song] = List()) { | ||||
|   def addSong(song: Song): TopSongs = { | ||||
|     TopSongs(song :: songs) | ||||
|   } | ||||
|   def printSongs(): Unit = { | ||||
|     songs.foreach(song => println( | ||||
| @@ -62,7 +61,7 @@ object TopSongs { | ||||
|  | ||||
| @main def main(): Unit = | ||||
|   // create a new TopSongs object | ||||
|   val topSongs = TopSongs | ||||
|   var topSongs = TopSongs() | ||||
|  | ||||
|   val reader = CSVReader.open(new File("src/main/resources/songs.csv")) | ||||
|   val allRows = reader.allWithHeaders() | ||||
| @@ -79,7 +78,7 @@ object TopSongs { | ||||
|     ) | ||||
|  | ||||
|     // add the song to the TopSongs object | ||||
|     topSongs.addSong(s) | ||||
|     topSongs = topSongs.addSong(s) | ||||
|   } | ||||
|   reader.close() | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user