For the love of god please help.

ShinRa

Companion Cube
Joined
Jun 23, 2003
Messages
5,044
Reaction score
84
Guys, I am so desparate right now its not even funny. I have to write an incredibly simple program, and if i dont, i fail out of the course. If i fail out of the course, I wont get into the college i wanted to. I am begging you, someone please, if anyone has java experience, can someone please write the code for me for this program?

This is what the sheet says:

Different packages of ground beef have different percentages of fat and different costs per pound. Write a program that asks the user for:

1. The price per pound of package "A"
2. The percent lean (non-fat) in package "A"
3. The price per pound of package "B"
4. The percent lean (non-fat) in package "B"

The program then calculates the cost per pound of lean (non-fat) beef for each package and writes which is the best value.

Example:

Price per pound package A: 2.89
Percent lean package A: 85
Price per pound package B: 3.49
Percent lean package B: 93

Package A cost per pound: 3.4
Package B cost per pound: 3.75
Package A is the best value.

Assume the two packages will not come out equal in value. Input must be verified. Currency must be verified as such.




And thats it. If anyone, ANYONE, with the littlest programming skill who knows what to do, please I beg of you to write the code for me. If not, I'm going to fail and not go to college, I'm really not kidding. Please help out a man in desparate need. All I need is the .java file with the code in it.

God bless anyone who helps me.
 
IF it was for C++, I could have helped. However, I don't know anything about Java. Sorry man.

-Angry Lawyer
 
:O

Geeze m8...

How about we give you help, you write the code and post it, and we'll look over it?

The first thing I would do if I were writing it would be to make a class representing a package of ground beef, probably starting something like this:
Make a BeefPackage class with the following variables:
String name;
double perPound;
double percentLean;
Then, a method, double getValue();

Do they want a GUI or can you use standard in/out?
 
Well, I took a few minutes and wrote up a working solution by doing basically what I said above. A much more elegant solution would've been to implement java.lang.Comparable. But if the link switch gave is indeed your assignment, can't you just do something like this?
Code:
public void getBetterValue(double priceA, double percentA, double priceB, double percentB) {
  if ((priceA/percentA) <= (priceB/percentB)) {
    System.out.println("A is the better value.");
  }else{
    System.out.println("B is the better value.");
  }
}
I wouldn't recommend it, but if that's all it's asking for...
 
thank you guys so much. and to the guy who asked, it doesnt have to be anything fancy, just basic in/out. i really dont know anything about java, and he didnt teach us jack shit. he said here's a program, write it. so i cant thank you guys enough. ill see if that code works when i get home.
 
btw psyno, thank u especially. i just tried to compile it with javac and it gave me a class error. idk what could be wrong.
 
Well, it's not a class, it's just a method. If you put it inside something like public class BeefCalculator{/*code*/} then it would compile, but you'd have to make the method static for it to be useful like that. As in:
Code:
public class BeefCalculator {
  public static void getBetterValue(double priceA, double percentA, double priceB, double percentB) {
    if ((priceA/percentA) <= (priceB/percentB)) {
      System.out.println("A is the better value.");
    }else{
      System.out.println("B is the better value.");
    }
  }
}
Then to use it you'd do something like BeefCalculator.getBetterValue(2.89, 85, 3.49, 93); and it would print out "A is the better value."

Problem is that we don't know how much you know, and we don't know how he wants the user to be able to interact with the program...
 
well the file psyno posted can't be the only file, i hope you know. You need an entry point, i.e. a 'main()' function.

Edit: BeefCalculator, hahaha. that sounds funny... :LOL:
 
ok. what he wants is just for the program to run. it could be in a dialog box, whatever, he doesnt care. and how much i know? absolutely nothing lol.
 
What kind of a class is this? Why would you be programming if you haven't ben instructed?

I'm sorry, I'm not going to write anything for you. I find it hard to believe that you would have a project like this without having been instructed in some basics. Even if your teacher is an idiot, he must have shown you something...

Try doing a web search on a java tutorial... This project is about a half a step past 'hello world'. You should be able to figure out the basics enough to do this in about an hour.

I'm sorry if you think I'm being a dick about this. I won't do someone elses homework (got enough of my own :p) and I encourage everyone else to do the same...

You learn through failiure. Do a search if you really know nothing, a 'hello world' tutorial should get you started. Fail a couple tries, come back, eh?
 
guinny said:
If i fail out of the course, I wont get into the college i wanted to.
Not trying to slam you. Really. Its just, if you need that much of a bosst - instead of just some help or pointers - you may find courses to be over your head at a college that can't accept your not getting this project.

It doesn't need to be the end of your life if you have to go to another college. Better to find out now, than after wasting a year floundering in the wrong school.

Old Man's Advice: Take the code. Pass the course, Search for a college that fits your skills/interests.
 
He taught us hello world. He didnt teach us how to actually write a program. i did hello world last week. i know that this project is only like 10 lines of code, i just dont know WHAT 10 lines of code, and id really appriciate it if someone who knew making a program like this one would be a breeze, if they could write up the code for me. :( pretty please?
 
btw the college i want to go to requires a year of adv. comp to be accepted. however, the major im going into is electrical engineering, which doesnt require c++ or java.
 
it does require programming, probably. I know EE majors at my college require either one or two courses concerning matlab, a mathematics simulation programming tool. some colleges require knowledge of maple. yeah it's more math then cs, but you still need to understand the basics...

besides, you can't go to college if you're not prepared to put some energy into things that aren't your major. no-one expects you to be an expert, but that's what 'generals' are for...

so, if you've done a hello world program, try modifying it. code in the math, if you're going into EE, you should at least be winning to take a shot at this.

basic form for simple math:

double varToMultiply, anotherVarToMultiply, varToAdd;
double varToAssignAValueTo = varToMultiply * anotherVarToMultiply + varToAdd; // etc etc.

stick em in a class and try it.

declare, assign, use. not too much to that bit...

everyone wants to help you (i hope i speak for everyone) but we don't want to do it for you, get it?

P.S. not to sound like a nagging mod, but use the edit :)
 
ok ok. ill do it myself. the thing is, is idk what goes first when coding. i know input, process, and output. but how do u know what code to put first/next/last etc etc? does it matter where in the notepad it is? :( i hate myself i suck at life i can never do hard shit like this :(
 
Call the drama police! Seriously you obviously know enough to realize it is a very simple program, so why not do a little guess and check? I'm sure you can get it with a little effort, especially if you have a text book helping you. I don't know java but basically all you need to do is get the input, do the math and show the output. Not that hard.
 
^ that's the basics. give it try and put up the code if it don't work. and truth be told who cares how it works if it works. unless your teacher grades on style, which almost never happens in very low level classes, then as long as it fullfills the requirements it'll do.

basics java form:

make a class. give it a constructor, data members, and methods (i.e. functions). everything in a class (at the lowest level at least) has to be private, public, or protected (ignore the last one).
In you particular case, you should just do it all within the 'main()' fuunction. just to make it easier.

you must declare a variable before you use it. for ex:
int myVariable;

now you have a variable name myVariable. now you can assign it a value:
myVariable = 5;

now you can use myVariable in a calculation:
int myNewVariable = myVariable * 4; // this line declares and assigns in one step.

if you don't know input, that's okay. do it later. someone here should be able to help you. simple input in java is kind of a bitch, at least the way i learned it.

use a value, pretend you got input. do something with it.

basic form for output in a console environment:

System.out.println( ... ); // except replace the ... part with strings and basic data types (through what's called concantenation):

System.out.println("Hi this is my output so there: " + nyNum + " and heres some more: " + myOtherNum);

okay, this is way short of a tutorial, but you should try some stuff at least.

play with it for a bit. it can be fun.

Edit: oops. typos in code. i'm a sloppy typer. don't take this crap at face value if it don't work.

get you started, here's a sample prog with a main func.

Code:
class MyProgram {

    public int main() {
        double myNum = 15,  myNum2 = 20;

        System.out.println("Hi this is my sample program!");
        System.out.println("Let's pretend we have some input numbers!");
        System.out.println("Number 1 : " + myNum);
        System.out.println("Number 2 : " + myNum2);
        System.out.println("Number 1 + Number 2 : " + (myNum + myNum2));
        System.out.println("Wasn't that fun!");

        return 0;
    }
}
I havent compiled but it should work.

I'd have to look up input i forgot off the top of my head...
 
I have one question though... wtf kind of class has a project like this..where if you don't get it done...you fail the class... i find this very hard to believe... even my CS120 class had harder projects than that...

plus if you are stuggling this bad in the beginning of the semester i'd suggest...

a) paying attention more in class...

b) drop the class...

this really shouldn't be all that hard to figure out...


one more thing... I have had some bad teachers in my day, but I'm sure he/she has taught you more than this...
 
JFry said:
I'm sure you can get it with a little effort, especially if you have a text book helping you. I.


im sure i could too, if i had a text book. the idiots forgot to order the textbook, all we have is the workbook. and as hard as it is to believe, yes, i will fail the course, and yes, he did not teach us a stitch of work. thats y im reaching out to u guys who i know would look at this and laugh and would take like 2 minutes to code.
 
Ok ok, just stop complaining about the class and get writing. Look, the first steps to developing code is often developing pseudo-code. This means you don't actually worry about syntax or things like that, but you work through the steps, write it on paper or something. It will help to outline your tasks. You just need to write something, and work out from there. I'd say worry about the input last, and the output just before the input.

Oh, one thing that I think will help you a lot is if you don't use Notepad. For simple tasks like this, I recommend you use Dr. Java instead. The interactions pane is its best feature. You can test code out there.

*Edit: post your work when you've got some stuff written down.
 
I'd like to help you, but if I'd do the work for you, you'd learn nothing. Besides it's not that difficult. The only difficult part would be getting input from the console, unless your teacher provided you with a class that has methods for input.

for input from the console use this:

Code:
         try
    	{
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		String str;
    		str=in.readLine();
    		//do stuff with str
    	}
    	catch(IOException e)
    	{
              //something went wrong
    	}

I can only give you these tips:
-use the API reference found at http://java.sun.com/j2se/1.4.2/docs/api/index.html

-read the java tutorial found at http://java.sun.com/docs/books/tutorial/index.html
 
yay i learned new stuff today in class. (im still here in school btw)

i learned int means interger
i learned about constructors and private/public classes
i learned what an object is, how to create one, and what an object reference is and does


now that i learned that, i still have no clue what to do. im assuming that my first class would start out something like this?

publicClass LeanCalculator

{int someVariableHere bla bla bla.......

k lost now. lol. according to him it was expected of us to know c++ or java before signing up for the course. when i looked at my old course requirement sheets it said nothing of the sort.

my major problems with coding are -

1. i dont know the order of putting code. i.e input/process instructions/output.
2. i dont know code names besides String and int.
3. i dont know what to write basically, as i have no experience in the field.


btw i know it sounds like ive been nagging and whining but really thank you guys a ton i appriciate it so much...i just dont comprehend c++.

this project is due october 7th, it has to work completely. i have my PDL(plan of action for what ur going to do in the actual coding process....y am i telling u guys u know this already) file if you guys want that.
 
1. Find a length of rope - 1m should be enough.
2. Find a high sturdy structure. This must support the weight of one person.
3. Find a stool or chair high enough to reach the support structure. Whatever you choose must be easily knocked over.
3. Tie the length of rope to the support.
3. Create a noose at the bottom end of the rope. See here for instructions: http://www.ehow.com/how_7535_tie-noose.html
4. Standing on your stand, loop the noose around your neck and tighten.
5. Rocking back and forth knock the stand over so you are left hanging.
6. count to 1000 slowly.
 
"i just dont comprehend c++."


you do know this is java right?...hehe...
 
ok, anyone besides we11er whos apparently just a ****ing troll that can help me out?
 
I never done java, but here is what I can say:
If you know how to write a basic program that does nothing (i.e. the structure of an empty program) and if you know how to declare variables in the program, and if you know the math required for this assignment, then do this:

-start an empty program.
-declare some variables for whatever beef stuff.
-let the user input the variables
-do the math, in java ofcourse. (for example you can say var1 = var2 + var 3 .. etc, I hope you know how to manage basic algebraic operations in java).
-out put the result
-end the program (if it requires a special ending or something .. I really have no idea how the structure of a java program looks like).

But here is a more important advice:
Search the net for Java tutorials. Don't underestimate them, I learned C++ all from the net. (well I had a book at the beginning, but I don't see how it would make a difference learning-wise if I hadn't had it)
 
OK, I refuse to be labelled a troll, hence the following. I can't remember to how to input stuff, but fill the variables with the right values, and it should work. Note I just did this quickly in notepad so there may be some simple mistakes - and I may have completely missed the point of the exercise!!

edit: lol just realised the maths is all wrong, but you get the idea!!

Code:
// input price per pound A
int fullPriceA;

// input percent lean A
int percentLeanA;

// input price per pound B
int fullPriceB;

// input percent lean B
int percentLeanB;


// Calculate price per pound lean A
// Watch out with division as you may lose
// precision.  Best to multiply first

leanPriceA = ( fullPriceA * percentLeanA ) / 100;

leanPriceB = ( fullPriceB * percentLeanB ) / 100;

System.Out.Println( "Package A cost per pound: " + leanPriceA );
System.Out.Println( "Package B cost per pound: " + leanPriceB );

System.Out.Println( "Package " + ( A < B ? "A" : "B" ) + "is the best value" );
 
Hehe, looks like Guinny's name-calling payed off. :D
 
Oh bugger, another thing i messed up. You should use

float xxx;

for all the variables or you lose precision
 
Seeing as you're this desperate, I've done it for you. Read the comments and try and understand the code. Don't expect us to make all your homework for you. JCreator ****ed up the formatting, but you'll manage.
http://users.pandora.be/piele/
 
guinny said:
He taught us hello world. He didnt teach us how to actually write a program. i did hello world last week. i know that this project is only like 10 lines of code, i just dont know WHAT 10 lines of code, and id really appriciate it if someone who knew making a program like this one would be a breeze, if they could write up the code for me. :( pretty please?
The class has a book to it to for a reason.
 
Bert said:
Seeing as you're this desperate, I've done it for you. Read the comments and try and understand the code. Don't expect us to make all your homework for you. JCreator ****ed up the formatting, but you'll manage.
http://users.pandora.be/piele/

You really shouldn't have done that Bert... now this guy probably wont learn a damn thing...

He didn't even say Thank You!


I wonder what his next project is? output to a file?:eek:
 
im sorry i havent replyed. i actually was trying to figure it out on my own, but to no avail of course. bert, i cannot thank you enough. not only did u code it for me, but u gave me a really awesome tutorial in the code that i can actually understand. Thank you so much, I hope one day i can return the favor. and thanks to everyone as well for supporting me through this and not just brushing me off, i really really appriciate it. :thumbs: :cheers:
 
For a laugh I made a version with a GUI, in under 100 lines no less.

The only code that is relavent is in actionPerformed().

PHP:
package tests;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BeefCalculator {
    GUI gui = new GUI();
   
    public BeefCalculator() {   
    }
    
    public static void main(String[] args) {
        BeefCalculator beef = new BeefCalculator();
    }
    
    class GUI extends JFrame implements ActionListener{
        
        JTextField priceA = null, percentA = null;
        JTextField priceB = null, percentB = null;
        JTextField result = null;
        JButton compute = null;
        
        public GUI(){
            super("BeefCalculator");
            
            this.setSize(300, 200);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            
            GridBagConstraints gc = new GridBagConstraints();
            GridBagLayout gl = new GridBagLayout();
            this.setLayout(gl);
            gc.gridwidth = gc.REMAINDER;
            gc.gridheight = 1;
            
            priceA = new JTextField("Enter price A here");
            gl.setConstraints(priceA, gc);
            percentA = new JTextField("Enter percentage of lean meat");
            gl.setConstraints(percentA, gc);
            priceB = new JTextField("Enter price B here");
            gl.setConstraints(priceB, gc);
            percentB = new JTextField("Enter percentage of lean meat");
            gl.setConstraints(percentB, gc);
            result = new JTextField("Result is shown here");
            gl.setConstraints(result, gc);
            compute = new JButton("Compute");
            gl.setConstraints(compute, gc);
            compute.addActionListener(this);
            
            this.add(priceA);
            this.add(percentA);
            this.add(priceB);
            this.add(percentB);
            this.add(compute);
            this.add(result);
            
            this.pack();
            this.show();
        }
        
        public void actionPerformed(ActionEvent e) {
            float pA = Float.valueOf(priceA.getText()).floatValue();
            int cA = Integer.valueOf(percentA.getText()).intValue();
            float pB = Float.valueOf(priceB.getText()).floatValue();
            int cB = Integer.valueOf(percentA.getText()).intValue();
            
            float lA = ( pA * cA ) / 100;
            float lB = ( pB * cB ) / 100;
            
            if(lA < lB){
                result.setText("A is better value");
            }else{
                result.setText("B is better value");
            }
        }
        
    }
    
}
 
hey mr chimp i compiled ur code for fun, i got the class file and everything. but now how do i run it? i wanna see how cool it is. :thumbs:
 
On the coolness scale it rates about -1 :LOL:

Instead of trying to tell you how to run a class file (which I have never done myself) or create jar file with a manifest file, I'll just post the jar file.

rename .zip to .jar

You need the JRE1.5 - 1.4 won't work.
 
If you want help in the future, guinny, take my advice; don't beg for others to write the program for you. You won't learn anything this way. Asking someone to do your homework for you is not looked upon too highly, it's actually regarded as quite a pathetic act because it shows no will to learn. If you want help, try to write the program yourself first. Pursue the information available to you in books, and scour the net. Exhaust every possible avenue, and if you still haven't got it, post all of your work (that is, your code) followed by a description of what you've done yourself to solve the problem. Nobody wants to do your dirty work because you can't be bothered to do it yourself. Trust me, you were incredibly lucky to get help here asking for it the way you did.
 
if it isn't official policy for the coding forums to not post solutions to homework problems, it should be. I noticed that's the policy at experts-exchange.

In one of my classes, several people cheated off of each other, they all failed the class. Well, as someone who actually did the assignments (which were very easy, and a few big steps over the one discussed here), I was glad.

So, if I see someone wanting a complete solution for a suspiciously homework-type problem, I'm going to recommend that the post be deleted or some similar type action.

Here, guinny (not intending to pick on him specifically, just making a point) evidently had at least 3 days to get this assignment done ( judging from the amount of time between first post and last post. It seems as if he was still working on it in the last one...)
I'd say, that (unless you are of unusually low intelligence) 3 days would be long enough to research the tiny amount of java required to complete this assignment and get it to work.

If, on the other hand, you needed help on one function, or on a particular part of the code, there's nothing wrong with that...
 
Back
Top