0
  • First Name
  • Last Name
  • Street Address
  • City
  • State - 2 digits in length
  • Zip - Integer 4 digits in length (minimum and maximum)
  • GPA (from 0.0 to 4.0)
  • Major - String
  • Teacher Class - overrides the student class

The main class should

  • Instantiate the student class and prompt the user to enter each of these properties
  • Print out the data from the instantiated class.
  • Instantiate the teacher class.
  • Print out the data from the instantiated class.

I'm new to Kotlin but this is what I have so far. How do I prompt the user for each data point, get their input for each, and then print the user input out as a whole once all info is entered

Ideal output

  • First Name: ...
  • Last Name: ...

Then once all info is entered it prints the entirety of the info entered by user with prompts.

open class Student(first: String, last: String, street: String, city: String, state: String, zip: Int, gpa: Int, major: String)
{

    var firstName : String?= first
    var lastName : String?= last
    var streetAddress: Int?= street
    var city: String?= city
    var state : String?=state
    var zip:Int?=zip
    var gpa: Int?=gpa
    var major: String?=major
}

class Teacher (first: String):Student (first)

fun main() {
   

aSemy
  • 5,485
  • 2
  • 25
  • 51
  • 1
    Does this answer your question? [Reading console input in Kotlin](https://stackoverflow.com/questions/41283393/reading-console-input-in-kotlin) – aSemy Jan 29 '23 at 23:08
  • Couple side notes: (1) You can make the code more compact if you declare the properties in the primary constructor, and possibly with the use of default arguments (see https://kotlinlang.org/docs/classes.html#constructors). (2) It doesn't make much sense for a `Teacher` to inherit from `Student`. That implies that all teachers are themselves students. Using a common superclass between `Teacher` and `Student` may be warranted, but the former should not extend the latter. – Slaw Jan 29 '23 at 23:40

0 Answers0