You are on page 1of 2

Helpful Tips for Programming Project Two

Creating the solution to a programming problem is not an exercise in finding


an answer on the Internet and submitting it as your own work. Submitting
someone else’s work as your own is plagiarism. Plagiarism is an example of
Scholastic Dishonesty. Copying all or part of a solution from a site like Chegg
is plagiarism.
Worse, you have not learned anything about how to use a computer
program to solve a problem. You are always far better off submitting your
own original work. You will always be given credit for attempting to solve the
problem. On the other hand, if plagiarism is detected, you will receive a
grade of zero (0).
Start early. Read the book. Ask for help if you get stuck. Do your own work.
Do not share your work with any other students. Do not ask any other
students to share their work. There are no group projects in this course.
In Programming Project Two you are asked to create a two-dimensional
array, accumulate values in each of the elements of the array, and use the
resulting values to display a report. The report will show the contents of
each of the elements in the array as well as column totals and row totals.
A two-dimensional array is actually a one-dimensional array in which each
element is another one-dimensional array. The length attribute of a two-
dimensional array object is the number of rows in that two-dimensional
array. Your textbook contains all the details and good examples of how to
perform all the required activities required in this assignment.
Spend some time examining Code Listing 7-19 (Lengths.java) where the
program uses the length fields of a two-dimensional array to determine and
display the number of rows and the number of columns in each row.
Another useful example can be found in Code Listing 7-20
(Pass2Darray.java) where the program demonstrates passing a two-
dimensional array to a method.
A good way to control the formatting of your output is by using the printf
method. The syntax to invoke this method is as follows:
System.out.printf(format, item1, item2, . . ., itemN);

Where format is a string that consists of format specifiers. The items that
are to be displayed by the format specifiers must match the specifiers in
order, in number, and in exact data type. Common format specifiers are:
 %c a character, for example ‘a’
 %d a decimal integer, for example 200
 %f a floating-point number, for example 45.4600
 %s a string, for example “Java is cool”

Field width and precision can also be specified as well as adding comma
separators. These statements produce the following output:
System.out.println("-------+-------+-------+");
System.out.printf("%,8d%8s%8.1f\n", 1234, "Java", 34.56);

Output:
-------+-------+-------+
1,234 Java 34.6

By default, the output is right justified. You can place a minus sign (-) in the
specifier immediately after the per cent sign (%) to specify that the item will
be left justified within the specified field width. For example, these
statements:
System.out.println("-------+-------+-------+");
System.out.printf("%-,8d%-8s%-8.1f\n", 1234, "Java", 34.56);

produce the following output:


-------+-------+-------+
1,234 Java 34.6

The percent sign (%) denotes a specifier. To output a literal percent sign,
you must specify %% in the format string.
The printf method does not automatically supply a new line character (\n).
This can allow you to “build up” output one item at a time before proceeding
to the next line to be displayed.

You might also like