Page 1 of 2 12 LastLast
Results 1 to 20 of 22
Like Tree1Likes

Thread: Help. i dont know where to even start.

  1. #1
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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"

    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.
    were working with methods so it needs to use methods to give the answer.

    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();
    }
    }
    }
    (i think i did that post code in the forum thing right)

  2. #2
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  4. #4
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default Re: Help. i dont know where to even start.

    so like this

    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;
    }
    }
    but its not working. hmmm there seems to be an issue with this line "public static double explosion(mass){"
    Last edited by kiddCOWBOYY; 03-20-2012 at 02:49 AM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  6. #6
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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){
    ^

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help. i dont know where to even start.

    Quote Originally Posted by kiddCOWBOYY View Post
    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){
    ^

    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

  8. #8
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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;
    }
    }

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help. i dont know where to even start.

    Quote Originally Posted by kiddCOWBOYY View Post
    ok so the missing identifier was "double"
    That is correct.


    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.
    Look at the Math class which will have some static methods that can help you out here, including the pow(...) method.


    thanks for helping me out by the way. :D
    You're welcome!


    PHP Code:
        //....
    	double c = 2.998*10^8; // yikes
    
        // ....
    	public static double explosion(double mass){
               //....
    	return mass; // !!! are you sure about this?
    }
    }
    Please see some comments

  10. #10
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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;
    }
    }

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  12. #12
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  14. #14
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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;
    }
    }

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  16. #16
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default 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;
    }
    }

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  18. #18
    kiddCOWBOYY is offline javaNOOB
    Join Date
    Mar 2012
    Location
    Texas
    Posts
    16
    Rep Power
    0

    Default Re: Help. i dont know where to even start.

    I DID IT!!!!!
    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.
    Fubarable likes this.

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help. i dont know where to even start.

    Good show young person, good show!

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help. i dont know where to even start.

    Quote Originally Posted by kiddCOWBOYY View Post
    Java Code:
    	public static double explosion(double mass){
    	double energy;
    
    
    	energy = mass/((2.998 * Math.pow(10,8))*(2.998* Math.pow(10,8)));
    
    	return energy;
    }
    Shouldn't that division be a multiplication? Oh, b.t.w. the name of that guy was Einstein, not Einstien.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 1 of 2 12 LastLast

Similar Threads

  1. JButton's dont appear
    By k3eper in forum New To Java
    Replies: 7
    Last Post: 10-10-2011, 10:25 PM
  2. Replies: 1
    Last Post: 01-18-2011, 06:27 PM
  3. Out of Bounds. I dont know Why :L
    By socboy6579 in forum New To Java
    Replies: 10
    Last Post: 01-13-2011, 12:02 AM
  4. Hello! and I need help. I dont know were to start
    By Fall0ut in forum New To Java
    Replies: 10
    Last Post: 05-19-2010, 06:26 PM
  5. Replies: 5
    Last Post: 03-20-2009, 10:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •