THINK FIRST·CODE LATER

← All labs

Student ID card: reading different types

Problem

Write StudentCard. Read, in this order: a name (one word), an ID (int), the credits earned (int), the GPA (double), the section letter (char) and whether the student is international (boolean). Print:

Name:          Lina
ID:            1180234
Section:       B
Credits:       45
GPA:           3.70
International: false
Credits left:  75

(120 credits are needed to graduate; GPA with 2 decimals.) Hint: Scanner has no nextChar() — read a word and take its first character.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l3-3-data-1.txt

Lina 1180234 45 3.7 B false
What your program must print for l3-3-data-1.txt
Name:          Lina
ID:            1180234
Section:       B
Credits:       45
GPA:           3.70
International: false
Credits left:  75

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l3-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content l3-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.