(forgot to add this in) 1. Quizzes(2) 15%each 2.Homework 10% 3.Lab experiaments(
ID: 3750849 • Letter: #
Question
(forgot to add this in)
1. Quizzes(2) 15%each
2.Homework 10%
3.Lab experiaments(paper optional)(group project) 10%
4. Midterm Examination 25%
5. Final Examination 25%
This program must be done in Kotlin
Write a class that contains 3 fields, the item type, the item weight, and the item grade. Make the grades up, but they must be different, not all 100s
create an array or list of the items and add the values, ideally through a constructor.
After you load all the data, use the weight fields and the grades to calculate the correct final grade.
Explanation / Answer
package leetcode
import java.util.ArrayList
import java.util.HashSet
import java.util.Scanner
internal class Item(type:String, weight:Int, grade:Int) {
var type:String
var weight:Int = 0
var grade:Int = 0
init{
this.type = type
this.weight = weight
this.grade = grade
}
}
fun main(args:Array<String>) {
val scan = Scanner(System.`in`)
println("enter number of items you wants to add")
val noOfItem = scan.nextInt()
val itemList = ArrayList<Item>()
for (i in 0 until noOfItem)
{
println("enter item type")
val type = scan.next()
println("enter item weight")
val weight = scan.nextInt()
println("enter item grade")
val grade = scan.nextInt()
val item = Item(type, weight, grade)
itemList.add(item)
}
for (i in itemList)
{
val finalGrade = (i.grade * i.weight).toDouble()
println("final grade of item " + i.type + " is " + finalGrade)
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.