sdness
06-20-2007, 07:21 AM
So my friend is taking a computer science course at his college for summer school right now. To put it simply -- he's not too smart. I think he failed or got a D in the course during the fall semester. He's one of those kids who shouldn't be in a computer science course; just doesn't have the brain for it.
I've been helping him with his homeworks for the past couple of weeks. They've been really easy. Most of it was general knowledge about computers. I was helping him last night -- one of the assigments, like usual, was really easy. It was a homework sheet on viruses and security. The other assignment -- which is longterm -- is a little more complex because it's actual programming. At the time, he had no idea what to do. Haha. So I said I'd take the assignment and play around with it for a while.
Nonetheless, I determined a long time ago that computer programming was not one of my strengths in life. I'm very interested in the subject. I enjoyed taking Visual Basic, C++, and Java in high school, but I don't have the patience/mind for it.
So, if you can help me in any way with this project that'd be wonderful. Of course, I know you don't want to do this person's homework as that's not fair.
Let's say you go to a gourmet coffee store in a local supermarket and that you choose to create a coffee blend consisting of two types of coffee. Espresso and Sumatra. Espresso beans costs $5.99 per unit and Sumatra beans cost $8.99 per unit. Since you like having both flavors into a single unit, you decide that you want to mix the two blends together into a single unit consisting of certain percentages of the two cofefe types.
In this exercise, your job is to create a function that will calculate the price of the coffee blend. Assume that the percentages are stored as two variables in that function, as EspressoPercent and SumatraPercent, respectively.
The function you create is subject to the following conditions.
1. The percentages of both EspressoPercent and SumatraPercent must sum to 100. If not, warn the user with a window alert box that says "Your percentages must sum to 100."
2. If they sum to a 100, assume the following formula:
Finalprice = (Espresso * 5.99 + Sumatra * 8.99) / 100.
Display this final price in the "Find Price" textbox in the screen.
The goal of this assignment is to create a web page. I have to use a combination of both HTML and Java. The HTML part is naturally easy, but I'm quite rusy on my Java.
After a quick look, I know that for the first condition above I need to use an if-else statement.
Any hints, comments, or advice would be greatly appreciated. I've got some pseudo code below -- just a sketch of what to do.
in the main, something like:
float coffee_display = coffeeprice();
then in the function/method itself, i want to declare that as a float
float coffeeprice(void){
//declare values of unit espresso and the other
//declare percentage integers
//prompt user for percent of coffee desired in sumatra
if (pcnt_sum > 100){
prompt user again
}
else{
pcnt_esp = 100 - pcnt_sum
}
//next, i use use the equation
cost_per_unit_blend = ((pcnt_esp * cost_esp) / 100) + (pcnt_sumatra * cost_sumatra) / 100)
return cost_per_unit_blend;
}
make the percentages integers
make the costs floating points
I've been helping him with his homeworks for the past couple of weeks. They've been really easy. Most of it was general knowledge about computers. I was helping him last night -- one of the assigments, like usual, was really easy. It was a homework sheet on viruses and security. The other assignment -- which is longterm -- is a little more complex because it's actual programming. At the time, he had no idea what to do. Haha. So I said I'd take the assignment and play around with it for a while.
Nonetheless, I determined a long time ago that computer programming was not one of my strengths in life. I'm very interested in the subject. I enjoyed taking Visual Basic, C++, and Java in high school, but I don't have the patience/mind for it.
So, if you can help me in any way with this project that'd be wonderful. Of course, I know you don't want to do this person's homework as that's not fair.
Let's say you go to a gourmet coffee store in a local supermarket and that you choose to create a coffee blend consisting of two types of coffee. Espresso and Sumatra. Espresso beans costs $5.99 per unit and Sumatra beans cost $8.99 per unit. Since you like having both flavors into a single unit, you decide that you want to mix the two blends together into a single unit consisting of certain percentages of the two cofefe types.
In this exercise, your job is to create a function that will calculate the price of the coffee blend. Assume that the percentages are stored as two variables in that function, as EspressoPercent and SumatraPercent, respectively.
The function you create is subject to the following conditions.
1. The percentages of both EspressoPercent and SumatraPercent must sum to 100. If not, warn the user with a window alert box that says "Your percentages must sum to 100."
2. If they sum to a 100, assume the following formula:
Finalprice = (Espresso * 5.99 + Sumatra * 8.99) / 100.
Display this final price in the "Find Price" textbox in the screen.
The goal of this assignment is to create a web page. I have to use a combination of both HTML and Java. The HTML part is naturally easy, but I'm quite rusy on my Java.
After a quick look, I know that for the first condition above I need to use an if-else statement.
Any hints, comments, or advice would be greatly appreciated. I've got some pseudo code below -- just a sketch of what to do.
in the main, something like:
float coffee_display = coffeeprice();
then in the function/method itself, i want to declare that as a float
float coffeeprice(void){
//declare values of unit espresso and the other
//declare percentage integers
//prompt user for percent of coffee desired in sumatra
if (pcnt_sum > 100){
prompt user again
}
else{
pcnt_esp = 100 - pcnt_sum
}
//next, i use use the equation
cost_per_unit_blend = ((pcnt_esp * cost_esp) / 100) + (pcnt_sumatra * cost_sumatra) / 100)
return cost_per_unit_blend;
}
make the percentages integers
make the costs floating points