A Table of Student Grades
Write a Java class, GradesTabs, that
prints a table with a list
of at least 5 students together with their grades earned (lab
points, bonus points, and the total) in the
format below.
///////////////////\\\\\\\\\\\\\\\\\\\
== Student Points (tabs) ==
\\\\\\\\\\\\\\\\\\\///////////////////
Name Lab Bonus Total
---- --- ----- -----
Joe 43 7 50
William 50 8 58
Mary Sue 39 10 49
The requirements for the program are as
follows:
- Print the border on the top as illustrated (using the slash and
backslash characters (recall that you have to do something tricky to print backslashes).
- Use tab
characters to get your columns aligned.
- Make up your own student names and points -- the ones
shown are just for illustration purposes. You need 5 names.
- Copy the output of your program into the lab document, labelling it "With Tabs". Make sure you use a fixed-width font such as Courier for your output in the Word document. (That will make all the characters have the same width (consider "i" vs. "m", for example), so that your output will line up nice and neat.)
Submit your GradesTabs.java.
- Now create a second class, GradesPrintf, to do the same thing, but use System.out.printf instead of tab characters to generate the table. You'll want to use the "%s" and "%d" control tokens. See the section on printf in your text, including Display 2.1. Using printf, the numeric output should be right justified, yielding this output:
///////////////////\\\\\\\\\\\\\\\\\\\
== Student Points (printf) ==
\\\\\\\\\\\\\\\\\\\///////////////////
Name Lab Bonus Total
---- --- ----- -----
Joe 43 7 50
William 50 8 58
Mary Sue 39 10 49
- Copy the output of your GradesPrintf into the lab document, labelling it "With Printf". Make sure you use the Courier font for your output. Submit your GradesPrintf.java
Here is a portion of code you might want to use:
String name = "Joe";
int labScore = 43;
int bonus = 7;
// [here insert your code to print one line of the table]
name = "William";
labScore = 50;
bonus = 10;
// [insert same line of code as above to print the next line]
Feel free to modify the above code, add more variables, etc.