Lecture Question In a package named “lecture12“, create and complete the "Store" class which is stated below. • asJSON returns a JSON string representing an object with keys "cashInRegister" and "inventory" mapping to the values from the two state variables with the same names. • fromJSON takes a JSON string in the same format returned from asJSON and sets the state variables to the values from the JSON string. package lecture12 class Store(var cashInRegister: Double, var inventory: List[String]) { def asJSON(): String = { "" } def fromJSON(jsonString: String): Unit = { } } Lecture Question Class TestJSON extends FunSuite { val EPSILON: Double = 0.000001 def equalDoubles(d1: Double, d2: Double): Boolean = { (d1 - d2).abs < EPSILON } test("test the store JSON") { val store: Store = new Store(550.21, List("eggs", "milk", "waffles")) val storeJSON: String = store.asJSON() val store2: Store = new Store(0.0, List()) store2.fromJSON(storeJSON) assert(equalDoubles(store2.cashInRegister, 550.21)) val actualList: List[String] = store2.inventory.sorted val expectedList: List[String] = List("eggs", "milk", "waffles").sorted assert(actualList == expectedList) } } in this there is already test cases given. i want code in scala for as JSON nad from JSON
Lecture Question
In a package named “lecture12“, create and complete the "Store" class which is stated
below.
• asJSON returns a JSON string representing an object with keys "cashInRegister" and
"inventory" mapping to the values from the two state variables with the same names.
• fromJSON takes a JSON string in the same format returned from asJSON and sets the
state variables to the values from the JSON string.
package lecture12
class Store(var cashInRegister: Double, var inventory: List[String]) {
def asJSON(): String = {
""
}
def fromJSON(jsonString: String): Unit = {
}
}
Lecture Question
Class TestJSON extends FunSuite {
val EPSILON: Double = 0.000001
def equalDoubles(d1: Double, d2: Double): Boolean = {
(d1 - d2).abs < EPSILON
}
test("test the store JSON") {
val store: Store = new Store(550.21, List("eggs", "milk", "waffles"))
val storeJSON: String = store.asJSON()
val store2: Store = new Store(0.0, List())
store2.fromJSON(storeJSON)
assert(equalDoubles(store2.cashInRegister, 550.21))
val actualList: List[String] = store2.inventory.sorted
val expectedList: List[String] = List("eggs", "milk", "waffles").sorted
assert(actualList == expectedList)
}
}
in this there is already test cases given. i want code in scala for as JSON nad from JSON
Trending now
This is a popular solution!
Step by step
Solved in 2 steps