...

View Full Version : Javascript function project



sdness
06-20-2007, 08: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

_Aerospace_Eng_
06-20-2007, 08:26 AM
So wait you are doing your friend's assignment for him but yet you don't know how to however you said he didn't have the brain to begin with? Ironic don't you think?

Sorry for sounding rude but you shouldn't be doing someone else's homework for them. And we aren't going to do it for them either.

Read the forum rules: http://www.codingforums.com/rules.htm
Mainly #1.5

sdness
06-20-2007, 08:45 AM
You didn't read my post.



So wait you are doing your friend's assignment for him but yet you don't know how to however you said he didn't have the brain to begin with? Ironic don't you think?
That's not irony. Like I originally wrote, I've been helping my friend all summer with his work. This assignment is giving me trouble because I'm quite rusty with my programming. I'm not going to get into the debate about "rudeness" haha, but I don't think it's fair to play the "brain" card above just because I'm asking for help. I've already admitted that I'm rusty.


Sorry for sounding rude but you shouldn't be doing someone else's homework for them. And we aren't going to do it for them either.

Read the forum rules: http://www.codingforums.com/rules.htm
Mainly #1.5
Yeah, I read those. Most programming forums have that rule. I'm not breaking it either. It reads: "Do not post your entire homework assignment and request that other members do it for you. This is considered cheating, and your thread may even be used by your school to prove your guilt. Now, you may ask for advice or help on a specific aspect of your assignment that you're having trouble with. Use common sense as far as what's acceptable in terms of soliciting help with homework assignments."

That's all I've done -- ask for advice.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum