Results 1 to 12 of 12
- 05-25-2008, 09:46 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
5 Class Project- Last one before Summer!
EDIT: It seems the code the teacher setup for us has "todo" comments for what we need to do... help?
Ok maybe im getting a little restless and cant wait to finish this because I finally get to do a little resting in the summer (besides taking one class) but I hope I can receive the same great help I've received in the past (thanks hardw1red!)
We're doing a project which involves having 5 classes this time. So you understand what it is im doing exactly, its probably best I post the instructions we were given so we stay on the same page:
First our objectives (so you know which concepts we are trying to apply):
II. Objectives
1. To learn how to use Conditional Statements, Loops, Flowcharts
2. To learn how to use Static variables and methods (chp.6)
3. To learn how to use the string Object and StringTokenizer
4. To learn how to use UML to create Class and Sequence diagrams (JUDE)
5. To learn how to use Object composition to create complex objects (chp.6)
6. To learn how to use JOptionPane and Arrays to create a menu (See example)
7. To learn how to use a Validator class (chp.6)
Now the assignment (which I will post what is setup for us so far afterwards):
1. You are to use the solution for Project 2 and create a program with 5 classes. A
Controller class, a Validator class to validate data, a PhotoCenter class to hold
the Business logic, a class to hold the Customer object definition, and a class to
hold the Film object definition.
2. This project will use Object composition to create a class that uses the Customer
and Film objects
3. Follow the same guidelines we used in Project2 to name your package, .Jar and
Java files. Precede the package name with the same (xxx) initials you used for
your project. For example if your project is jsmProject3 your package can be
jsmphotoprocessing (basically jsmpackagename).
4. Use JOptionPane to enter the order information separated by spaces, enter the
following: (see the data input examples provided in this handout)
a. First Name
b. Last Name
c. Phone Number
d. Number of Rolls
e. Number of Prints
5. Select the type of film from the menu window
6. Then you are to test the program using the values provided in the handout
7. Display on a JOptionPane window the summary of the order
8. Keep processing orders until the user decides to stop
9. Display a summary of all orders processed (see examples)
10. Validation rules:
a. The name of the customer is not blank
b. The phone number of the customer is not blank and doesn’t exceed 10
characters and is an integer with positive number only
c. The number of rolls is between 1 and 100 and is an positive integer
d. The number of prints can only be (1,2,8,10, 25,30,50), positive integer
11. Below is the pseudo-code of what the program should do
a. The film object holds information about the film
b. The customer object holds information about the customer
c. The business logic class handles all the calculations
d. The validator class handles all the validation
e. The controller class handles input by the use and output back to the user as
well as controlling all the other classes
f. In the controller class start by asking the user to enter data in one line
separated by spaces
g. Parse the data entered by using StringTokenizer and break it into variables
h. Validate each variable using the Validator class
i. After all variables have been validated prompt the user to select a film
type
j. Retrieve the film type selected by the user from the menu and store it in
variables
k. Use all the customer data provided by the user to create a Customer
object
l. Use the data selected by the customer from the film menu to create a Film
object
m. Use the Film object and the Customer object to create a PhotoCenter
(BusinessLogic) object
n. Ask the PhotoCenter class to process the order
o. The PhotoCenter determines what price to use by looking at the film type
and the Number of exposures the user selected and comparing them with
the PricingSheet array
p. The PhotoCenter class to return a summary for the order
q. Ask the user if they want to enter another order
r. If the user doesn’t want to enter another order then display a summary of
all orders that were processed
3. Extra Credit (10 points)
i. Save the total order summary to a file named OrdersSummary.txt (6 points)
j. Find the last name of APU, you will need this to process his order. (4 points)
Also if it helps, our instructor has given us pictures of what the pop ups should look like. Please let me know if those are necessary to help understand what Im trying to do.
To keep this neat I'll post the classes in the next post.Last edited by Bascotie; 05-26-2008 at 12:41 AM. Reason: Neater
- 05-25-2008, 09:52 PM #2
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Now for the classes:
There are 5 classes Customer, Film, PhotoCenter, PhotoCenterController, and Validator:
Heres what we have:
Customer:
Film:Java Code:public class Customer { //Create local properties //to hold the customer information private String firstName; private String lastName; private String phone; private int nbrRolls; private int nbrPrints; public Customer(String aFirstName, String aLastName,String aPhone, int aNbrRolls, int aNbrPrints){ } public int getNbrRolls(){ } public int getNbrPrints(){ } public String toString(){ String result = ""; result += "Customer First Name: " + this.firstName + "\n"; result += "Customer Last Name: " + this.lastName + "\n"; result += "Customer Phone: " + this.phone; return result; } }
PhotoCenter:Java Code:public class Film { //Create local properties //to hold the Film information private String filmType; private int nbrExposures; //constructor public Film(String aFilmType, int aNbrExposures){ } //getters public String getFilmType(){ } public int getNbrExposures(){ } //return object info as a string public String toString(){ String result = ""; result += "Film Type: " + this.filmType + "\n"; result += "Film Exposures: " + this.nbrExposures; return result; } }
PhotoCenterController:Java Code:import java.text.NumberFormat; import java.util.StringTokenizer; public class PhotoCenter { //Create our object variables (attributes) //variables to hold the user input //these are instance variables private Customer owner; private Film film; //totals these are static variables //in other words CLASS variables private static int totalRollsProcessed =0; private static int totalPrintsProcessed=0; private static double totalSales=0; private static int orderId = 0; //This follows the following format //Film Type //Exposures //Development Cost per Roll //Printing Cost per exposure //this is a CLASS variable //==todo== put the rest of the pricing sheet elements private static String[] pricingSheet ={"APS 24 5 0.10"}; //variables to hold the cost of //each process //these are instance variables private double developCost; private double printCost; //variables to hold the results //of the calculations //these are instance variables private double subtotal; private double tax; private double total; //variables to hold the development rate //and the print rate we are getting from //the price sheet //these used to be Constants in project1 //now they are instance variables private double devRate; private double printRate; //Create constants for //items that are fixed and are not //going to change //this is a constant CLASS variable private final static double TAX_RATE = 0.08; //This is the overloaded constructor //it's similar to the default //constructor but holds variables //that are passed from the controller class public PhotoCenter(Customer anOwner, Film aFilm){ //initialize our local object variables //with the variables passed by the user //==todo==initialize the owner //==todo===initialize the film //These variables are initilized //because their values are not set //until the calculations are executed developCost = 0; printCost = 0; subtotal = 0; tax = 0; total =0; //increment our order counter } //Create methods to do //each calculation separately //this way we can follow the //flow of execution //these methods are private and are //only accessible to the object itself //the controller class cannot execute them private void calcDevCost(){ //==todo==increment number of rolls processed //==todo==calculate development cost here } private void calcPrintCost(){ //==todo==increment number of prints processed //==todo==calculate printing cost here } private void calcSubtotal(){ //==todo==calculate subtotal here } private void calcTax(){ //==todo==calculate tax cost here } private void calcTotal(){ //==todo==calculate total cost here //==todo==increment total sales here } //this method finds the correct //pricing for the item selected //by the user. We loop through the //pricingSheet array and compare the value //stored in the array with the one provided //by the customer. private void findPricing(){ //==todo== //you need a for loop //a tokenizer //an if statement //then assign the costs to each variable } //create a public method //to have the object process the order //this method is accessible //from the controller class //The order is processed by //executing the calculations //one at a time public void processOrder(){ findPricing(); calcDevCost(); //calculate the dev. cost calcPrintCost(); //calculate the print cost calcSubtotal(); //calculate the subtotal calcTax(); //calculate the tax calcTotal(); //calculate the total } //this public method is used to return //a summary of this order this method //is accessible from the controller class //we use the currency format to format //the results and display them as currency public String getReceipt(){ NumberFormat cf = NumberFormat.getCurrencyInstance(); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String summary = ""; summary = "Welcome to PhotoCenter\n\n"; //==todo== you need to add to this summary return summary; } //this public method is used to return //a summary of all the sales made int the store //it is a static CLASS method public static String salesSummary(){ //our number formatting NumberFormat nf = NumberFormat.getCurrencyInstance(); String result = ""; result += "+++=================================+++\n"; result += "+++ Sales Summary +++\n"; result += "+++=================================+++\n\n"; //==todo== //you need to add to this summary return result; } }
Validator:Java Code:import javax.swing.JOptionPane; import java.util.StringTokenizer; public class PhotoCenterController { public static void main(String[] args) { do{ //collect the data entered by the user in //variables //==todo== //use a validator class for to collec the input //==todo== //create a customer object //ClassName objectVariable = new ClassName(parameters) //prompt the user to select a FILM String[] choices = {"APS 24", "APS 28", "35mm 12", "35mm 26", "35mm 30"}; int response = JOptionPane.showOptionDialog( null // center over parent , "Select a Film type and Number of Exposures" // message , "Camera Film Selection" // title in titlebar , JOptionPane.YES_NO_OPTION // Option type , JOptionPane.PLAIN_MESSAGE // messageType , null // icon , choices // Options , "APS 24" // initial value ); //==todo== //create a film object using the user selection //ClassName objectVariable = new ClassName(parameters) //==topdo== //create a new PhotoCenter object //and pass the data to the object (CUSTOMER AND FILM) //by passing the variables //in the constructor //ClassName objectVariable = new ClassName(parameters) //==todo== //tell the PhotoCenter object to process the order //by executing the processOrder public method //tell the object to return a receipt //by executing the getReceipt public method //Display the receipt in a JOptionPane window //JOptionPane.showMessageDialog(null,object.getReceipt()); }while (JOptionPane.showConfirmDialog(null, "Enter More Customers?") == JOptionPane.YES_OPTION); JOptionPane.showMessageDialog(null,PhotoCenter.salesSummary()); } }
I guess if I had a starting question it would be as to why I am getting an error in the CUSTOMER class code next to public int getNbrRollsJava Code://create the validator class for this project public class Validator { }
It says it must return a value of type int. I tried typing return getNbrRolls; within braces but that creates a new problem?
Again I really appreciate any help guys, I know im getting a little impatient wanting to just finally get this over with but bear with me please!
- 05-26-2008, 12:13 AM #3
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
I guess I should say my real problem here is figuring out which section of code goes where, such as in the beginning of the instructions it asks that we use the JOptionPane to get customer input, now I know the code to use (as ive used in the previous project) but I dont know which class it would go in..?
- 05-26-2008, 03:29 AM #4
I guess if I had a starting question it would be as to why I am getting an error in the CUSTOMER class code next to public int getNbrRolls
I guess I should say my real problem here is figuring out which section of code goes where, such as in the beginning of the instructions it asks that we use the JOptionPane to get customer input, now I know the code to use (as ive used in the previous project) but I dont know which class it would go in..?Java Code:/** * This method must return an [i]int[/i] primitive data type. */ public int getNbrRolls(){ // To get this to compile before you complete // the implementation, ie, the code that will // eventually go between the curley braces // (method body) just return an [i]int[/i] value: return 0; }
This is outlined for you in the main method in the PhotoCenterController class. The first comment in the do while loop is where you use your previously–developed code that gets the user–input. The next comment/section is where you create the code for validation using your new Validator class.
So you start at the top and slowly work your way down, developing whatever is needed in each class as you go.
- 05-26-2008, 05:10 AM #5
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Thanks hardwired, I guess I was trying to rush through this and get it over with so I ignored some things but when I went over it I was able to fill in some of the blanks, Ill work on it some more and update the code and ask questions along the way, thanks!
- 05-26-2008, 06:52 PM #6
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Yeah for my first question I put return nbrRolls; and that worked.
As for the PhotoCenterController class, I started coding the JOptionPane input but why is it that I have to declare the variables again, we have another class that declares them, is there a way to call them from there? (or would that be the point of having more than one class anyway?)
- 05-27-2008, 05:27 AM #7
As for the PhotoCenterController class, I started coding the JOptionPane input but why is it that I have to declare the variables again, we have another class that declares them, is there a way to call them from there?
Java Code:do{ //collect the data entered by the user in //variables //==todo== //use a validator class to validate the input //==todo== //create a customer object Customer customer = new Customer(parameters); // Now this instance of Customer keeps the variables that // you collected from the user and validated. You can go // on to do other things; even to collect more data and // create another Customer instance during the next trip // through the enclosing do–while loop. The Customer // class keeps all the info for each customer so you can // do other things.
- 05-28-2008, 01:07 AM #8
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Thanks hardwired,
but do I still have to declare all the variables in the photocenterController class that are declared in the customer class already?
I've been reading through the chapter on creating classes/objects and just now im barely getting it, the way it was presented to me was a little confusing.
- 05-28-2008, 01:35 AM #9
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Ok before I finished filling out the PhotoCenterController class and showed it to you I wanted to make sure my Customer and Film classes look ok, please let me know, I'd very much appreciate feedback.
CUSTOMER CLASS:
FILM CLASS:Java Code:public class Customer { //Create local properties //to hold the customer information private String firstName; private String lastName; private String phone; private int nbrRolls; private int nbrPrints; public Customer(String aFirstName, String aLastName,String aPhone, int aNbrRolls, int aNbrPrints){ } public int getNbrRolls(){ return nbrRolls; } public int getNbrPrints(){ return nbrPrints; } public String toString(){ String result = ""; result += "Customer First Name: " + this.firstName + "\n"; result += "Customer Last Name: " + this.lastName + "\n"; result += "Customer Phone: " + this.phone; return result; } }
Java Code:public class Film { //Create local properties //to hold the Film information private String filmType; private int nbrExposures; //constructor public Film(String aFilmType, int aNbrExposures){ } //getters public String getFilmType(){ return filmType; } public int getNbrExposures(){ return nbrExposures; } //return object info as a string public String toString(){ String result = ""; result += "Film Type: " + this.filmType + "\n"; result += "Film Exposures: " + this.nbrExposures; return result; } }
- 05-28-2008, 02:36 AM #10
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
hardwired,
if my customer and film class are ok, PLEASE take a look at my PhotoCenter class, I would like to make sure what I have "so far" is correct, but I am also stuck on the "findPricing" section:
PhotoCenter Class:
I dont understand how the findpricing code is suppose to work, and for it to work im sure my pricingSheet arrays need to be correct, and I hope they are?Java Code:/*********************************************************** * Class Name: PhotoCenter * Description: This class defines the PhotoCenter Object ************************************************************/ import java.text.NumberFormat; import java.util.StringTokenizer; public class PhotoCenter { //Create our object variables (attributes) //variables to hold the user input //these are instance variables private Customer owner; private Film film; //totals these are static variables //in other words CLASS variables private static int totalRollsProcessed = 0; private static int totalPrintsProcessed = 0; private static double totalSales = 0; private static int orderId = 0; //This follows the following format //Film Type //Exposures //Development Cost per Roll //Printing Cost per exposure //this is a CLASS variable //==todo== put the rest of the pricing sheet elements private static String[] pricingSheet ={"APS 24 5 0.10"}; private static String[] pricingSheet2 = {"APS 28 5 0.10"}; private static String[] pricingSheet3 = {"35mm 12 5 0.10"}; private static String[] pricingSheet4 = {"35mm 26 5 0.10"}; private static String[] pricingSheet5 = {"35mm 30 5 0.10"}; //variables to hold the cost of //each process //these are instance variables private double developCost; private double printCost; //variables to hold the results //of the calculations //these are instance variables private double subtotal; private double tax; private double total; //variables to hold the development rate //and the print rate we are getting from //the price sheet //these used to be Constants in project1 //now they are instance variables private double devRate; private double printRate; //Create constants for //items that are fixed and are not //going to change //this is a constant CLASS variable private final static double TAX_RATE = 0.08; private final static int USER_EXPOSURES = 1; //This is the overloaded constructor //it's similar to the default //constructor but holds variables //that are passed from the controller class public PhotoCenter(Customer anOwner, Film aFilm){ //initialize our local object variables //with the variables passed by the user //==todo==initialize the owner //==todo===initialize the film this.owner = anOwner; this.film = aFilm; //These variables are initialized //because their values are not set //until the calculations are executed developCost = 0; printCost = 0; subtotal = 0; tax = 0; total =0; //increment our order counter } //Create methods to do //each calculation separately //this way we can follow the //flow of execution //these methods are private and are //only accessible to the object itself //the controller class cannot execute them private void calcDevCost(){ //==todo==increment number of rolls processed ++totalRollsProcessed; //==todo==calculate development cost here developCost = devRate * totalRollsProcessed; } private void calcPrintCost(){ //==todo==increment number of prints processed ++totalPrintsProcessed; //==todo==calculate printing cost here printCost = totalPrintsProcessed * totalRollsProcessed * USER_EXPOSURES * printRate; } private void calcSubtotal(){ //==todo==calculate subtotal here subtotal = developCost + printCost; } private void calcTax(){ //==todo==calculate tax cost here tax = subtotal * TAX_RATE; } private void calcTotal(){ //==todo==calculate total cost here total = subtotal + tax; //==todo==increment total sales here ++totalSales; } //this method finds the correct //pricing for the item selected //by the user. We loop through the //pricingSheet array and compare the value //stored in the array with the one provided //by the customer. private void findPricing(){ //==todo== //you need a for loop //a tokenizer //an if statement //then assign the costs to each variable } //create a public method //to have the object process the order //this method is accessible //from the controller class //The order is processed by //executing the calculations //one at a time public void processOrder(){ findPricing(); calcDevCost(); //calculate the dev. cost calcPrintCost(); //calculate the print cost calcSubtotal(); //calculate the subtotal calcTax(); //calculate the tax calcTotal(); //calculate the total } //this public method is used to return //a summary of this order this method //is accessible from the controller class //we use the currency format to format //the results and display them as currency public String getReceipt(){ NumberFormat cf = NumberFormat.getCurrencyInstance(); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String summary = ""; summary = "Welcome to PhotoCenter\n\n"; //==todo== you need to add to this summary return summary; } //this public method is used to return //a summary of all the sales made int the store //it is a static CLASS method public static String salesSummary(){ //our number formatting NumberFormat nf = NumberFormat.getCurrencyInstance(); String result = ""; result += "+++=================================+++\n"; result += "+++ Sales Summary +++\n"; result += "+++=================================+++\n\n"; //==todo== //you need to add to this summary return result; } }
Thank you so much, its a big stress reliever to have some help with this
- 05-28-2008, 02:38 AM #11
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Just a note:
I made slight modifications to the pricingSheet arrays:
I updated it with the correct pricing information.Java Code:private static String[] pricingSheet ={"APS 24 5 0.10"}; private static String[] pricingSheet2 = {"APS 28 10 0.13"}; private static String[] pricingSheet3 = {"35mm 12 3 0.08"}; private static String[] pricingSheet4 = {"35mm 26 6 0.12"}; private static String[] pricingSheet5 = {"35mm 30 14 0.18"};
Also I think I was wrong to set USER_EXPOSURES as a final constant that is equal to 1 since exposures can be 24,28,12,26,30 as represented by the first element of each pricingsheet array (the number 1 element rather?)Last edited by Bascotie; 05-28-2008 at 02:40 AM.
- 05-30-2008, 03:08 AM #12
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping project
By Ed in forum JDBCReplies: 4Last Post: 05-13-2011, 10:04 PM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM -
Class Reflection: Finding class modifiers
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:11 PM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks