Java help?

A place for general discussions about anything and everything.

Java help?

Postby BreathofFire » Sun Jan 29, 2012 1:18 am

i am so confused on java lol it's harder then Japanese and that was hard for me to learn XD
i need help on some simple programs, the problems are not simple to me as it's going jump jump jump no breaks to harder and harder things with out stopping if any one can help me with java i would really appreciate the help...
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby Suraru » Sun Jan 29, 2012 1:40 am

Java sucks, but its widly used for some reason.

I've learned it twice and forgotton both times. I am currently relearning it, but unless you have some programming experiance, don't learn java yet.
"Thanks to your unfortunate life, I've found myself being more and more grateful!"

"Are you horny? Do you not want babies? Just watch porn!
They'll make you jizz in your pants, so others don't have to!"
Suraru
 
Joined: Fri Nov 25, 2011 4:13 am
Location: Behind you.

Re: Java help?

Postby BreathofFire » Sun Jan 29, 2012 1:48 am

wish i could say that but right now i am already in the class so i am going in blind right now, and have two programs left to do with key words i need to use that i didn't really learn in depth yet it makes my head hurt thinking about it and what i need to do with the programs.
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Sun Jan 29, 2012 2:38 am

I use java. I don't know if i can since I don't always follow convention.
Also don't get help from Suraru. I tried that once and he was fucking telling the wrong thing for an hour and not until i ignored him did my program work.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Sun Jan 29, 2012 2:53 am

thanks a bunch if you ever need any more things for graphic design just ask (i think i actually got better ideas for ship parts now after some time has past and i have been thinking about it any ways i digress) well right now i need to make a program that converts gas into other things liters barrels ect i was given all the information and conversion rates so i am ok there
but the trouble is i have no clue how to use:
floats i never even knew till now that we are using that... lol oh well that's what i get for jumping in to a second semester class.
that and do i use it just for one or all i am scratching my eyes as i find when i do get it i get numbers like .2382738272819... (not one i really got but it's like it)

2) Gasoline Measurements. Write a Java program in the file Gas.java that prompts the user for a floating point number which stands for gallons of gasoline. You will reprint that value along with other information about gasoline and gasoline usage

Number of liters
Number of barrels of oil required
Number of pounds of CO2 produced
Equivalent energy amount of ethanol
gallons Price in US dollars

1 gallon is equivalent to 3.7854 liters 1 barrel of oil produces 19.5 gallons of gas (approximately, can vary depending on the oil source. This number will work for us). FYI, a barrel is 42 gallons. 1 gallon of gas produces approximately 20 pounds of CO2. Again, good enough 1 gallon of gas produces 115,000 BTU (British Thermal Units). 1 gallon of ethanol produces 75,700 BTU. Who knows what the cost should be, but let’s state it at $3.67/gallon
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Sun Jan 29, 2012 3:59 am

Just to make sure. Is it a Floating point variable or a float variable?
The two are different.
A float, and double are floating point variables.
I believe float only covers like 5.23 and i believe uses a f at the end or something. 5.23f. I personally don't use them but i know of them.

So by the code of conduct rules i can't write this for you. I can help you with understanding the elements.
Also sorry about the soon be "treating you like a idiot" talk but i don't know what you know and it sounds like you jumped into this.
Might be better if you don't read but your still going to have to think what to do.
This does not contain code but i say "This divided by that is them times 3 equals gas"
Spoiler (click to show/hide):

Your likely going to need a place to save your gas while working with it. I would write a method for each test required by the program.

so basically your saying "gas times 3.784 is number of gasLiters. gas divided by 19.5 = oilBarrel .(note might be wrong when thinking in retro spec to your FYI) . gas times CO2.

give me time to think of the other one. but thats basically what their saying. I mean look at it this way.

1 gallon is equivalent to 3.7854 liters.
If your doing programming i would assume you have your math classes in order and you could figure out what L is if you gave G a value. That basically what your doing there
G = 3.7854L.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Sun Jan 29, 2012 10:24 pm

thank you that helps a lot and float variable though never was specified nor a lot of the things in the codes.
any ways i will give it my best lol hopefully i will choose a class that doesn't kill my brain next time.
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Sun Jan 29, 2012 11:05 pm

Make sure you write a system.out of some kinda for your test.
You might not need to make a new object of the class. However this would require to use the main method which is a pain in my case be because everything that you has to be static.
However if you only have the main method and your using a local variable or class variable and not a instants variable you should be find.

A local variable is one in the class.
A Class variable is instants variable with a static modifier
A instants variable is a variable that is used out side of a method but in side the class. (well you can't have a variable out side a class. Silly!)


Also if you do not know how to use "return" in a method then using more than the main method might be a bad idea.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Sun Jan 29, 2012 11:31 pm

i think i finished it for the most part thanks again for the help.

Spoiler (click to show/hide):

import java.util.Scanner;


public class Gas {
static Scanner inpute = new Scanner(System.in);

public static void main(String[] args){
// inpute
System.out.print("Number of gallons");
// outpute
float gallon = inpute.nextFloat();
float liters = (float) (gallon * 3.7854118);
System.out.println("Liters: " + liters);
double barrels = gallon/ 19.5;
System.out.println("Number of barrels of oil required: " + barrels);
double cotwo = gallon*20;
System.out.println("Number of pounds of CO2 produced: " +cotwo);
double ethonal = gallon * 75700;
System.out.println("Equivalent energy amount of ethanol gallons: " + ethonal + " BTW");
double price = 3.67*gallon;
System.out.println("Price in US dollars" + price);

}
}


thanks for the help now on to the hardest one lol though i still didn't use the float correctly though the program still works which is nice but i get some large numbers.

output
Spoiler (click to show/hide):

Number of gallons1
Liters: 3.7854118
Number of barrels of oil required: 0.05128205128205128
Number of pounds of CO2 produced: 20.0
Equivalent energy amount of ethanol gallons: 75700.0 BTW
Price in US dollars3.67
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Mon Jan 30, 2012 12:15 am

The only thing i would be worried about that i see is your spelling if your teacher check that and if your English. inpute is not a English work but input is.
I mean if where ever your from it's spelled inpute that what you should used.

In your output strings your missing a ": ". and you seem to have a magic 1 one popping up at gallons.

I thought this was your only home work. Did i completely by pass one? I'll recheck.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Mon Jan 30, 2012 12:23 am

the magic 1 is my input sorry to get all those out puts when i run the program and not making it so that that after words that input of 1 for gallons vanishes.
really i guess i just mean that 1 for gallons is me testing the program for the rest of the out puts.
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Mon Jan 30, 2012 12:42 am

So personally i fined it ugly how you did the first system.out.print but it might be what gets you the A.

I would've asked the person how many gallons and then started the the report.
But that might not follow convention or what your teachers expects so it's your call.

Other than that it looks like this should pass. I would have to look over the math again to be sure.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Mon Jan 30, 2012 12:58 am

thank you very much for your time, and yeah i noticed it's a bit of a mess but really i just wanted to get it done no excuse though but hey i have my lazy moments too.
this really helped a lot though thanks.
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Mon Jan 30, 2012 1:04 am

here is the output i got for the modified version of yours i got.
Code: Select All Code
How much gas do you have?
2.345
Number of gallons: 2.345
Liters: 8.876791
Number of barrels of oil required: 0.1202564117236015
Number of pounds of CO2 produced: 46.900001525878906
Equivalent energy amount of ethanol gallons: 177516.5 BTW
Price in US dollars: 8.606150104999543

Since it sounds like your still working on this so i will follow code of conduct rules and not show you my code yet.
It's basically a edit for 3 lines and a bunch of comments that you forgot.... *magical coder glare!*
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Mon Jan 30, 2012 1:56 am

that's actually pretty cool i would like to see it after i turn my work in.
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;

Re: Java help?

Postby BlueLight » Mon Jan 30, 2012 2:27 am

Now time to butcher your code... MUHHAHAH!!!

Are you using Java 6 or 7?
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Java help?

Postby BreathofFire » Tue Jan 31, 2012 1:32 am

eclipse i believe it uses 7 though not sure.
and pfff
Image

yes this is my design
User avatar
BreathofFire
 
Joined: Fri Jan 13, 2012 3:40 am
Location: 221B Baker Street (elementary my dear) * i hope you get the refernce if you don't i might be sad ;3;


Return to General



Who is online

Users browsing this forum: No registered users