Results 1 to 20 of 22
- 03-20-2012, 01:54 AM #1
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Help. i dont know where to even start.
ok so i have an assignment for school we have to write a program, here is the "question"
were working with methods so it needs to use methods to give the answer.Einstein’s famous equation relating energy and matter is
Where E is the amount of energy in Kilojoules
m is the mass of the object in Kg
c is the speed of light (2.998*108)
Write a method that calculates the energy released by the complete annihilation of matter, where the amount of matter is provided as an argument or parameter to the method.
Write a program that allows the user to enter the size of the mass and get a report of the energy produced.
(i think i did that post code in the forum thing right)PHP Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double e; double m; double c = 2.998*10^8; double matter; explosion(); public static double explosion(e=m(c*c)){ Scanner kbd = new Scanner(System.in); System.out.println("enter amount of matter "); kdb = nextDouble(); } } }
- 03-20-2012, 02:17 AM #2
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
i'am not trying to homework dump, i just would like a push in the right direction.
-
Re: Help. i dont know where to even start.
You can't nest one method inside of another. Keep the main method and the explosion method separate. And don't have any equations in the parameter. Just accept a single value, mass, and deal with it inside of the method.
- 03-20-2012, 02:32 AM #4
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
so like this
but its not working. hmmm there seems to be an issue with this line "public static double explosion(mass){"Java Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double e; double mass; double c = 2.998*10^8; double matter; explosion(); } public static double explosion(mass){ Scanner kbd = new Scanner(System.in); System.out.println("enter amount of mass "); kdb = nextDouble(); mass = e/((2.998*10^8)*(2.998*10^8)); return mass; } }Last edited by kiddCOWBOYY; 03-20-2012 at 02:49 AM.
-
Re: Help. i dont know where to even start.
"there seems to be an issue with..." doesn't tell us much. If your code generates a compilation error or a run-time exception, you'll want to post the entire text of the message you get, and indicate which line is causing it.
- 03-20-2012, 02:36 AM #6
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
sorry, new to this hole thing.
line 18 on here.
C:\Users\Damien Breaux\Documents\Programing\Einstien.java:19: error: <identifier> expected
public static double explosion(mass){
^
-
Re: Help. i dont know where to even start.
OK, so it's saying that the parameter is written wrong. When declaring a method, you need to also show the parameter type, not just a variable name. Please have a look here for more on this: Passing Information to a Method or a Constructor
- 03-20-2012, 02:43 AM #8
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
ok so the missing identifier was "double"
now i need to figure out what "e: is equal too and how to write this "2.998*10^8" so that java can read it.
thanks for helping me out by the way. :D
PHP Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double e; double mass; double c = 2.998*10^8; double matter; explosion(); } public static double explosion(double mass){ Scanner kbd = new Scanner(System.in); System.out.println("enter amount of mass "); kdb = nextDouble(); mass = e/((2.998*10^8)*(2.998*10^8)); return mass; } }
-
Re: Help. i dont know where to even start.
That is correct.
Look at the Math class which will have some static methods that can help you out here, including the pow(...) method.now i need to figure out what "e: is equal too and how to write this "2.998*10^8" so that java can read it.
You're welcome!thanks for helping me out by the way. :D
Please see some commentsPHP Code://.... double c = 2.998*10^8; // yikes // .... public static double explosion(double mass){ //.... return mass; // !!! are you sure about this? } }
- 03-20-2012, 03:07 AM #10
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
Java Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double e; double mass; /* there is something i need to put here but i don't know what it should look like 2.998*10 Math.pow(8,somthing); but iam not sure what. */ double c = 2.998*10 Math.pow(8); double matter; explosion(); } public static double explosion(double mass){ Scanner kbd = new Scanner(System.in); System.out.println("enter amount of mass "); kbd = nextDouble(); mass = e/((2.998*10 Math.pow(8)*(2.998*10 Math.pow(8)); return mass; } }
-
Re: Help. i dont know where to even start.
Are you saying that it now works?
- 03-20-2012, 03:09 AM #12
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
No hah not at all, but i think if i can get that math class figured out i can get it working. maybe :P
-
Re: Help. i dont know where to even start.
Some suggestions:
- Re-read the instructions, in particular: "Write a method that calculates the energy released"
- When writing code, and if not using an IDE, compile often, usually after adding each line of code.
- If you find a compilation bug, fix it before adding any more code to your program.
- 03-20-2012, 04:10 AM #14
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
so close, i dont understand how to call the method tho. any hints ?
Java Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double energy; double mass; double c = 2.998 * Math.pow(10,8); double matter; System.out.println("the energy realeased is" explosion); } public static double explosion(double energy){ Scanner kbd = new Scanner(System.in); double mass; System.out.println("enter amount of mass "); mass = kbd.nextDouble(); energy = mass/((2.998 * Math.pow(10,8))*(2.998* Math.pow(10,8))); return energy; } }
-
Re: Help. i dont know where to even start.
- Please re-read your instructions. What is the input to the method supposed to be? energy? I don't think so.
- No need to declare many of those variables in main if you're not going to be using them in main.
- Let's see you attempt to call your method first. But first you'll need to use your Scanner object to get user input.
- 03-20-2012, 04:31 AM #16
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
Java Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double mass; double energy; //here is were the user inputs mass. and then it is carried to the next method. i think? System.out.println("enter amount of mass "); mass = kbd.nextDouble(); // this is were i should be calling the method, but it wont.? System.out.println("the energy released is " + explosion); } public static double explosion(double mass){ double energy; energy = mass/((2.998 * Math.pow(10,8))*(2.998* Math.pow(10,8))); return energy; } }
-
Re: Help. i dont know where to even start.
Read up on how to call methods: Passing Information to a Method or a Constructor
- 03-20-2012, 05:20 AM #18
javaNOOB
- Join Date
- Mar 2012
- Location
- Texas
- Posts
- 16
- Rep Power
- 0
Re: Help. i dont know where to even start.
I DID IT!!!!!
.gif)
.gif)
.gif)
thanks for the help man. :P iam still a noob at this haha
Java Code:import java.util.Scanner; public class Einstien { public static void main(String[] args){ Scanner kbd = new Scanner(System.in); double mass; double energy; System.out.println("enter amount of mass "); mass = kbd.nextDouble(); energy = explosion(mass); System.out.println("the energy realeased is " + energy ); } public static double explosion(double mass){ double energy; energy = mass/((2.998 * Math.pow(10,8))*(2.998* Math.pow(10,8))); return energy; } }Last edited by kiddCOWBOYY; 03-20-2012 at 05:23 AM.
-
Re: Help. i dont know where to even start.
Good show young person, good show!
- 03-20-2012, 08:35 AM #20
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
JButton's dont appear
By k3eper in forum New To JavaReplies: 7Last Post: 10-10-2011, 10:25 PM -
Start Swing GUI program by Java Web Start with IE in Eclipse debug mode
By albertkao in forum EclipseReplies: 1Last Post: 01-18-2011, 06:27 PM -
Out of Bounds. I dont know Why :L
By socboy6579 in forum New To JavaReplies: 10Last Post: 01-13-2011, 12:02 AM -
Hello! and I need help. I dont know were to start
By Fall0ut in forum New To JavaReplies: 10Last Post: 05-19-2010, 06:26 PM -
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks