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.
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()
{
}//end computeCost
public String updatePriceCode(String PriceCode)
{
return priceCode;
}//end updatePriceCode
public String toString()
{
return " ";
}//end
}//end class Muffler
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
Re: Java Programming project
Do you have any specific questions about the code and your problems?
Quote:
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.
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
Re: Java Programming project
I'm waiting for your questions and the code you are having problems with.
Re: Java Programming project
like what?
--- Update ---
I'm confused about what to do next.
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.
Make a list of the steps the code needs to do and start working on them one at a time.
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
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.
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;
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.
Re: Java Programming project
Can you tell me the definition of a method?
Re: Java Programming project
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
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.
Re: Java Programming project
I did. My compiler says this code is right that means my compiler say no error.
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.
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
Re: Java Programming project
Make a complete class that will compile and execute, not just pieces of code.
Quote:
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
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.
Re: Java Programming project
Don't post code before the compiler has seen it.
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
{
^
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.
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?