format output such as DecimalFormat in the
java.text.DecimalFormat
package
packages (how to use them) and import directive
typecast (implicit and explicit)
wrapper classes and autoboxing
String class
array
void and value-returning method
default constructor (constructor without parameters)
parameterized constructors
varags
static members of a class
how to instantiate objects, i.e., how to use the operator new
how to use reference variables
how objects are destroyed in Java (garbage collector)
Problem Statement
In this lab we are to develop a Student Registration and Grades application
which is to provide the following functionality:
Store information about students such as
last name
first name
whether or not a student is a Canadian
a student's grades for all the courses taken.
Calculate and display the overall average (average of all grades obtained
by one student).
Compute and display the application fee for each student.
Requirements
We need to take the following into account when we develop our application:
User must be able to enter first and last names of a student, her/his nationality
and the grade for each of the courses a student has taken. In this lab,
we shall not record the courses taken, simply the awarded grades.
Grades are given in integral percentage (e.g. 78%), therefore they can
only be integers from 0 to 100.
The application fee is calculated as follows:
For Canadian students with overall average >= 85%, the application fee
is Fee1.
For International students with overall average >= 85%, the application
fee is Fee2.
For any students with overall average < 85%, the application fee is
Fee3.
The application fees are as follows:
Fee1 is $30,
Fee2 is $45, and
Fee3 is $70
Use arrays whenever we need to store many elements of the same data type.
We must store the size of the grades array as a constant since all students
will have the same number of grades and we shall not expand the array of
grades.
Suggestions
Design and Implementation
When creating our classes, apply encapsulation as we would when we create
C++ classes. This is to say, our application (client code) must not be
able to access the data fields of our classes directly. We will need to
create appropriate methods in order to allow the client code to access
these data fields and modify their content.
Remember: there are no pointers and pointer arithmetic in Java.
Make sure we have included all necessary packages at the top of our files.
Remember: we cannot define variables outside the scope of a class. All
data must reside inside our class.
We don't have to separate the interface of a class (*.h file) from its
implementation (*.cc) as we would do in C++.
There are no unsigned data types in Java.
The type char uses the Unicode characters, not the ASCII code as
in C++.
Size of the array don't have to be a compile-time constant, as in C++.
Since Java has an automatic garbage collection, there are no destructors
in Java.
We can compile several files in a variety of ways.
Here are a few:
javac *.java javac <name of file containing the main
method with its ".java" extension> javac <name of all java files with their
".java" extension>
If the java file containing our main method is called LAB1.java,
we compile it using the following command
javac LAB1.java
After performing this command our executable
file is named LAB1.class
To run our application, we use the following command:
java LAB1
Resources
The first thing we will need to do is investigate and read about the topics
listed above in the Objectives section . Below are partial lists
of books and web sites you may wish to look at in order to perform your
investigation.
List of books:
Java from the Beginning
(2nd Edition) (International Computer Science Series)
- by Jan Skansholm
Beginning Java Objects:
From Concepts to Code - by Jacquie Barker
Tutorial for JBuilder
- by Y. Daniel Liang
Beginning J2EE 1.4
- by James L. Weaver, Kevin Mukhar, James P. Crume, Ron Phillips
As stated, the above lists are not exhaustive, therefore feel free to add
to them the Java books and web sites you find useful. Also, feel free to
send these (books and URL's) to the instructor so that they can be added
to this lab and to our course web site.
Anne Lavergne, Irina Pekerskaya and Zhi
Hao Lin - May 2004 to January 2005 - Last Revision date September 2006