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 3 of 3

Thread: Learning OOP; Gettin error messages i cant explain.

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    11
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Learning OOP; Gettin error messages i cant explain.

    This is a "homework" of self-paid course of Java basics.

    Mission is to create a class Tulostaja, which ask's two integers and then calls method Summa() from a class Laskin. The code where i need to create this class is next.
    At first, i thought the problem was in line import java.util.Scanner; and i switched it to import java.util.*;, but that did not solve the problem.
     
    import java.util.Scanner;
     
     
    public class OlioidenToimintoja {
        public static void main(String args[]) {
            Tulostaja olio = new Tulostaja();
            olio.Tulosta();
        }
    }
     
     
    //  Here comes my piece of code.
     
     
    class Laskin {
        static int Summa(int eka, int toka) {
            int summa = eka + toka;
            return summa;
        }
    }

    And here is the code i have tried (with multiple variations).

    class Tulostaja {
    	public void Tulostaja(){
    		int eka;
    		int toka;
    		int kolmas;
    	}
    	// muuttujat
    	int eka, toka, kolmas;
     
    	// Luetaan kokonaisluvut
    	Scanner lukija = new Scanner(System.in);
    	System.out.print("Syötä ensimmäinen luku: ");
    	eka = lukija.NextInt();
    	System.out.print("Syötä toinen luku: ");
    	toka = lukija.nextInt();
     
    	// Kutsutaan laskinta
    	kolmas = Laskin.Summa(eka, toka);
    	System.out.print("Lukujen summa: " + kolmas);
    }

    Here is the error messages from javac.

    OlioidenToimintoja.java:28: <identifier> expected

    System.out.print("Syötä ensimmäinen luku: ");

    ^

    OlioidenToimintoja.java:28: illegal start of type

    System.out.print("Syötä ensimmäinen luku: ");

    ^

    OlioidenToimintoja.java:29: <identifier> expected

    eka = lukija.NextInt();

    ^

    OlioidenToimintoja.java:30: <identifier> expected

    System.out.print("Syötä toinen luku: ");

    ^

    OlioidenToimintoja.java:30: illegal start of type

    System.out.print("Syötä toinen luku: ");

    ^

    OlioidenToimintoja.java:31: <identifier> expected

    toka = lukija.nextInt();

    ^

    OlioidenToimintoja.java:34: <identifier> expected

    kolmas = olio.Laskin(eka, toka);

    ^

    OlioidenToimintoja.java:35: <identifier> expected

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: illegal start of type

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: ')' expected

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: ';' expected

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: illegal start of type

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: <identifier> expected

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:35: ';' expected

    System.out.print("Lukuje summa: " + kolmas);

    ^

    OlioidenToimintoja.java:42: reached end of file while parsing

    }

    ^

    15 errors
    Last edited by E.K.Virtanen; March 20th, 2013 at 12:48 PM. Reason: [Solved]


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,948
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Learning OOP; Gettin error messages i cant explain.

    The compiler is confused because it found statements that should be inside of a method that were not in a method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    11
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Learning OOP; Gettin error messages i cant explain.

    Thank you Norm. Feeling bit stupid here, but i guess it's the price of learning new
    Got it working.
    Last edited by E.K.Virtanen; March 25th, 2013 at 03:31 PM. Reason: Removed the solution.

Similar Threads

  1. Please explain why I get this error...
    By mrjavajava in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2013, 09:58 AM
  2. Getting error messages with my javafx video player
    By sharksaw40 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 24th, 2012, 02:27 AM
  3. Java Unit Testing How-To Gettin' started
    By Massaslayer in forum Java Theory & Questions
    Replies: 2
    Last Post: May 1st, 2012, 08:58 AM
  4. Help needed to figure out why I keep getting error messages in Eclipse
    By RookieCodeWriter in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 18th, 2012, 12:31 PM
  5. Error Messages Best Practices
    By Dalek_Supreme in forum Java Theory & Questions
    Replies: 0
    Last Post: April 1st, 2011, 08:22 PM