Multiple homework | Computer Science homework help

 

 

 

 

 

  1. Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values).  You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input).  All 15 items below are for a single purchase.  There are five sets of inputs as follows:

     

    Product 1    1 unit                    (cost is $2.98 per unit)

    Product 2    2 units                  (cost is $4.50 per unit)

    Product 3    3 units                  (cost is $9.98 per unit)

    Product 4    4 units                  (cost is $4.49 per unit)

    Product 5    5 units                  (cost is $6.87 per unit)

     

    Your application must calculate and display the total retail value of all products sold, after all 5 pairs of inputs are completed.  You must also display the total after each new pair of input values is entered.

     

    (This program was taken from Exercise 5.17 on page 228 of Deitel & Deitel’s “Java How to Program (Sixth Edition)” (2005 by Pearson Publishing Co.))

     

  2. You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

     

  3. You are to submit the following deliverables to the Assignment Link in a single Microsoft Word file:

    1. A screen snapshot of your Java source code (just the beginning is OK) as it appears in your IDE (e.g. Net Beans, Eclipse, etc.) or editor (e.g. a Windows Command Prompt DOS “more” of the .java file’s first screen).

    2. A listing of your entire Java source code in the same Microsoft Word file as item a), and following item a).  You can simply copy and paste the text from your IDE into Word.  Be sure to maintain proper code alignment by using Courier font for this item.

    3. A screen snapshot of your program’s input and output in the same Microsoft Word file, and following item b).  You must include screen snapshots of all inputs and all outputs, not just a sample.

       

  4. Your instructor may compile and run your program to verify that it compiles and executes properly.

     

  5. You will be evaluated on (in order of importance):

    1. Inclusion of all deliverables in Step #3.

    2. Correct execution of your program.

    3. Adequate commenting of your code.

    4. Good programming style (as specified in the textbook’s examples).

    5. Neatness in packaging and labeling of your deliverables.

       

      Deficiencies in any of the above areas are subject to up to a 1 (one) point deduction, per area, based on the severity of the deficiency.

       

  6. Programs received after the due date/time will receive a score of zero since there are already 15 extra points built into the grading for this class.

     

  7. Here is some pseudocode/skeleton Java code for one possible solution to the program to get you started (this shows procedural code, but an object-oriented solution would have been better, since Java is a pure object-oriented language):

     

    import the classes you need

    main

         declare productNo and quantity variables

         declare and initialize lineAmount and orderAmount variables

    set up a String for your output via the Scanner class (or you may use the JTextArea

              GUI component – this will require additional research beyond the textbook!)

         start filling the String (or JTextArea) with the headers for Product, Quantity, Line

                  Cost, and Total Cost

         prompt the user for the first productNo

         while the productNo is not the sentinel value of -1

                  get the quantity

                  if the quantity is -1 then exit

                  switch on productNo

                            in each case, determine the new lineAmount

                  add the lineAmount to the orderAmount

                  add the new subtotal/order line information to the output String (or JTextArea)

                  get the next productNo

         output the total orderAmount

     

     

  8. Here is an example of what the beginning of your output might look like after the first product has been input and the information for the second one is starting to be entered.  Note that this output uses a JTextArea GUI component for easy assembly and output of multiline text.

     

    It is NOT required that you use a JTextArea component!   You may use the Scanner class if you want.

     

    If you do want to use a JTextArea component though, you will have to do some research beyond our textbook.  Note that this is a frequent activity you’ll find yourself doing day-to-day in any IT programming job.  Not all answers are “right in the book”!  Look at it as a learning opportunity to familiarize yourself with the Java API.

     

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This would continue with a quantity of 2 for Product No. 2, then Product 3 with a quantity of 3, then Product 4 with a quantity of 4, and finally Product 5 with a quantity of 5. 

 

 

 

Therefore the quantity of each product matches the Product No.  And there are 15 total units for order. 

 

 

 

Note that there is a single correct answer for the order total!

 

 

 

 

 

 

  1. Develop a Java application to calculate the monthly paychecks for a number of different types of employees.  The employee types are created in a subclass array based on parent base class Employee.  Initial code is provided for each class and for a driver class. 

     

    You will need to compile each Java source file (provided below) separately, in its own file since they are public classes, to create a .class file for each, ideally keeping them all in the same directory.  

     

    You should first compile and execute the original classes and then make your customer modifications for this program.

     

    You should compile Date.java first, then Employee.java, then CommissionEmployee.java, then BasePlusCommission.java, then HourlyEmployee.java, then SalariedEmployee.java, and finally PayrollSystemTest.java.  And maintain this compilation order when you make your customized modifications to these classes later.

     

    As part of the modifications you need to make to the supplied code, you are to prompt the user for all the data that is now provided in the code for the class PayrollSystemTest (i.e. instead of using these values from their declaration in the code, get data from prompting the user for it, one value at a time).  All program output, including prompts and results and all program input must be done from the PayrollSystemTest class.

     

    In addition you need to add a new private instance field “birthDate” to the Employee class.  The “birthDate” field must be a Date data type, not a String!  Add get and set methods to Employee class for this new birthDate field.    

     

    The birthDate field must be determined from separate integer values, supplied by the user, for the birth month, day, and year.  As with all other inputs, these three birth date components must be prompted from and input to class PayrollSystemTest.  Once input, these three parameter values must then be supplied to the appropriate modified employee subclass constructor, and then the subclass constructors supply these three values to their parent class, a modified Employee class constructor.

     

    The single birthDate field of a Date data type must be declared and initialized in the Employee class.

     

    In class PayrollSystemTest create an array of Employee variables to store references to the various employee objects.  In a loop, calculate the monthly paycheck amount for each Employee (polymorphically), and add a $100.00 bonus to the person’s monthly payroll amount if the current month (i.e. November) is the month in which the Employee’s birthday occurs.

     

    Your program should input data and create the five employees below on the version of the program you submit for grading.  Your program must calculate their monthly salaries for November (assumed to be the “current” month).  Assume that the monthly salary is simply four times the weekly salary.

     

    1. one Salaried Employee with a weekly salary of $1000 and a birthday of  January 1, 1960,

    2. one Salaried Employee with a weekly salary of $1000 and a birthday in this month (November 1, 1961)

    3. one Commission Employee Worker with a gross weekly sales of $12,000 and a 5% commission rate and a birthday of February 1, 1962,

    4. one Base Plus Commission Employee with a gross weekly sales of $10,000, a 3% commission, and a $500 base weekly salary with a birthday of March 1, 1963, and

    5. one Hourly Employee with a wage of $20/hour working for 40 hours and a birthday of April 1, 1964

       

      You should make up your own employee names for the five required employees above.  Make sure you create the employees in the order above.

       

      In prompting the user for all input values for the five employees above, your program

      essentially replaces the existing main() method of  PayrollSystemTest.java.  You may user whatever input class you want (e.g. JOptionPane, Scanner).  Keep all other lines of the code in PayrollSystemTest as they are originally, including the code that gives a 10% increase to the Base Plus Commission employee. 

       

      You will probably find it helpful to prompt for the worker type first.  You may

      hardcode “November” as the special bonus month. 

       

      Since the outputs are to be for monthly paychecks, just multiply the weekly

      salaries, weekly output quantities, and weekly hours by 4. Display your results

      for each worker’s salary after all data for that employee type has been entered

      and the salary determined.

       

      Your output should appear like the example below (using the current examples in the code for PayrollSystemTest (the “Employees processed individually” portion isn’t shown, and monthly salaries are shown below as required by this program vs. weekly salaries that would be produced from the unmodified code).  Note that the test data is shown below.  Your five employees will create a different set of outputs.

       

      Employees process polymorphically:

       

      salaried employee: John Smith

      social security number: 111-11-1111

      date of birth: 01/02/1960(current code won’t do this but yours must)

      weekly salary: $800.00

      earned $3200.00

       

      hourly employee: Karen Price

      social security number: 222-22-2222

      date of birth: 01/02/1960(current code won’t do this but yours must)

      hourly wage: $16.75; hours worked: 40.00

      earned $2680.00

       

      commission employee: Sue Jones

      social security number: 333-33-3333

      date of birth: 01/02/1960(current code won’t do this but yours must)

      gross sales: $10,000.00; commission rate: 0.06

      earned $2400.00

       

      base-salaried commission employee: Bob Lewis

      social security number: 444-44-4444

      date of birth: 01/02/1960(current code won’t do this but yours must)

      gross sales: $5,000.00; commission rate: 0.04; base salary: $300.00

      new base salary with 10% increase is: $330.00

      earned: $2120.00

       

      Employee 0 is a SalariedEmployee

      Employee 1 is a HourlyEmployee

      Employee 2 is a CommissionEmployee

      Employee 3 is a BasePlusCommissionEmployee

       

      Be sure that you include screen snapshots of all user inputs, and all output.  Failure to do so will result in lost points.

       

      (This program was taken from Exercise 10.9 on page 508 of Deitel & Deitel’s “Java How to Program (Sixth Edition)” (2005 by Pearson Publishing Co.))

       

  2. You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

     

  3. You are to submit the following deliverables to the Assignment Link in a single Microsoft Word file:

    1. A screen snapshot of your Java source code (just the beginning is OK) as it appears in your IDE (e.g. Net Beans, Eclipse, etc.) or editor (e.g. a Windows Command Prompt DOS “more” of the .java file’s first screen).

       

    2. A listing of your entire Java source code, for all classes, showing your final version of the code, in the same Microsoft Word file as item a), and following item a).  You can simply copy and paste the text from your IDE into Word.  Be sure to maintain proper code alignment by using Courier font for this item.  Source files for all classes must be submitted for full credit.

       

    3. A screen snapshot of your program’s execution inputs and output in the same Microsoft Word file, and following item b).  Be sure that you include screen snapshots of all user inputs, and all output.  Failure to do so will result in lost points.

       

  4. Your instructor may compile and run your program to verify that it compiles and executes properly.

     

  5. You will be evaluated on (in order of importance):

    1. Inclusion of all deliverables in Step #3, include all user’s inputs and all output

    2. Correct execution of your program.

    3. Adequate commenting of your code.

    4. Good programming style (as specified in the textbook’s examples).

    5. Neatness in packaging and labeling of your deliverables.

       

      Deficiencies in any of the above areas are subject to up to a 2 (two) point deduction, per area, based on the severity of the deficiency.

       

  6. Programs received after the due date/time will receive a score of zero since there are already 15 extra points built into the grading for this class.

     

     

    Here’s the initial code you need to modify!

     

 

// PayrollSystemTest.java

 

// Employee hierarchy test program.

 

 

 

public class PayrollSystemTest

 

{

 

   public static void main( String args[] )

 

   {

 

      // create subclass objects

 

      SalariedEmployee salariedEmployee =

 

         new SalariedEmployee( “John”, “Smith”, “111-11-1111”, 800.00 );

 

      HourlyEmployee hourlyEmployee =

 

         new HourlyEmployee( “Karen”, “Price”, “222-22-2222”, 16.75, 40 );

 

      CommissionEmployee commissionEmployee =

 

         new CommissionEmployee(

 

         “Sue”, “Jones”, “333-33-3333”, 10000, .06 );

 

      BasePlusCommissionEmployee basePlusCommissionEmployee =

 

         new BasePlusCommissionEmployee(

 

         “Bob”, “Lewis”, “444-44-4444”, 5000, .04, 300 );

 

 

 

      System.out.println( “Employees processed individually:n” );

 

     

 

      System.out.printf( “%sn%s: $%,.2fnn”,

 

         salariedEmployee, “earned”, salariedEmployee.earnings() );

 

      System.out.printf( “%sn%s: $%,.2fnn”,

 

         hourlyEmployee, “earned”, hourlyEmployee.earnings() );

 

      System.out.printf( “%sn%s: $%,.2fnn”,

 

         commissionEmployee, “earned”, commissionEmployee.earnings() );

 

      System.out.printf( “%sn%s: $%,.2fnn”,

 

         basePlusCommissionEmployee,

 

         “earned”, basePlusCommissionEmployee.earnings() );

 

 

 

      // create four-element Employee array

 

      Employee employees[] = new Employee[ 4 ];

 

 

 

      // initialize array with Employees

 

      employees[ 0 ] = salariedEmployee;

 

      employees[ 1 ] = hourlyEmployee;

 

      employees[ 2 ] = commissionEmployee;

 

      employees[ 3 ] = basePlusCommissionEmployee;

 

 

 

      System.out.println( “Employees processed polymorphically:n” );

 

     

 

      // generically process each element in array employees

 

      for ( Employee currentEmployee : employees )

 

      {

 

         System.out.println( currentEmployee ); // invokes toString

 

 

 

         // determine whether element is a BasePlusCommissionEmployee

 

         if ( currentEmployee instanceof BasePlusCommissionEmployee )

 

         {

 

            // downcast Employee reference to

 

            // BasePlusCommissionEmployee reference

 

            BasePlusCommissionEmployee employee =

 

               ( BasePlusCommissionEmployee ) currentEmployee;

 

 

 

            double oldBaseSalary = employee.getBaseSalary();

 

            employee.setBaseSalary( 1.10 * oldBaseSalary );

 

            System.out.printf(

 

               “new base salary with 10%% increase is: $%,.2fn”,

 

               employee.getBaseSalary() );

 

         } // end if

 

 

 

         System.out.printf(

 

            “earned $%,.2fnn”, currentEmployee.earnings() );

 

      } // end for

 

 

 

      // get type name of each object in employees array

 

      for ( int j = 0; j < employees.length; j++ )

 

         System.out.printf( “Employee %d is a %sn”, j,

 

            employees[ j ].getClass().getName() );

 

   } // end main

 

} // end class PayrollSystemTest

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

 

 

// Employee.java

 

// Employee abstract superclass.

 

 

 

public abstract class Employee

 

{

 

   private String firstName;

 

   private String lastName;

 

   private String socialSecurityNumber;

 

 

 

   // three-argument constructor

 

   public Employee( String first, String last, String ssn )

 

   {

 

      firstName = first;

 

      lastName = last;

 

      socialSecurityNumber = ssn;

 

   } // end three-argument Employee constructor

 

 

 

   // set first name

 

   public void setFirstName( String first )

 

   {

 

      firstName = first;

 

   } // end method setFirstName

 

 

 

   // return first name

 

   public String getFirstName()

 

   {

 

      return firstName;

 

   } // end method getFirstName

 

 

 

   // set last name

 

   public void setLastName( String last )

 

   {

 

      lastName = last;

 

   } // end method setLastName

 

 

 

   // return last name

 

   public String getLastName()

 

   {

 

      return lastName;

 

   } // end method getLastName

 

 

 

   // set social security number

 

   public void setSocialSecurityNumber( String ssn )

 

   {

 

      socialSecurityNumber = ssn; // should validate

 

   } // end method setSocialSecurityNumber

 

 

 

   // return social security number

 

   public String getSocialSecurityNumber()

 

   {

 

      return socialSecurityNumber;

 

   } // end method getSocialSecurityNumber

 

 

 

   // return String representation of Employee object

 

   public String toString()

 

   {

 

      return String.format( “%s %snsocial security number: %s”,

 

         getFirstName(), getLastName(), getSocialSecurityNumber() );

 

   } // end method toString

 

 

 

   // abstract method overridden by subclasses

 

   public abstract double earnings(); // no implementation here

 

} // end abstract class Employee

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

// SalariedEmployee.java

 

// SalariedEmployee class extends Employee.

 

 

 

public class SalariedEmployee extends Employee

 

{

 

   private double weeklySalary;

 

 

 

   // four-argument constructor

 

   public SalariedEmployee( String first, String last, String ssn,

 

      double salary )

 

   {

 

      super( first, last, ssn ); // pass to Employee constructor

 

      setWeeklySalary( salary ); // validate and store salary

 

   } // end four-argument SalariedEmployee constructor

 

 

 

   // set salary

 

   public void setWeeklySalary( double salary )

 

   {

 

      weeklySalary = salary < 0.0 ? 0.0 : salary;

 

   } // end method setWeeklySalary

 

 

 

   // return salary

 

   public double getWeeklySalary()

 

   {

 

      return weeklySalary;

 

   } // end method getWeeklySalary

 

 

 

   // calculate earnings; override abstract method earnings in Employee

 

   public double earnings()

 

   {

 

      return getWeeklySalary();

 

   } // end method earnings

 

 

 

   // return String representation of SalariedEmployee object

 

   public String toString()

 

   {

 

      return String.format( “salaried employee: %sn%s: $%,.2f”,

 

         super.toString(), “weekly salary”, getWeeklySalary() );

 

   } // end method toString

 

} // end class SalariedEmployee

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

// HourlyEmployee.java

 

// HourlyEmployee class extends Employee.

 

 

 

public class HourlyEmployee extends Employee

 

{

 

   private double wage; // wage per hour

 

   private double hours; // hours worked for week

 

 

 

   // five-argument constructor

 

   public HourlyEmployee( String first, String last, String ssn,

 

      double hourlyWage, double hoursWorked )

 

   {

 

      super( first, last, ssn );

 

      setWage( hourlyWage ); // validate and store hourly wage

 

      setHours( hoursWorked ); // validate and store hours worked

 

   } // end five-argument HourlyEmployee constructor

 

 

 

   // set wage

 

   public void setWage( double hourlyWage )

 

   {

 

      wage = ( hourlyWage < 0.0 ) ? 0.0 : hourlyWage;

 

   } // end method setWage

 

 

 

   // return wage

 

   public double getWage()

 

   {

 

      return wage;

 

   } // end method getWage

 

 

 

   // set hours worked

 

   public void setHours( double hoursWorked )

 

   {

 

      hours = ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) ) ?

 

         hoursWorked : 0.0;

 

   } // end method setHours

 

 

 

   // return hours worked

 

   public double getHours()

 

   {

 

      return hours;

 

   } // end method getHours

 

 

 

   // calculate earnings; override abstract method earnings in Employee

 

   public double earnings()

 

   {

 

      if ( getHours() <= 40 ) // no overtime

 

         return getWage() * getHours();

 

      else

 

         return 40 * getWage() + ( getHours() – 40 ) * getWage() * 1.5;

 

   } // end method earnings

 

 

 

   // return String representation of HourlyEmployee object

 

   public String toString()

 

   {

 

      return String.format( “hourly employee: %sn%s: $%,.2f; %s: %,.2f”,

 

         super.toString(), “hourly wage”, getWage(),

 

         “hours worked”, getHours() );

 

   } // end method toString

 

} // end class HourlyEmployee

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

// CommissionEmployee.java

 

// CommissionEmployee class extends Employee.

 

 

 

public class CommissionEmployee extends Employee

 

{

 

   private double grossSales; // gross weekly sales

 

   private double commissionRate; // commission percentage

 

 

 

   // five-argument constructor

 

   public CommissionEmployee( String first, String last, String ssn,

 

      double sales, double rate )

 

   {

 

      super( first, last, ssn );

 

      setGrossSales( sales );

 

      setCommissionRate( rate );

 

   } // end five-argument CommissionEmployee constructor

 

 

 

   // set commission rate

 

   public void setCommissionRate( double rate )

 

   {

 

      commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate : 0.0;

 

   } // end method setCommissionRate

 

 

 

   // return commission rate

 

   public double getCommissionRate()

 

   {

 

      return commissionRate;

 

   } // end method getCommissionRate

 

 

 

   // set gross sales amount

 

   public void setGrossSales( double sales )

 

   {

 

      grossSales = ( sales < 0.0 ) ? 0.0 : sales;

 

   } // end method setGrossSales

 

 

 

   // return gross sales amount

 

   public double getGrossSales()

 

   {

 

      return grossSales;

 

   } // end method getGrossSales

 

 

 

   // calculate earnings; override abstract method earnings in Employee

 

   public double earnings()

 

   {

 

      return getCommissionRate() * getGrossSales();

 

   } // end method earnings

 

 

 

   // return String representation of CommissionEmployee object

 

   public String toString()

 

   {

 

      return String.format( “%s: %sn%s: $%,.2f; %s: %.2f”,

 

         “commission employee”, super.toString(),

 

         “gross sales”, getGrossSales(),

 

         “commission rate”, getCommissionRate() );

 

   } // end method toString

 

} // end class CommissionEmployee

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

// BasePlusCommissionEmployee.java

 

// BasePlusCommissionEmployee class extends CommissionEmployee.

 

 

 

public class BasePlusCommissionEmployee extends CommissionEmployee

 

{

 

   private double baseSalary; // base salary per week

 

 

 

   // six-argument constructor

 

   public BasePlusCommissionEmployee( String first, String last,

 

      String ssn, double sales, double rate, double salary )

 

   {

 

      super( first, last, ssn, sales, rate );

 

      setBaseSalary( salary ); // validate and store base salary

 

   } // end six-argument BasePlusCommissionEmployee constructor

 

 

 

   // set base salary

 

   public void setBaseSalary( double salary )

 

   {

 

      baseSalary = ( salary < 0.0 ) ? 0.0 : salary; // non-negative

 

   } // end method setBaseSalary

 

 

 

   // return base salary

 

   public double getBaseSalary()

 

   {

 

      return baseSalary;

 

   } // end method getBaseSalary

 

 

 

   // calculate earnings; override method earnings in CommissionEmployee

 

   public double earnings()

 

   {

 

      return getBaseSalary() + super.earnings();

 

   } // end method earnings

 

 

 

   // return String representation of BasePlusCommissionEmployee object

 

   public String toString()

 

   {

 

      return String.format( “%s %s; %s: $%,.2f”,

 

         “base-salaried”, super.toString(),

 

         “base salary”, getBaseSalary() );

 

   } // end method toString  

 

} // end class BasePlusCommissionEmployee

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

// Date.java

 

// Date class declaration.

 

 

 

public class Date

 

{

 

   private int month; // 1-12

 

   private int day;   // 1-31 based on month

 

   private int year;  // any year

 

 

 

   // constructor: call checkMonth to confirm proper value for month;

 

   // call checkDay to confirm proper value for day

 

   public Date( int theMonth, int theDay, int theYear )

 

   {

 

      month = checkMonth( theMonth ); // validate month

 

      year = theYear; // could validate year

 

      day = checkDay( theDay ); // validate day

 

 

 

      System.out.printf(

 

         “Date object constructor for date %sn”, this );

 

   } // end Date constructor

 

 

 

   // utility method to confirm proper month value

 

   private int checkMonth( int testMonth )

 

   {

 

      if ( testMonth > 0 && testMonth <= 12 ) // validate month

 

         return testMonth;

 

      else // month is invalid

 

      {

 

         System.out.printf(

 

            “Invalid month (%d) set to 1.”, testMonth );

 

         return 1; // maintain object in consistent state

 

      } // end else

 

   } // end method checkMonth

 

 

 

   // utility method to confirm proper day value based on month and year

 

   private int checkDay( int testDay )

 

   {

 

      int daysPerMonth[] =

 

         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

 

  

 

      // check if day in range for month

 

      if ( testDay > 0 && testDay <= daysPerMonth[ month ] )

 

         return testDay;

 

  

 

      // check for leap year

 

      if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||

 

           ( year % 4 == 0 && year % 100 != 0 ) ) )

 

         return testDay;

 

  

 

      System.out.printf( “Invalid day (%d) set to 1.”, testDay );

 

      return 1;  // maintain object in consistent state

 

   } // end method checkDay

 

  

 

   // return a String of the form month/day/year

 

   public String toString()

 

   {

 

      return String.format( “%d/%d/%d”, month, day, year );

 

   } // end method toString

 

} // end class Date

 

 

 

 

 

/**************************************************************************

 

 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *

 

 * Pearson Education, Inc. All Rights Reserved.                           *

 

 *                                                                        *

 

 * DISCLAIMER: The authors and publisher of this book have used their     *

 

 * best efforts in preparing the book. These efforts include the          *

 

 * development, research, and testing of the theories and programs        *

 

 * to determine their effectiveness. The authors and publisher make       *

 

 * no warranty of any kind, expressed or implied, with regard to these    *

 

 * programs or to the documentation contained in these books. The authors *

 

 * and publisher shall not be liable in any event for incidental or       *

 

 * consequential damages in connection with, or arising out of, the       *

 

 * furnishing, performance, or use of these programs.                     *

 

 *************************************************************************/

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. Develop a Java application that plays a “guess the number” game as described below.

     

    1. The user interface is displayed and the user clicks the “Start Game” button to begin the game.

       

    2. Your application then gets a random number in the range 1-1000 inclusive (you might want to use Math.random or the Random class). 

       

    3. The application then displays the following prompt (probably via a JLabel):

       

      I have a number between 1 and 1000 can you guess my number?

      Please enter a number for your first guess and then hit Enter.

       

      Post a textbox for the user to enter a number and post a message telling the user to hit ‘Enter’ after entering a guess in a textbox (probably using a JTextField). 

       

    4. Input the user’s guess in the code for a previously-registered event-handler method (consider using the event-handling approach discussed in the text, or the actionPerformed method of class based on the ActionListener interface, which will require some additional research outside the text).

       

    5. For the first guess color the entire background red, meaning that they are getting warmer (you might want to use the setBackground method for a container).  If this is the second or later guess, and they are further from the correct number than the last guess, then color the entire background blue.  If they get the correct number then color the background some other color than red or blue.

       

    6. If the user guessed the number correctly, respond with their number, post a congratulatory message, get a new random number, and display a JButton to start a new game.  Otherwise, to help the user close in on the correct number, post a message, with their guessed number, whether they are “TOO HIGH” or “TOO LOW” from the correct number, and whether they are “WARMER” or “COLDER” (this should match the background color).  Also report the guess number of the next guess (e.g. “Enter guess number nnn”). You might want to use a concatenated string in JLabel for these incorrect guess messages. 

       

    7. The process is repeated each game until the user guesses the correct number.  Be sure that you erase obsolete status messages.

       

      You must run your program for a scenario where the number is not guessed correctly for at least 4 (four) tries (it can be more).  A game where you guess the correct number on the fourth try is acceptable.  You must show all user inputs and program outputs for this scenario, not just a sample.

       

      Your submitted output must include the appropriate red or blue background after each guess. 

       

      You must include at least one “warmer” and one “cooler” result. 

       

      To help you visualize what is required for this program please review the sample output from the last step in these specifications below.

       

      (This program was taken from Exercise 11.15 on page 592 of Deitel & Deitel’s “Java How to Program (Sixth Edition)” (2005 by Pearson Publishing Co.).  It is not necessary to obtain this book to write this program!  This citation is only being listed to give proper credit to the author.)

       

  2. You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

     

  3. You are to submit the following deliverables to the Assignment Link in a single Microsoft Word file:

     

    1. A screen snapshot of your Java source code (just the beginning is OK) as it appears in your IDE (e.g. Net Beans, Eclipse, etc.) or editor (e.g. a Windows Command Prompt DOS “more” of the .java file’s first screen).

       

    2. A listing of your entire Java source code in the same Microsoft Word file as item a), and following item a).  You can simply copy and paste the text from your IDE into Word.  Be sure to maintain proper code alignment by using Courier font for this item.

       

    3. A screen snapshot of your program’s execution output in the same Microsoft Word file, and following item b). You must show all user inputs and all program output responses for the complete scenario, not just a sample.  Failure to show all inputs and outputs will result in lost points.

       

  4. Your instructor may compile and run your program to verify that it compiles and executes properly.

     

  5. You will be evaluated on (in order of importance):

    1. Inclusion of all deliverables in Step #3.

    2. Correct execution of your program.  This includes meeting all of the requirements in Step #1, including screen snapshots of all user inputs and all program outputs.

    3. Adequate commenting of your code.

    4. Good programming style (as specified in the textbook’s examples).

    5. Neatness in packaging and labeling of your deliverables.

       

      Deficiencies in any of the above areas are subject to up to a 2 (two) point deduction, per area, based on the severity of the deficiency.

       

  6. Programs received after the due date/time will receive a score of zero since there are already 15 extra points built into the grading for this class.

     

  7. Here’s an example of what the output from your application might look like:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Duepapers
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.