JDEP 183H

Fall 2006

 

Homework Assignment 1:  To Profit or Not To Profit

 

Assigned:  September 5, 2006

Due:  September 19, 2006

 

Note: This assignment is to be completed individually - collaboration is strictly prohibited.

Points100 points

 

Objectives

 

The objectives of this homework assignment:

  1. Understand the concept of object-oriented programming.
  2. Understand the concepts of “basic” class and “application/tester” class.
  3. How one class uses another class elegantly!
  4. Understand the concepts of object instantiation.
  5. Become familiar with the concept behind “get” and “set” methods.
  6. Become familiar with reading from standard in and writing to standard out.
  7. Become familiar with code documentation, compilation, and execution.
  8. Gain exposure to Java syntax, programming styles, and Java classes.

 

Problem Description

 

Text Box: Memo To: Chief programmer
Memo From: Your boss

Given the variable cost, fixed cost, capacity, production quantity, & price of a particular product, what is the profit?  

If the variable cost & fixed cost are given, what is the profit if there is no production, OR if there is full-capacity production, given that the price is 10% higher or 10% lower?

We want to be able to input the numbers.  Then the system prints the profit info. to the screen.

Have a nice day! 8P


The industry consulting firm ABC specializes in advising customers on profit and production decisions.  ABC has decided to build a computer system that it will use to help its consultants so they can give sound advice based on correct calculations.  However, ABC does not yet know exactly how the system should look.  One thing that ABC requires is that the system must be designed using the object-oriented programming approach as the system will definitely be extended and developed by different programmers as it evolves in the future. 

 

ABC has sent a memo to its chief programmer on a set of basic things ABC want the system should be able to do.  (See memo on the right.)

 

And, guess what?  You are the chief programmer for ABC!! Now, you know that the first thing to do is to come up with the objects that you need to consider for this problem:

There should be a Product class.  There should be an “application” class ProfitAdvisor that uses the Product class.  

 

To define the Product class, you need to define its attributes (i.e., variables) and behavior (i.e., methods).  In this case, the attributes that are of concern are variable cost, fixed cost, capacity, production quantity, price, and profit.  The behavior should include methods such as computeProfit(),computeProfitNoProduction(), and computeProfitFullProduction(), computeProfitNoProductionHigher(), computeProfitNoProductionLower(), computeProfitFullProductionHigher(), computeProfitFullProductionLower(), and so on.

 

To define the ProfitAdvisor class, it is basically a text-based interactive application that creates and makes use of Product instances.  This ProfitAdvisor class must have a “main” method.  This is very important.  It allows the user to run the program.  That is why we call a class like ProfitAdvisor an “application” class since it can be run as an application.  If you design your ProfitAdvisor class well, it does not have to have any methods of its own at all (other than some basic I/O processing methods).  (Hint: Think about what your ProfitAdvisor can ask a Product instance to do!)

 

A sample run of the program is shown below.  (Note: Bold texts are user input.)

 

Sample Output (ABC’s Profit Advising System)

Welcome to ABC’s Profit Advising System (PAS): 

 

Please enter the following for your product:

   Unit Variable Cost:  100.00

   Fixed Cost:  5000.00

   Capacity:  400

   Production Quantity:  300

   Unit Price: 250.00

   The profit of producing 300 units at $250.00/unit is $40,000

Additional information: 

   The profit of no production is -$5,000

   The profit of full-capacity production is $55,000

More information:

   (a) At +10% of unit price:

   The profit of producing 300 units at $275.00/unit is $47,500

   The profit of no production is -$5,000

   The profit of full-capacity production is $65,000

   (b) At -10% of unit price:

   The profit of producing 300 units at $225.00/unit is $32,500

   The profit of no production is -$5,000

   The profit of full-capacity production is $45,000

Thank you for using PAS.

 

 

To compute the profit value,

where P is the unit price, VC is the unit variable cost, FC is the fixed cost, and Q is the production quantity.   To compute for the profit of no production, Q = 0.  To compute for the profit of full-capacity production, Q = C, where C is the capacity. 

 

To compute the profit at 10% increase (or decrease) of the unit price, basically, the new price P is 1.10 (or 0.90) the old price. 

 

Supplied Solution Components

 

You can download a method for reading an integer from standard input from the course web page (HW1Supplement).  On its own, this document does not compile.  You must incorporate this method into your ProfitAdvisor class. You need a method to read an integer and another to read a real number for your implementation of the ProfitAdvisor class. 

 

Note that import java.io.* is required in ProfitAdvisor.java (and probably Product.java too) since these programs involve reading from and printing to the screen (i.e., standard in and standard out).  

 

Challenge - Extra Credit (10 points)

 

Modify your program to add a feature that allows a user to supply his/her input through an external text file.  So, instead of typing each input after each prompt as shown above, the user has the option to also enter the name of a text file.  Your ProfitAdvisor class will then read from this text file and carry out the same operations to display the information on profits accordingly. 

 

Submission Procedure

 

This assignment is due on September 19th, 2005 at the start of class (12:30 PM).  Assignments five minutes late will NOT be accepted.  It is highly recommended that you read the grading policy and grading guidelines on the course website for a complete explanation of how the assignments will be graded. Remember, your program should follow a good programming style, include plenty of comments – both inline documentation and Javadoc documentation, and perform all of the functionality outlined above. Also, in the welcome message of your program, state whether you are implementing the extra credit functionality. 

 

There are two submission steps:

 

(1)    You must “handin” the following files on-line:

1.      Source files: Product.java ProfitAdvisor.java

2.   Compiled files: Product.class ProfitAdvisor.class

3.   Readme file:  README

4.   Testing file:  TEST (also, if you complete the extra credit, please submit your input text file as well)

 

(2)    You must submit a stapled paper copy of a coversheet, your source files, the README file, and the TEST file. 

 

Both of these steps must be done by the start of the class on the day the assignment is due.  Please download this coversheet from the instructor’s course website, under the Homework Assignments link.   This coversheet allows the grader to give comments and categorize the points for your homework.

 

Additional Information

 

The README file should contain information about all the files that you hand in.  List the files, and describe each file in terms of whether the file is a program or a text file, the objective of each file, and so on.  The README file is also part of the files that you hand in too!  Further, the README file should contain information about how to compile your programs and how to run your programs.  It should also contain information about your testing results.

 

In the future, as your program becomes more complicated, you will also have to include the hierarchy of the files, the call-links of the files, and so on.

 

For testing, capture the screen output for your various tests.  Show the interactions that display the testing of the two components.  Show the interactions that demonstrate the robustness of your program (for example, by inputting an invalid response).  If you turn in the extra credit portion, also show the interactions that demonstrate that your program accomplishes the additional features.  Basically, the testing should show that you are confident that your program works convincingly.

 

If you do not know how to capture the screen output, please go to the Student Resource Center at Room 19, Avery Hall and ask for help.  (It is straightforward.)