Java Programming

profileSagat
HelpfulTipsforProgrammingProjectTwo.pdf

Copyright © 2022, Dallas College, All Rights Reserved Page 1 of 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 web site 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, store values in some of the elements of the array and use these values to display a report. The report will show the contents of each of the elements in the array as well as row totals and an overall total.

In Section 7.9 of our textbook, we learn that 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.

Following that example program in our textbook are text discussions and example code for determining the row and column totals for a two- dimensional array.

Another useful example program can be found in Code Listing 7-20 (Pass2Darray.java) where the program demonstrates passing a two- dimensional array to a method. That example program also demonstrates how to determine the sum of all the elements in a two-dimensional array.

Copyright © 2022, Dallas College, All Rights Reserved Page 2 of 2

Section 4.3 of our textbook is entitled “Using the while Loop for Input Validation”. Validate user input when they enter their menu choice as well as when they identify a seat to be reserved.

Characters are stored using Unicode in Java. If you add one (1) to the character representation of upper-case ‘A’, you get upper-case ‘B’. Add one more to get upper-case ‘C’, and so on.

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” • %n a newline character (‘\n’)

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

The printf method does not automatically supply a new line character (\n). This will allow you to “build up” output one item at a time before proceeding to the next line to be displayed.

A suggested way to obtain and print the date and time is:

// Obtain the current date/time Date now = new Date();

outputFile.println("Prepared: " + now.toString());

  • Helpful Tips for Programming Project Two