Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help with user imput

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with user imput

    Im trying to make a program that does a formula and the user imputs the variables and it prints the result.
    I dont know terminology, so im just gona call this the class with the formula
    //Geometeric Series - Sn = (1-r^(n-1))/(1-r) 
     
     
     
    public class geometricSeries 
    { 
    public static double geometricSeries(double a, int n, double r)
    {
     
    double sum = (1-(Math.pow(r,n)))/(1-r);
    return sum;  
    }
    }

    This is the user imput part i have a problem with
    import java.util.Scanner;
     
    public class geometricSeriesDriver
    {
     public static void main(String[]args);
     {
      System.out.println("Imput the first term");
     
      Scanner scan = new Scanner(System.in);
      double a = scan.nextDouble;
     
      System.out.println("Imput the n term");
      int n = scan.nextInt;
     
      System.out.prinln("Imput the ratio");
      double r = scan.nextDouble;
     
      return sum; 
      }
     }

    I have no idea how to connect the two, its been like 2 weeks since ive written code and im just starting so i kind of forgot how. Also i get these errors.
    geometricSeriesDriver.java:5: error: missing method body, or declare abstract
    public static void main(String[]args);
    ^
    geometricSeriesDriver.java:10: error: cannot find symbol
    double a = scan.nextDouble;
    ^
    symbol: variable nextDouble
    location: variable scan of type Scanner
    geometricSeriesDriver.java:13: error: cannot find symbol
    int n = scan.nextInt;
    ^
    symbol: variable nextInt
    location: variable scan of type Scanner
    geometricSeriesDriver.java:15: error: cannot find symbol
    System.out.prinln("Imput the ratio");
    ^
    symbol: method prinln(String)
    location: variable out of type PrintStream
    geometricSeriesDriver.java:16: error: cannot find symbol
    double r = scan.nextDouble;
    ^
    symbol: variable nextDouble
    location: variable scan of type Scanner
    geometricSeriesDriver.java:18: error: return outside method
    return sum;
    ^
    6 errors


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Need help with user imput

    errors could be fixed by changing scan.nextDouble; to scan.nextDouble(); and scan.nextInt; to scan.nextInt();

    There is no method of prinln(), I think it should be println();

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with user imput

    Thank you, changing to scan.nextDouble() and scan.nextInt() cleared up 3 errors. And the prinln was changed to println();
    I still get these errors for the second one

    geometricSeriesDriver.java:5: error: missing method body, or declare abstract
    public static void main(String[]args);
    ^
    geometricSeriesDriver.java:18: error: return outside method
    return sum;
    2 errors
    Last edited by GeneralPihota; February 29th, 2012 at 01:22 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Need help with user imput

    Read those errors carefully, as they describe the problem pretty explicitly. For instance:
    missing method body, or declare abstract
    main is a method...where is its body? If you don't know what this means, see
    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    and
    Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started)

  5. #5
    Member clydefrog's Avatar
    Join Date
    Feb 2012
    Posts
    67
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: Need help with user imput

    Why not just move the method into the geometricSeriesDriver class?

    Like so;
    public class geometricSeriesDriver
    {
     
      public static double geometricSeries(double a, int n, double r)
      {
     
        double sum = (1-(Math.pow(r,n)))/(1-r);
        return sum;  
      }
     
      public static void main(String[]args);
      {
        System.out.println("Imput the first term");
     
        Scanner scan = new Scanner(System.in);
        double a = scan.nextDouble;
     
        System.out.println("Imput the n term");
        int n = scan.nextInt;
     
        System.out.prinln("Imput the ratio");
        double r = scan.nextDouble;
     
        return sum; 
       }
     }

    As the other user mentioned, you need add a () to nextInt and nextDouble to become nextInt() nextDouble()

    also you never defined the variable sum. so it would be: double sum;

    do you know how to call a method?

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Need help with user imput

    Quote Originally Posted by clydefrog View Post
    Like so;
    Please read the compile messages posted in post #3 above - your code just recapitulates the errors.

  7. #7
    Member clydefrog's Avatar
    Join Date
    Feb 2012
    Posts
    67
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: Need help with user imput

    Quote Originally Posted by copeg View Post
    Please read the compile messages posted in post #3 above - your code just recapitulates the errors.
    I just want to know why he/she has a separate class when you could put the whole thing in just one class. I wasnt trying to debug those errors; though i have fixed the code and runs on my machine lol.

    I want to see if the OP has figured it out

Similar Threads

  1. User Titles
    By snowguy13 in forum Totally Off Topic
    Replies: 4
    Last Post: January 26th, 2013, 04:37 AM
  2. Overlaying User Help Over GUI
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: August 8th, 2011, 10:06 AM
  3. Keyboard imput not working!
    By Skyhigh32 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 16th, 2011, 08:47 AM
  4. user preferences
    By nasi in forum Java Theory & Questions
    Replies: 5
    Last Post: April 17th, 2011, 11:55 PM
  5. User Interface Problems
    By pmg in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 4th, 2011, 07:32 AM