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:

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:

  1. 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/ .
  2. Graphical user interface: It is the most difficult one (e.g., using AWT, Abstract Windowing Toolkit).
  3. 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:

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

Password:       Interface:                    



~/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: