CSC1110 Exercise 11
Recall that we can use the
printf() function to add formatting to a String output using flags such as
%s as placeholders for values that we can add formatting instructions to. For example, to display pi to five decimal places, we would do the following
If we want to format a
String but not print it to the console, we can use the
String.format() method that uses the same syntax and structure as
printf(), but returns a formatted
String instead, so the above formatting could be done like this:
The Java documentation on formatting can be a bit tough to read, but can be found here
The Course Enumeration
Course enumeration is a collection of courses that an MSOE Software Engineering student would be taking. Each course has a code, a title, and a number of credits.
The Student class
Student class contains a first and last name of the user, a
Courses they will be taking, and a total number of credits, based on their courses. Use the UML diagram below to implement the
toString() method will be formatted to force each course code to take up 8 spaces, each title to take up 25 spaces and be right justified, and each credit to take 2 spaces. A sample output from the Driver class would look like this
Jones, Sean Course Title Credits ======== ========================= ======= CSC-1110 Software Development 4 COM-1001 College Writing 3 MTH-1110 Calculus I 4 PHY-1110 Physics I 4 ========================================== 15 Jones, Sean Course Title Credits ======== ========================= ======= CSC-1110 Software Development 4 COM-1001 College Writing 3 ========================================== 7
Using the information above, implement the
Student class, add a new
Student object to the
Driver class with your Spring class schedule, and print that
Student to the console.
Commit and push your code to your GitHUb repository.