Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: any programmers here ?

  1. #11
    Join Date
    Oct 2013
    Posts
    4,051
    Reviews
    9

    Default

    Hmmm. This seems like it's an important exam to you ... how much is it worth


    First off I hadn't actually ran that EchoTest class through my compiler, something you really should do after every few lines of code. If you run the class you'll get two compile time errors. Here's the fix

    public class EchoTest
    {


    public void echo(String name)
    {
    System.out.println("You said " + name );
    }


    public static void main(String []args)
    {
    for(int i = 0; i < args.length; i++)
    {


    EchoTest echotest = new EchoTest();
    echotest.echo( args[i] );


    }


    }


    }


    There's a little bit more going on in that second problem so I won't do it all for you but here's the main structure

    public class NumberFormatter
    {


    public static String format(int number, int width)
    {
    //This is just the skeleton of the method. Try working out the logic
    String answer = "";
    return answer;
    }


    public static void main(String []args)
    {
    NumberFormatter nf = new NumberFormatter();
    int foo = Integer.parseInt(args[0]);
    int bar = Integer.parseInt(args[1]);
    NumberFormatter.format( foo, bar);
    }




    }


    I'm leaving the logic in the 'format' function for you to attempt. If you get stuck then let me know but at least give it a try for for your own benefit. Look into the formatting classes in the API for some help.



    The scanner library package was added in Java 5 AFAIK. It's a cleaner way of getting command line input. Not sure if your tutor would have wanted you using it though as it's a bit too easy.

    Have a read through this http://stackoverflow.com/questions/5...anner-nextline

    It has some good examples.


    Edit: If the question is asking specifically for calls to static methods then you should look into what that means.

    http://stackoverflow.com/questions/2...static-methods

    http://stackoverflow.com/questions/1...method-in-java
    Last edited by Jiberjabber; 17-11-14 at 21:04.

  2. #12
    Join Date
    Jan 2014
    Posts
    3,360

    Default

    Quote Originally Posted by Jiberjabber View Post
    Hmmm. This seems like it's an important exam to you ... how much is it worth


    First off I hadn't actually ran that EchoTest class through my compiler, something you really should do after every few lines of code. If you run the class you'll get two compile time errors. Here's the fix

    public class EchoTest
    {


    public void echo(String name)
    {
    System.out.println("You said " + name );
    }


    public static void main(String []args)
    {
    for(int i = 0; i < args.length; i++)
    {


    EchoTest echotest = new EchoTest();
    echotest.echo( args[i] );


    }


    }


    }


    There's a little bit more going on in that second problem so I won't do it all for you but here's the main structure

    public class NumberFormatter
    {


    public static String format(int number, int width)
    {
    //This is just the skeleton of the method. Try working out the logic
    String answer = "";
    return answer;
    }


    public static void main(String []args)
    {
    NumberFormatter nf = new NumberFormatter();
    int foo = Integer.parseInt(args[0]);
    int bar = Integer.parseInt(args[1]);
    NumberFormatter.format( foo, bar);
    }




    }


    I'm leaving the logic in the 'format' function for you to attempt. If you get stuck then let me know but at least give it a try for for your own benefit. Look into the formatting classes in the API for some help.



    The scanner library package was added in Java 5 AFAIK. It's a cleaner way of getting command line input. Not sure if your tutor would have wanted you using it though as it's a bit too easy.

    Have a read through this http://stackoverflow.com/questions/5...anner-nextline

    It has some good examples.


    Edit: If the question is asking specifically for calls to static methods then you should look into what that means.

    http://stackoverflow.com/questions/2...static-methods

    http://stackoverflow.com/questions/1...method-in-java
    that looks complicated........i did coding years ago. wasnt for me
    "The mass of men live lives of quiet desperation" - Henry David Thoreau.

  3. #13
    Join Date
    Oct 2013
    Posts
    4,051
    Reviews
    9

    Default

    Quote Originally Posted by Meursault View Post
    that looks complicated........i did coding years ago. wasnt for me
    It's not really but I guess that comes down to if you're into it or not. Or as you say, if it's for you.




  4. The Following User Says Thank You to Jiberjabber For This Useful Post:

    Meursault (17-11-14)

  5. #14
    Join Date
    Jan 2014
    Posts
    3,360

    Default

    Quote Originally Posted by Jiberjabber View Post
    It's not really but I guess that comes down to if you're into it or not. Or as you say, if it's for you.



    true, how the mind is coded is my fetish
    "The mass of men live lives of quiet desperation" - Henry David Thoreau.

  6. The Following User Says Thank You to Meursault For This Useful Post:

    Jiberjabber (17-11-14)

  7. #15
    Join Date
    Jun 2014
    Posts
    780

    Default

    Quote Originally Posted by Jiberjabber View Post
    Hmmm. This seems like it's an important exam to you ... how much is it worth


    First off I hadn't actually ran that EchoTest class through my compiler, something you really should do after every few lines of code. If you run the class you'll get two compile time errors. Here's the fix

    public class EchoTest
    {


    public void echo(String name)
    {
    System.out.println("You said " + name );
    }


    public static void main(String []args)
    {
    for(int i = 0; i < args.length; i++)
    {


    EchoTest echotest = new EchoTest();
    echotest.echo( args[i] );


    }


    }


    }


    There's a little bit more going on in that second problem so I won't do it all for you but here's the main structure

    public class NumberFormatter
    {


    public static String format(int number, int width)
    {
    //This is just the skeleton of the method. Try working out the logic
    String answer = "";
    return answer;
    }


    public static void main(String []args)
    {
    NumberFormatter nf = new NumberFormatter();
    int foo = Integer.parseInt(args[0]);
    int bar = Integer.parseInt(args[1]);
    NumberFormatter.format( foo, bar);
    }




    }


    I'm leaving the logic in the 'format' function for you to attempt. If you get stuck then let me know but at least give it a try for for your own benefit. Look into the formatting classes in the API for some help.



    The scanner library package was added in Java 5 AFAIK. It's a cleaner way of getting command line input. Not sure if your tutor would have wanted you using it though as it's a bit too easy.

    Have a read through this http://stackoverflow.com/questions/5...anner-nextline

    It has some good examples.


    Edit: If the question is asking specifically for calls to static methods then you should look into what that means.

    http://stackoverflow.com/questions/2...static-methods

    http://stackoverflow.com/questions/1...method-in-java
    i'd pay anything at this stage lol well if I pass i might get you some phone credit , thanks for that man I really appreciate it it gives me some idea anway better than have nothing done up ,yeah the string name she went yellow on me alright but the new code just says run echo and nothing else ?

    I tried this

    import java.util.Scanner;

    public class Echo
    {

    public static void main (String[] args)
    {

    String message;
    Scanner scan = new Scanner (System.in);


    System.out.println ("you said");

    message = scan.nextLine();

    System.out.println ("yousaid \"" + message + "\"");
    }
    }

    it says you said and you input yousaid and it repeats it I think thats what it wants ??

  8. #16
    Join Date
    Jun 2014
    Posts
    780

    Default

    Quote Originally Posted by Jiberjabber View Post
    It's not really but I guess that comes down to if you're into it or not. Or as you say, if it's for you.



    so true you do feel like a gobshite with this like it takes ages just to get your head around the simple stuff you can't really learn the stuff you to do it again again until you crazy to get it so frustrating lol

  9. #17
    Join Date
    Oct 2013
    Posts
    4,051
    Reviews
    9

    Default

    Quote Originally Posted by naturis View Post
    i'd pay anything at this stage lol well if I pass i might get you some phone credit , thanks for that man I really appreciate it it gives me some idea anway better than have nothing done up ,yeah the string name she went yellow on me alright but the new code just says run echo and nothing else ?

    I tried this

    import java.util.Scanner;

    public class Echo
    {

    public static void main (String[] args)
    {

    String message;
    Scanner scan = new Scanner (System.in);


    System.out.println ("you said");

    message = scan.nextLine();

    System.out.println ("yousaid \"" + message + "\"");
    }
    }

    it says you said and you input yousaid and it repeats it I think thats what it wants ??

    That code you wrote will work but the output won't be formatted as per the question. Also the question asks you to include an 'echo' method which you haven't. A lot of how they'll mark it goes on how close to the given instructions you stick as they're looking for your understanding of class structure in this instance ... I'm guessing.

    I ran the code that I gave you for the EchoTest class above and it works fine on my IDE. What are you using? Eclipse, Netbeans or are you using code highlighting in Notepad++? I'm guessing it's an IDE because your 'run echo' comment. If so you'll need to input some variables for the program in the IDE's console window. Can't see any errors in it under Eclipse


    When is the assignment due in? I can't stick around much longer tonight unfortunately ...
    Last edited by Jiberjabber; 17-11-14 at 22:55.

  10. #18
    Join Date
    Oct 2013
    Posts
    4,051
    Reviews
    9

    Default

    By the way I was joking about the code's worth man, I enjoy helping people with the programming mechanics. I'm not using Java much any more so it's just a way of making sure it's still fresh in my head if ever the need arises. PM me if you want with any further questions, I'm sure the rest of the E-I posters are enthralled by this and all but it's probably making some people wonder if they've logged into the wrong forum

    Later.

  11. #19
    Join Date
    Jun 2014
    Posts
    780

    Default

    Quote Originally Posted by Jiberjabber View Post
    By the way I was joking about the code's worth man, I enjoy helping people with the programming mechanics. I'm not using Java much any more so it's just a way of making sure it's still fresh in my head if ever the need arises. PM me if you want with any further questions, I'm sure the rest of the E-I posters are enthralled by this and all but it's probably making some people wonder if they've logged into the wrong forum

    Later.
    yeah lol no if does help me get past this I will send on credit or something sure its entry into job at end of day ,have done man

  12. #20

    Default

    Very impressed with your very intelligent reply here

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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