Programming Exercise II: My Grocery Shopping (I/O)
(Industry-Level, Second-to-None Comprehensive Specifications)
According to a study, students in computer-science courses learn much more by building large-scale exercises instead of many small-scale test programs, which give fragmented knowledge contrary to solid understanding of the language.
However, not to overwhelm students by the large size, the exercise is divided into several sub-exercises.
This is the first part of a bus-itinerary exercise.
Together, they give students an understanding of a large-size exercise development experience.
Though these exercises are related, you are NOT allowed to submit one exercise to cover two or more exercises.
Development Requirements
When start developing the exercise, follow the requirements below:
- Have to use the Java language mainly and may use Perl or other languages to connect the Web to Java.
- All software requires to include user interfaces, and three approaches are available for user interface construction for the exercises of this course.
The grading would not be affected by the approach chosen, but user-friendliness will be heavily considered.
- Internet-enabled interface:
It is the most popular one and a trend for current IT systems.
The system entry page must be located at
http://undcemcs02.und.edu/~user.id/280/1/
and all pages must be hosted by http://undcemcs02.und.edu/~user.id/
.
- Graphical user interface:
It is the most difficult one (e.g., using AWT, Abstract Windowing Toolkit).
- Text user interface:
It is the least favorite one and an obsolete method.
An example is a 1-2-3 system like
Start Using the System.
1. Enter routes
2. List all routes
3. Show a specific route
4. Reset the system
5. Exit
Select (1/2/3/4/5): 3¶
⇓
Show a specific route.
Enter the route: 2¶
⇓
Route 2: South Middle School, Choice Fitness, Hugo, Columbia Mall, Altru, UND, Ralph, BK, Aerospace
1. Enter routes
2. List all routes
3. Show a specific route
4. Reset the system
5. Exit
Select (1/2/3/4/5): 2¶
⇓
...
|
Due Date and Submission Methods
Due on or before Monday, September 27, 2021:
- For the above Approach a, send the password for displaying the source code online to the instructor at wenchen@cs.und.edu (only one password for all interfaces and all exercises).
- For the above Approaches b and c,
- Send an email to the instructor at wenchen@cs.und.edu to set up an appointment to demonstrate your exercise to the instructor individually, so misunderstanding would be minimized.
The instructor will prepare a set of test data to be used by all students.
(Zoom at https://und.zoom.us/j/2489867333 will be used for demonstration.)
- Submit all source code via Blackboard.
Objective
This is the first part of the problem of finding a bus itinerary, which could be very complicated.
The exercise is made simple on purpose, and its objective is to have students practice Java I/O programming.
Keep in mind that the only effective way to learn a programming language is practicing, instead of studying concepts or writing some testing programs.
No pain, no gain 😂
Requirements
This is the first part of a bus-itinerary problem, which is to read, save, and list data.
The exercise includes the following requirements:
- (Violated: -20%)
The input data should not be erased unless specified, so the testing could be applied many times.
- (Entering bus routes (given): 25%) (Given code)
Enter routes one by one.
A route is a bi-directional sequence of bus stops, unique names, separated by commas such as
South Middle School, Choice Fitness, Rydell, Hugo, Columbia Mall, Altru, UND, Ralph, Burger King
(or South Middle School ⇔ Choice Fitness ⇔ Rydell ⇔ Hugo ⇔ Columbia Mall ⇔ Altru ⇔ UND ⇔ Ralph ⇔ Burger King)
Also, a bus stop can not be repeated in a sequence.
- (Listing all routes: 25%)
List the bus-stop sequences of all bus routes.
- (Listing a specific route: 25%)
List the bus-stop sequence of a specific bus route.
- (Instructor’s requirements: 25% total)
Other than the above system requirements, the instructor has the following requirements:
- (User-friendliness: 15%)
User-friendliness will be heavily considered when grading.
In the past, some exercises were awkward, which made the grading or browsing difficult.
- (System reset (given): 10%) (Given code)
The system can be reset, which is to clear all data stored in the database, files, or any data structure, so the instructor can test the system by using only his own test data.
That is the system has to include a button such as “Clear system” at the system entry page.
Programming Hints
The four essential components of software are (i) algorithms, (ii) data structures, (iii) programming languages, and (iv) code, where algorithms are the most critical one.
Finding a best bus itinerary is very complicated, and is most likely an
NP-complete problem, which may not be solved in polynomial time.
That is you have to find an approximation method to solve the problem because if it is not carefully planned, a brute-force or exhaustive method may take infinite time to find the answer.
However, a brute-force or exhaustive method may just work well for a small amount of data.
This exercise is only for input and output, so you do not need to worry about the complexity.
Using appropriate data structures for this exercise could save a great deal of effort from you.
An example of using the dynamic array
ArrayList
could be found at
A travel-agent case study.
A User Interface
An example of the exercise’s
interface is shown below:
Plagiarism Checking
If the web interfaces are used, the instructor has the following requirements.
It is for the instructor to find any plagiarism.
Each interface includes a button “Display source,” which is to list ALL the source code for implementing the functions of this interface.
Only one password is for all exercises and interfaces.
The system will be highly suspected if fail to implement this button.
The source code will be studied carefully for any suspected plagiarism.
Besides, the exercise is suspicious if the results are substantially different from the assumed results from the code.
The interface can be found from
here.
~/public_html/course/280/exercise/1/check.html
|
|
~/public_html/cgi-bin/280/exercise/1/Check.pl
|
|
#!/usr/bin/perl
use CGI;
$query = new CGI;
$act = $query->param( 'act' );
$password = $query->param( 'password' );
$interface = $query->param( 'interface' );
if ( $act eq "Display source" ) {
# Remove leading and trailing spacing.
$password =~ s/^\s*(\S*)\s*$/$1/;
$interface =~ s/^\s*(\S*)\s*$/$1/;
# For security, remove some Unix metacharacters.
$password =~ s/;|>|>>|<|\*|\?|\&|\|//g;
$interface =~ s/;|>|>>|<|\*|\?|\&|\|//g;
system( "/usr/bin/java Check '$password' '$interface'" );
}
elsif ( $act eq "Help" ) {
print ( "Content-type: text/html\n\n" );
system( "/bin/cat Help.html" );
}
else {
print( "Content-type: text/html\n\n" );
print( "No such option: <em>$act</em>" );
}
|
~/public_html/cgi-bin/280/exercise/1/Check.java
|
|
// Import the File class.
import java.io.File;
// Import this class to handle errors.
import java.io.FileNotFoundException;
// Import the Scanner class to read text files.
import java.util.Scanner;
public class Check {
public static void main( String[ ] args ) {
if ( !( args[0].equals( "password" ) ) ) {
System.out.print ( "Content-type: text/html\n\n" );
System.out.println( "<html><body background='http://undcemcs01.und.edu/~wen.chen.hu/bg.jpg'>" );
System.out.println( "<font size='+1'>" );
System.out.println( "<center>Wrong password: <b>" + args[0] );
System.out.println( "</b></center></font></body></html>" );
}
else {
int interfaceNo = Integer.parseInt( args[1] );
Print p = new Print( );
switch( interfaceNo ) {
case 1:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "Check.pl" );
p.printFile( "Check.java" );
break;
case 2:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "InsertRoutes.pl" );
p.printFile( "insertRoutes.java" );
break;
case 3:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "ListAllRoutes.pl" );
p.printFile( "ListAllRoutes.java" );
break;
case 4:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "ShowRoute.pl" );
p.printFile( "ShowRoute.java" );
break;
default:
System.out.print ( "Content-type: text/html\n\n" );
System.out.println( "<html><body background='http://undcemcs01.und.edu/~wen.chen.hu/bg.jpg'>" );
System.out.println( "<font size='+1'>" );
System.out.println( "<center>No such interface: <b>" + args[1] );
System.out.println( "</b></center></font></body></html>" );
}
}
}
}
class Print {
public void printFile( String fileName ) {
System.out.print ( "\n// ===================== " );
System.out.print ( fileName );
System.out.println( " =====================\n" );
try {
File myObj = new File( fileName );
Scanner myReader = new Scanner( myObj );
while ( myReader.hasNextLine( ) )
System.out.println( myReader.nextLine( ) );
myReader.close( );
}
catch( FileNotFoundException e ) {
System.out.println( "An error occurred." );
e.printStackTrace( );
}
}
}
|
Modify the password in the
Line 11 to the password you pick.
Evaluations
The following features will be considered when grading:
- Specifications:
- The instructor (or your assumed client) has given the exercise specifications as many details as he possibly can.
If you are confused about the specifications, you should ask in advance.
Study the specifications very carefully.
No excuses for misunderstanding or missing parts of the specifications after grading.
- The specifications are not possible to cover every detail.
You are free to implement the issues not mentioned in the specifications, but the implementations should make sense.
Implemented functions lacking of common sense may cause the instructor to grade your exercise mistakenly, and thus lower your grade.
- The exercise must meet the specifications.
However, exercises with functions exceeding the specifications will not receive extra credits.
- Grading:
- This exercise will not be graded if the submission methods are not met.
Students take full responsibility if the website/system is not working.
- A set of test data will be used by all students.
The grades are primarily based on the results of testing.
Other factors such as performance, programming styles, algorithms, and data structures will be only considered minimally.
- After the data is entered, it should NOT be erased unless specified.
- Before submitting the exercise, test it comprehensively.
Absolutely no extra points will be given after grading.
- This course is about the Java language, so Java should be used to implement all functions, except the functions related to web (like connecting the Web to Java by using Perl or PHP).
- The total weight of all four exercises (06%, 09%, 12%, and 13%, respectively) is 40% of the final grade.
- If not specified, no error checking is required; i.e., you may assume the input is always correct for that case.
For example, the bus stops entered will always be unique names.
- Feel free to design your own interfaces; user-friendliness will be heavily considered; each function/button will be tested extensively; and from the source code submitted, the programs will be examined.
- The newest Firefox browser will be used to grade exercises.
Note that Internet Explorer, Edge, Chrome, and Firefox are not compatible.
That is your exercises may work on the IE, Edge, or Chrome but not Firefox.
- The systems have to be active until the end of this semester.
They will be re-checked for plagiarism from time to time.
- The instructor will inform you the exercise evaluations by emails after grading.
- Comments:
- Make the exercise work first.
Do not include extra features, such as fancy interfaces, in the beginning.
By the way, you will not receive credits for the extra features.
- Time management is critical for software development.
If you are not able to complete the exercise, display whatever you have accomplished, so the instructor can give partial credit to your exercise.
- One way to build a website/system from scratch is to design the user interfaces first and then implement the system button by button or step by step.
By doing this way, it could simplify the construction.
The recommended construction steps are
- Examine the specifications very carefully.
- Build the user interfaces (Java or Web including HTML, CSS, and JavaScript).
- Implement the system button by button (Java or Web including Java and Perl).
- Test the exercise thoroughly.
- If web interface is used, minimum web programming (for connecting the Web to Java) skills will be needed in this exercise.
HTML and CSS should be easy to learn.
Check CGI 101 for dynamic web programming.
Besides, many dynamic web programming examples are given in the class slides.
CGI (Common Gateway Interface) is an old technology, but is easy to learn and has no problems implementing most of web features.
However, the problem of CGI is the security and we may ignore the security issues at this moment.
- In addition, remote work is a trend for IT workers.
If web interface is used, it also allows you to learn how to do it by using the VPN (virtual private networks) to connect to our Linux server
undcemcs02.und.edu
, and having the exercises set up at the server and be accessed from the clients.
- This course may be the only chance for you to learn the construction of dynamic websites including the programming of web, Java, and client-server/cloud connection, which are critical and may not be offered by any other courses in this school.
“When someone loves you, the way they talk about you is different.
You feel safe and comfortable.”
― Jess C. Scott, The Intern
|