Programming Exercise I: My Shopping List: Part I
(Industry-Level, Second-to-None Comprehensive Specifications)
Absolutely no copying others’ works
According to a study, students in computer 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 shopping list 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.
- The exercise has to be Internet-enabled (a trend of 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/
.
- The systems have to be active even after being graded until the end of this semester.
They will be re-checked for plagiarism from time to time.
Due Date and Submission Methods
Due on or before Monday, September 28, 2023.
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).
Objective
An application of grocery shopping is trivial, but its implications, such as scheduling and optimizing, could be significant.
The objective of this exercise is to have students set up the user interfaces, which are required for all software.
There are three approaches are available for user interface construction:
- 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.
This exercise is to set up the Internet-enabled interfaces for the grocery shopping application.
Requirements
This is the first part of a grocery shopping application, which is to read, save, and list data.
The exercise includes the following requirements:
- The input data should not be erased unless specified, so the testing could be applied many times.
- (Entering food items: 15%)
Enter items one by one.
The data of an item includes
- a unique name such as French fries and double cheeseburger, and
- a price like $2.49.
- (Entering meal combos: 15%)
After entering all food items, enter combos one by one.
The data of a combo includes
- a unique number (assigned by the system automatically after being entered),
- a list of food items such as (French fries, coke, cheeseburger) and (Caesar salad, coke, double cheeseburger), and
- a price like $7.99, which is greater than the sum of all its food items’ prices.
- (Listing all food items: 15%)
List the details of all food items including
- item names and
- item prices.
- (Listing all combos: 15%)
List the details of all meal combos each including
- combo number,
- all food items of the combo, and
- combo price.
- (Listing a specific combo: 15%)
After entering the combo number, list its details including
- combo number,
- all food items of the combo, and
- combo price.
- (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: 10%)
The system can be reset, which is to clear all data stored in the database, files, and arrays, 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.
A User Interface
An example of the exercise’s
interface is shown below:
Plagiarism-Proof
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.
~/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( "EnterItems.pl" );
p.printFile( "EnterItems.java" );
break;
case 3:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "ShowItem.pl" );
p.printFile( "ShowItem.java" );
break;
case 4:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "EnterCombos.pl" );
p.printFile( "EnterCombos.java" );
break;
case 5:
System.out.print( "Content-type: text/plain\n\n\n" );
p.printFile( "ShowCombo.pl" );
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.
For example, finding the lowest price could be an NP-hard problem.
Instead of finding an optimizing algorithm, an exhaustive search may be used to find the answer.
- 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 three exercises (10%, 15%, and 15%) is 40% of the final grade.
Exercises I & II are required, and you can pick either Exercise III or IV.
- If not specified, no error checking is required; i.e., you may assume the input is always correct for that case.
For example, the food items entered will always be valid 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
- Examining the specifications very carefully,
- Building the user interfaces (Java or Web: HTML, CSS, and JavaScript),
- Implementing the system button by button (Java or Web: Java and Perl), and
- Testing the exercise thoroughly.
- 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.
- The only effective way to learn a programming language is practicing, instead of studying concepts or writing some testing programs.
No pain, no gain 😂