You are on page 1of 4

import java.io.

BufferedInputStream
import java.util.*
import java.io.File
import java.io.*
import java.io.Reader

class Note(private var autor:String,private var data:Date,private var ora:String,


private var continut:String)
{

public fun getAutor():String


{
return autor
}

public fun setAutor(name:String)


{
autor=name;
}

public fun getData():Date


{
return data
}

public fun setData(d:Date)


{
data=d
}

public fun getOra():String


{
return ora
}
public fun setOra(o:String)
{
ora=o;
}

public fun getContinut():String


{
return continut
}
public fun setContinut(c:String)
{
continut=c;
}

class NoteManager(private var availableNotes:MutableSet<Note>,private var


deletedNotes:MutableSet<Note> )
{
public fun new(n:Note)
{
availableNotes.add(n)
}
public fun delete(n:Note)
{
if(availableNotes.contains(n))
{
availableNotes.remove(n)
deletedNotes.add(n)
}
else
{
println("Notita nu exista")
}
}

public fun add(sirNou:String)


{
availableNotes.elementAt(1).setContinut(sirNou)
}

public fun getAvailableNotes():MutableSet<Note>


{
return availableNotes
}

public fun getDeletedNotes():MutableSet<Note>


{
return deletedNotes
}
}

class User(private val notes:NoteManager )


{

public fun new(n:Note)


{
notes.new(n)
}

public fun delete(n:Note)


{
notes.delete(n)
}

public fun add(sir:String)


{
notes.add(sir)
}

public fun getNoteManager():NoteManager


{
return notes
}

interface Display
{
public fun print(n:Note,fName:String)
}
object printHTML:Display
{
override fun print(n: Note, fName:String) {
val content = File(fName).writer()

content.write("<html>\n")
content.write("<head>\n")
content.write("<head><title>Notita</title></head>\n")
content.write("</head>\n")
content.write("<body>\n")
content.write("<h1>\n"+n.getAutor()+"</h1>\n")
content.write("<h2>\n"+n.getData()+"</h2>\n")
content.write("<h3>\n"+n.getOra()+"</h3>\n")
content.write("<h4>\n"+n.getContinut()+"</h4>\n")
content.write("</body>\n")
content.write("</html>\n")

content.close()
}
}

object printJSON:Display
{

override public fun print(n:Note,fName:String)


{
val content = File(fName).writer()
content.write("[\n")

content.write(" {\"Autor\": \"${n.getAutor()}\", \"Data\":\"$


{n.getData()}\", \"Ora\":\"${n.getOra()}\", \"Continut\":\"${n.getContinut()}\"\n")

content.write("]\n")
content.close()
}

fun main(args : Array<String>)


{
val N1=Note("Popa",Date(2021,3,20),"12:40","My name is Popa")
val N2=Note("Mircea",Date(2021,2,25),"2:00","My name is Mircea")
val N3=Note("Radu",Date(2021,3,18),"15:33","My name is Radu")
val N4=Note("Vlad",Date(2021,3,20),"12:40","My name is Vlad")
val N5=Note("Eliza",Date(2021,2,25),"2:00","My name is Eliza")
val N6=Note("Bogdan",Date(2021,3,18),"15:33","My name is Bogdan")

val Notes= mutableSetOf(N1,N2,N3)


val del=mutableSetOf(N4)
var u=User(NoteManager(Notes,del))

println("Selectati optiunea dorita: ")


println("1-Afisare lista notite\n 2-Incarcare notita\n 3-Creare notita noua\n
4-Stergere notita" )

var x= readLine()
var nr=Integer.parseInt(x)

while(true){
when(nr)
{
1->{var i=0
for (n in u.getNoteManager().getAvailableNotes())
{
i++
printHTML.print(n,"Notita"+i+".html")

}}
2->u.add("Notita a fost modificata")
3->u.new(N5)
4->u.delete(N2)
else-> print("none")

}
}

You might also like