class Student { private String name; private int id; private int credits; private double gpa; public Student(String name, int id, int credits, double gpa) { this.name = name; this.id = id; this.credits = credits; this.gpa = gpa; } public void print() { // the % sign means we are going to substitute in a value // the leading number indicates how many columns it should take in output // if it's negative it is left justified (default is right) // if we want to indicate a number of decimal points, we do so with the . // then comes the type specifier // s is String, d is int, and f is double String formatted = String.format("%-20s %6d %4d %6.2f", name, id, credits, gpa); System.out.println(formatted); } } public class Formatting { public static void main(String args[]) { Student s1 = new Student("Alice Anderson", 41, 101, 3.8234875203497); Student s2 = new Student("Bob Benson", 861, 86, 2.92311930); Student s3 = new Student("Clare Carter", 2188, 17, 2.497927273); s1.print(); s2.print(); s3.print(); } }