Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 64

Thread: Java Programming project

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Java Programming project

    Hi, I am new here. Java is my first programming class. How do you do the muffler program for Java project? I need more help on this.

    Project Requirements:
    1. Develop the beginnings of a simple invoicing program for a Muffler Shop. We will have a Muffler class representing an individual muffler ordered by a customer. We will also have a test class (driver program) for the Muffler class.
    2. Design and build a Muffler class. This will have three instance variables. There will be a customer variable that will hold the customers last name. We will have a priceCode variable that will identify the size and warranty class of the muffler. We will also have a cost variable that will hold the cost of the muffler given the pricing code. This class should have a constructor, accessors for the instance variables, a mutator for the customer, a method to compute the cost, a method to update the price code, and a method to convert the state of the object to a string. Using the UML, the class diagram looks like this:
    Muffler
    customer : String
    priceCode : String
    cost : double
    Muffler()
    Muffler(String, String)
    getCustomer() : String
    getPriceCode() : String
    getCost() : double
    setCustomer(String newCustomer)
    computeCost()
    updatePriceCode(String)
    toString(): String



    1. The default constructor will set the instance field to a default value.
    2. The parameterized constructor will assign the first parameter to the variable customer and the second to the priceCode variable. The constructor will call computeCost() to convert the price code to the numeric cost and store it in cost.
    3. The class will have three accessor methods getCustomer(), getPriceCode(), and getCost(). Each will return the value of the respective instance variable.
    4. The class will have an accessor method for customer.
    5. The method computeCost() handles the conversion of the price code to cost and saves it in the instance variable cost. Price codes consist of a size letter (A through F) and an optional warranty modifier. Base price of a muffler is $39.95 installed and as the size increases the cost changes according to the table below
    Size Code Price Factor
    A 1.00
    B 1.07
    C 1.15
    D 1.22
    E 1.38
    F 1.50
    6. The warranty modifier indicates that there is a either a three-year warranty (3) or a lifetime warranty (L). A three-year warranty adds $2.00 to the base price, while a lifetime warranty adds $5.00 to the base price. Note that the smallest muffler cannot have a lifetime warranty and the largest must have either a three-year or lifetime warranty. The cost should be rounded to the nearest penny. cost = (baseprice + warranty) * price factor.
    7. There will be 16 possible price codes: A, A3, B, B3, BL, C, C3, CL, D, D3, DL, E, E3, EL, F3, FL. Remember AL and F are invalid.
    8. Use the switch statement to determine the proper price factor. Use the if/else construction to handle the warranty modifiers.
    9. The class will have a method updatePriceCode(String) that takes a new price code and updates the priceCode and cost variables accordingly. Use the computeCost() method to update the cost. Note that we can call methods of a class from within the class; in this case, we do not use the dot (.) operator. Methods which are useful to other methods are called utility methods, and do not need to be public if they will only be called from within the class. The computeCost() method is a utility method.

    10. The method toString() allows us to access the state of the object in a printable or readable form. It converts the variables to a single string that is neatly formatted. Look at pages 152 and 153 of the text for a discussion of escape sequences. These are characters that you can insert into your strings and, when printed, will format the display neatly. You can insert an escape sequence for the tab character and get a tabular form when printing. This tab character is '\t'. Your class will have a toString() method that concatenates customer, priceCode, and cost separated by tab characters and returns this new string. When you try to print an object, the toString() method will be implicitly called. For example, if Jones bought a D3 muffler, the output would be:
    Jones D3 $51.18
    3. Build a class MufflerTest that will test the constructor and all the public methods and constructors of the class Muffler. This will run as an application. Generate objects that have each of the possible values for a price code and print each object by implicitly calling the toString() method on each object. Remember to test for invalid price codes. Invalid price codes should display an error message and set the cost to $9999.99. No user input, just create objects with the price code in the constructor call
    Muffler cust=new Muffler("David","C3");

    Implementation Notes:
    • You should use both the switch and the if/else constructions in this program. The switch construction is good when you are checking a single variable against a number of different discrete values. A character variable (char) is discrete (you have one of a set of characters only) as are integral types (int). Strings and floating-point numbers are not discrete and will not work with the switch statement. if statements can be used anytime you have a relational operation such as equality, less than, etc. But you need to be careful when using a long series of if {...} else {...} constructs because of the confusion factor (Which if does this else go with? Where am I in this sequence of tests?).
    • Strings have many behaviors available. These behaviors include finding an individual character in the string, telling how many characters are in the string and converting the contents of the string to either upper or lower case. You will need to use the charAt(int i) method to extract the size code and warranty modifier from the priceCode string to work with. For example, suppose you have a Java statement:
    String x = "This is a string.";
    You can extract the period at the end of the statement by using the Java statement:

    char period = x.charAt(16);
    This will extract the 17th character in the string and place it in the variable period. Remember that string numbering starts at 0, not 1. A better way to do this would be to use the method length(), which tells us how many characters are in the string. So we can use it to tell us where the period is since we know it is the last character (in this specific case) in the string. So the Java statement:
    int howLong = x.length();
    tells us the number of characters. But the numbering starts at zero if we want to access them, so we have to reduce howLong by 1 to get to the last character. Then we could do:
    char period = x.charAt(howLong - 1);
    to get the same result as in statement b above. Experienced programmers would probably simplify the construction slightly more by eliminating the variable howLong if this is the only use of it. We could then re-write it as:
    char period = x.charAt(x.length() - 1);
    Note how we are nesting method calls inside of other method calls. This can be a very powerful programming technique.
    Submission Requirements:
    Your project must be submitted using the instructions below. Any submissions that do not follow the stated requirements will not be graded.
    1. Follow the submission requirements of your instructor.
    2. You should have three files for this assignment:
    a. Muffler.java - The Muffler class,
    b. Muffler.html - The documentation file generated from your class (you do not have to turn this file in),
    c. MufflerTest.java - A driver program for your Muffler class.
    d. Self graded Grade Sheet (+ 5 pts)
    3. Remember to compile and run your program one last time before you submit it. If your program will not compile, the graders will not be responsible for trying to test it.



  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    yes, i have questions about switch. can you help me to do this? I have done this:
    public String getCustomer()
    {
    return customer;
    }//end getCustomer

    public String getPriceCode()
    {
    return priceCode;
    }//end getPriceCode

    public double getCost()
    {
    return cost;
    }//end getCost

    public String setCustomer(String newCustomer)
    {
    return customer;
    }//end setCustomer

    public void computeCost()
    {
    <YOUR CODE HERE>
    }//end computeCost

    public String updatePriceCode(String PriceCode)
    {
    return priceCode;
    }//end updatePriceCode

    public String toString()
    {
    return " ";
    }//end

    }//end class Muffler

    <YOUR CODE HERE>


    my teacher said I need more codes but I don't know what I need to write code

    --- Update ---

    [/COLOR]This is due tomorrow at 11:59

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Do you have any specific questions about the code and your problems?

    i have questions about switch
    See the tutorial: The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    hey, so will you help me?

    public String getCustomer()
    {
    return customer;
    }//end getCustomer

    public String getPriceCode()
    {
    return priceCode;
    }//end getPriceCode

    public double getCost()
    {
    return cost;
    }//end getCost

    public String setCustomer(String newCustomer)
    {
    return customer;
    }//end setCustomer

    public void computeCost()
    {

    <YOUR CODE HERE>

    }//end computeCost

    public String updatePriceCode(String PriceCode)
    {
    return priceCode;
    }//end updatePriceCode

    public String toString()
    {
    return " ";
    }//end

    }//end class Muffler

    <YOUR CODE HERE>



    my teacher said I need more codes but I don't know what I need to write code

    --- Update ---

    This is due tomorrow at 11:59

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    I'm waiting for your questions and the code you are having problems with.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    like what?

    --- Update ---

    I'm confused about what to do next.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Strange question. I thought you were here for help with an assignment. What code have you written?
    Does the code do what you want? If not please explain and ask some specific questions about your problems.


    what to do next.
    Make a list of the steps the code needs to do and start working on them one at a time.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    Look at number 5-10:
    5. The method computeCost() handles the conversion of the price code to cost and saves it in the instance variable cost. Price codes consist of a size letter (A through F) and an optional warranty modifier. Base price of a muffler is $39.95 installed and as the size increases the cost changes according to the table below
    Size Code Price Factor
    A 1.00
    B 1.07
    C 1.15
    D 1.22
    E 1.38
    F 1.50
    6. The warranty modifier indicates that there is a either a three-year warranty (3) or a lifetime warranty (L). A three-year warranty adds $2.00 to the base price, while a lifetime warranty adds $5.00 to the base price. Note that the smallest muffler cannot have a lifetime warranty and the largest must have either a three-year or lifetime warranty. The cost should be rounded to the nearest penny. cost = (baseprice + warranty) * price factor.
    7. There will be 16 possible price codes: A, A3, B, B3, BL, C, C3, CL, D, D3, DL, E, E3, EL, F3, FL. Remember AL and F are invalid.
    8. Use the switch statement to determine the proper price factor. Use the if/else construction to handle the warranty modifiers.
    9. The class will have a method updatePriceCode(String) that takes a new price code and updates the priceCode and cost variables accordingly. Use the computeCost() method to update the cost. Note that we can call methods of a class from within the class; in this case, we do not use the dot (.) operator. Methods which are useful to other methods are called utility methods, and do not need to be public if they will only be called from within the class. The computeCost() method is a utility method.

    10. The method toString() allows us to access the state of the object in a printable or readable form. It converts the variables to a single string that is neatly formatted. Look at pages 152 and 153 of the text for a discussion of escape sequences. These are characters that you can insert into your strings and, when printed, will format the display neatly. You can insert an escape sequence for the tab character and get a tabular form when printing. This tab character is '\t'. Your class will have a toString() method that concatenates customer, priceCode, and cost separated by tab characters and returns this new string. When you try to print an object, the toString() method will be implicitly called. For example, if Jones bought a D3 muffler, the output would be: Jones D3 $51.18.


    I don't know what this instruction want me to do. Can you give a hints about this?
    Angel

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Don't try to do it all at once. Do it in small steps. Design the code for a step, write the code, compile the code, fix the problems and test it when it compiles without errors. When the test is successful, move to the next step.
    Step 5 describes what the method computeCost() is supposed to do. It converts a price code to a $ cost given some rules.

    I'm done for tonight, Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    Like this : double priceCost = 39.95;
    switch(customer)
    {
    case (A): cost = movieCost* 1.50;
    break;
    case (B): cost = movieCost*1.36;
    break;
    case (C): cost = movieCost*1.26;
    break;
    case (D): cost = movieCost*1.06;
    break;
    case (F): cost = movieCost*1.00;
    break;

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    That's not the definition of a method. That would be part of the code that would be used in the method.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    Can you tell me the definition of a method?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    Oh I have a method. Now, I'm at the church. My method is
    public void computeCost();
    {
    ......
    .....
    .....
    Return cost;
    {//end computeCost

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    When you get to a computer, type in the code and compile it to see what the compiler thinks of it.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    I did. My compiler says this code is right that means my compiler say no error.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Ok, now add some code to the method to start computing the cost. Do it a simple step at a time.
    Call the method with a price code String and print out the value of cost that it computes.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    Like I just write my code to you : double priceCost = 39.95;
    switch(customer)
    {
    case (A): cost = movieCost* 1.50;
    break;
    case (B): cost = movieCost*1.36;
    break;
    case (C): cost = movieCost*1.26;
    break;
    case (D): cost = movieCost*1.06;
    break;
    case (F): cost = movieCost*1.00;
    break;

    --- Update ---

    I mean priceCode. Ignore movieCost

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Make a complete class that will compile and execute, not just pieces of code.

    I mean priceCode. Ignore movieCost
    What does that mean? It looks like a copy and paste was done with no editing. A waste of time to copy code from post#11 and post it again in post#19
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    That is my code with examples that I just wrote. I left more code so I can't remember what I wrotein jgrasp. I have to wait until my church finish.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Programming project

    Don't post code before the compiler has seen it.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    ok, i'm back home

    --- Update ---

    i have problem with brackets: {. I have tried to compile it but it show one error: reached end of file while parsing
    {
    ^

  24. #24
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Java Programming project

    This is where using careful and consistent formatting will help you debug your code. If you haven't done so, you will want to do it now -- make sure to indent all blocks 3 or 4 spaces and check that all opening braces are matched by appropriately placed closing braces. There's no rocket science to this but rather it is basic grunt work that you should be able to do without our help.

    If you still have problems after doing this, then show us your well formatted code, with code tags, and any problems or errors the code is generating.

  25. #25
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming project

    public class Muffler
    {

    private String customer;
    private String priceCode;
    private double cost;

    public Muffler()
    {
    String customer = "Williams";
    String priceCode = "A" ;
    double cost = 39.95;

    }//end Muffler

    public Muffler(String inName, String inPriceCode)
    {
    this.customer = inName;
    this.priceCode = inPriceCode;
    computeCost();
    }//end Muffler

    public String getCustomer()
    {
    return customer;

    }//end getCustomer

    public String getPriceCode()
    {
    return priceCode;

    }//end getPriceCode

    public double getCost()
    {
    return cost;

    }//end getCost

    public String setCustomer(String newCustomer)
    {
    return customer;
    }//end setCustomer

    public void computeCost()
    {
    double priceCost = 39.95;
    switch(C)
    {
    case (A): cost = priceCost * 1.00;
    case (A3): cost = priceCost * 41.95;
    case (B): cost = priceCost * 1.07;
    case (B3): cost = priceCost * 44.89;
    case (BL): cost = priceCost * 48.10;
    case (C): cost = priceCost * 1.15;
    case (C3): cost = priceCost * 48.24;
    case (CL): cost = priceCost * 51.69;
    case (D): cost = priceCost * 1.22;
    case (D3): cost = priceCost * 51.18;
    case (DL): cost = priceCost * 54.84;
    case (E): cost = priceCost * 1.38;
    case (E3): cost = priceCost * 57.89;
    case (EL): cost = priceCost * 62.03;
    case (F3): cost = priceCost * 62.92;
    case (FL): cost = priceCost * 67.42;
    return cost;
    }//end computeCost

    --- Update ---

    public class Muffler
    {

    private String customer;
    private String priceCode;
    private double cost;

    public Muffler()
    {
    String customer = "Williams";
    String priceCode = "A" ;
    double cost = 39.95;

    }//end Muffler

    public Muffler(String inName, String inPriceCode)
    {
    this.customer = inName;
    this.priceCode = inPriceCode;
    computeCost();
    }//end Muffler

    public String getCustomer()
    {
    return customer;

    }//end getCustomer

    public String getPriceCode()
    {
    return priceCode;

    }//end getPriceCode

    public double getCost()
    {
    return cost;

    }//end getCost

    public String setCustomer(String newCustomer)
    {
    return customer;
    }//end setCustomer

    public void computeCost()
    {
    double priceCost = 39.95;
    switch(C)
    {
    case (A): cost = priceCost * 1.00;
    case (A3): cost = priceCost * 41.95;
    case (B): cost = priceCost * 1.07;
    case (B3): cost = priceCost * 44.89;
    case (BL): cost = priceCost * 48.10;
    case (C): cost = priceCost * 1.15;
    case (C3): cost = priceCost * 48.24;
    case (CL): cost = priceCost * 51.69;
    case (D): cost = priceCost * 1.22;
    case (D3): cost = priceCost * 51.18;
    case (DL): cost = priceCost * 54.84;
    case (E): cost = priceCost * 1.38;
    case (E3): cost = priceCost * 57.89;
    case (EL): cost = priceCost * 62.03;
    case (F3): cost = priceCost * 62.92;
    case (FL): cost = priceCost * 67.42;
    return cost;
    }//end computeCost


    I have problem compile with this bracklet // end computeCost and it show error

    --- Update ---

    hello?

Page 1 of 3 123 LastLast

Similar Threads

  1. android programming vs game programming using java
    By vgoel38 in forum Android Development
    Replies: 4
    Last Post: September 8th, 2012, 05:48 PM
  2. java programming 2 project
    By kin93 in forum Java Theory & Questions
    Replies: 6
    Last Post: June 16th, 2012, 12:00 AM
  3. Jukebox Programming project
    By joneslay_d in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2010, 02:48 PM
  4. Replies: 2
    Last Post: August 1st, 2010, 06:29 AM
  5. Programming partner that can earn revenue
    By Jay in forum Project Collaboration
    Replies: 0
    Last Post: May 25th, 2009, 02:33 PM