Complete the Programming of an Object-Oriented Console Application

profiletapastdas
U10A1_OOConsoleRegisterForCourse.zip

U10A1_OOConsoleRegisterForCourse/build.xml

Builds, tests, and runs the project U10A1_OOConsoleRegisterForCourse.

U10A1_OOConsoleRegisterForCourse/build/classes/.netbeans_automatic_build

U10A1_OOConsoleRegisterForCourse/build/classes/.netbeans_update_resources

U10A1_OOConsoleRegisterForCourse/build/classes/u10a1_ooconsoleregisterforcourse/Course.class

package u10a1_ooconsoleregisterforcourse;
public synchronized class Course {
    private String code;
    private int creditHour;
    private boolean isRegisterdFor;
    public void Course(String, int);
    public void setCode(String);
    public String getCode();
    public void setCrditHour(int);
    public int getCreditHour();
    public void setIsRegisteredFor(boolean);
    public boolean getIsRegisteredFor();
}

U10A1_OOConsoleRegisterForCourse/build/classes/u10a1_ooconsoleregisterforcourse/U10A1_OOConsoleRegisterForCourse.class

package u10a1_ooconsoleregisterforcourse;
public synchronized class U10A1_OOConsoleRegisterForCourse {
    public void U10A1_OOConsoleRegisterForCourse();
    public static void main(String[]);
    public static int getChoice(Course[], java.util.Scanner);
    public static int ValidateChoice(int, int, Course[]);
    public static boolean IsRegisteredBefore(int, Course[]);
    public static void WriteCurrentRegistration(Course[], int);
}

U10A1_OOConsoleRegisterForCourse/manifest.mf

Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build

U10A1_OOConsoleRegisterForCourse/nbproject/build-impl.xml

Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url

U10A1_OOConsoleRegisterForCourse/nbproject/genfiles.properties

build.xml.data.CRC32=4e3f342c build.xml.script.CRC32=2ee794bd [email protected] # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=4e3f342c nbproject/build-impl.xml.script.CRC32=b5bbdb0c nbproject/[email protected]

U10A1_OOConsoleRegisterForCourse/nbproject/private/private.properties

compile.on.save=true user.properties.file=C:\\Users\\omora\\AppData\\Roaming\\NetBeans\\8.1\\build.properties

U10A1_OOConsoleRegisterForCourse/nbproject/private/private.xml

U10A1_OOConsoleRegisterForCourse/nbproject/project.properties

annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/U10A1_OOConsoleRegisterForCourse.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=u10a1_ooconsoleregisterforcourse.U10A1_OOConsoleRegisterForCourse manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test

U10A1_OOConsoleRegisterForCourse/nbproject/project.xml

org.netbeans.modules.java.j2seproject U10A1_OOConsoleRegisterForCourse

U10A1_OOConsoleRegisterForCourse/src/u10a1_ooconsoleregisterforcourse/Course.java

U10A1_OOConsoleRegisterForCourse/src/u10a1_ooconsoleregisterforcourse/Course.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package  u10a1_ooconsoleregisterforcourse ;

/**
 *
 *  @author  omora
 */
public   class   Course   {

     private   String  code  =   "" ;
     private   int  creditHour  =   0 ;
     private   boolean  isRegisterdFor  =   false ;
    
     public   Course ( String  code ,   int  creditHour ){
         this . code  =  code ;
         this . creditHour  =  creditHour ;
     }
    
     public   void  setCode ( String  code ){
         this . code  =  code ;
     }
    
     public   String  getCode ()   {
         return   this . code ;
     }
    
     public   void  setCrditHour ( int  creditHour )   {
         this . creditHour  =  creditHour ;
     }
    
     public   int  getCreditHour ()   {
         return   this . creditHour ;
     }     
    
     public   void  setIsRegisteredFor ( boolean  trueOrFalse ){
         this . isRegisterdFor  =  trueOrFalse ;
     }
    
     public   boolean  getIsRegisteredFor ()   {
         return   this . isRegisterdFor ;
     }
        
}

U10A1_OOConsoleRegisterForCourse/src/u10a1_ooconsoleregisterforcourse/U10A1_OOConsoleRegisterForCourse.java

U10A1_OOConsoleRegisterForCourse/src/u10a1_ooconsoleregisterforcourse/U10A1_OOConsoleRegisterForCourse.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package  u10a1_ooconsoleregisterforcourse ;

import  java . util . Scanner ;

/**
 *
 *  @author  omora
 */
public   class   U10A1_OOConsoleRegisterForCourse   {


     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String []  args )   {
         // TODO code application logic here
        
         System . out . println ( "Teacher's Copy" );

         Scanner  input  =   new   Scanner ( System . in );
        
         //Courses is an array of course objects
         //see the Course.java source code for members of Course
         Course []  courses  =   {
             new   Course ( "IT1006" ,   6 ),
             new   Course ( "IT4782" ,   3 ),
             new   Course ( "IT4789" ,   3 ),
             new   Course ( "IT4079" ,   6 ),
             new   Course ( "IT2230" ,   3 ),
             new   Course ( "IT3345" ,   3 ),
             new   Course ( "IT2249" ,   6 )
         };
        

         //choice is the number selected by the user
         int  choice ;
         int  totalCredit  =   0 ;
         String  yesOrNo  =   "" ;

       
         do   {

            choice  =  getChoice ( courses ,  input );
   
             switch   ( ValidateChoice ( choice ,  totalCredit ,  courses ))   {
                 case   - 1 :
                     System . out . println ( "**Invalid** - Your selection of "   +  
                            choice  +   " is not a recognized course." );
                     break ;
                 case   - 2 :
                     System . out . println ( "**Invalid** - You have already registerd for this "   +
                            courses [ choice - 1 ]. getCode ()   +   " course." );
                     break ;
                 case   - 3 :
                     System . out . println ( "**Invalid** - You can not register for more than 9 credit hours." );
                     break ;
                 case   0 :
                     System . out . println ( "Registration Confirmed for course "   +
                            courses [ choice - 1 ]. getCode ()   );
                    totalCredit  +=  courses [ choice - 1 ]. getCreditHour ();
                    courses [ choice - 1 ]. setIsRegisteredFor ( true );
                     break ;
             }
            
             WriteCurrentRegistration ( courses ,  totalCredit );
 
             System . out . print ( "\nDo you want to try again? (Y|N)? : " );
            
            yesOrNo  =  input . next (). toUpperCase ();
            
         }   while   ( yesOrNo . equals ( "Y" ));

         System . out . println ( "Thank you for registering with us" );
     }

     //This method prints out the selection menu to the user in the form of
     //[selection number]Course Code (Course Credit Hours)
     //from the courses array one per line 
     //and then prompts the user to make a number selection
     public   static   int  getChoice ( Course []  courses ,   Scanner  input )   {     
         System . out . println ( "Please type the number inside the [] to register for a course" );
         System . out . println ( "The number inside the () is the credit hours for the course" );
        
         // TO DO
         // loop over the courses array and print out the attributes of its
         //objects in the format of 
         //[selection number]Course Code (Course Credit Hours)
         //one per line

         System . out . print ( "Enter your choice : " );  

         return   ( input . nextInt ());
     }
    
     //This method validates the user menu selection
     //against the given registration business rules
     //it returns the following code based on the validation result
     // -1 = invalid, unrecognized menu selection
     // -2 = invalid, alredy registered for the course
     // -3 = invalid, No more than 9 credit hours allowed
     // 0 = menu selection is valid

     public   static   int   ValidateChoice ( int  choice ,   int  totalCredit ,   Course []  courses )   {
         if   ( choice  <   1   ||  choice  >   7 )
             return   - 1 ;
         else   if   ( IsRegisteredBefore ( choice ,  courses )   )  
             return   - 2 ;
         else   if   (   ( totalCredit  +  courses [ choice - 1 ]. getCreditHour ())   >   9 )
             return   - 3 ;
         return   0 ;
     }
    
     //This method checks the courses array of course object to
     //see if the course has already been registered for or not
     public   static   boolean   IsRegisteredBefore ( int  choice ,   Course []  courses )   {
         for ( int  i  =   0 ;  i  <  courses . length ;  i ++ )
             if ( courses [ choice - 1 ]. getIsRegisteredFor ()   ==   true )
                 return   true ;
         return   false ;
     }
    
     //This method prints the current list of registered courses thus far
     //from the courses array separated by , and enclosed inside { }
     //It also prints the total credit registered for thus far
     public   static   void   WriteCurrentRegistration ( Course []  courses ,   int  totalCredit )   {

         System . out . print ( "Current course registration:  { "   );  
        
         // TO DO
         // loop over the courses array, determine which courses are registered
         //for thus and print them out in the format of
         //{ list of courses separated by , }
        
         System . out . println ( " }"   );      

         System . out . println ( "Current registration total credit = "   +  totalCredit );
     }
    
}