Home Technical Talk

Anyone know Java?

polycounter lvl 18
Offline / Send Message
Striff polycounter lvl 18
So I have this intro to Java class and I am having difficulty because my teacher is a senile 75-year old lady who thinks that teaching us how many bits are in different thing is more important then teaching us how to actually program.

Our assignment is to "Write a program that will read a line of text as input and then output the line with the first word moved to the end of the line."

We have to use strings, and can't use anything complex like if statements because we are not there in our crappy book yet. Does anyone know how to do this? Here is the code I have written so far, I just don't know how to use the strings to get it done.



<font class="small">Code:</font><hr /><pre>
import javax.swing.*;

public class wordchanger
{
public static void main(String[] args)
{
String phrase, output;


phrase = JOptionPane.showInputDialog(null,
"Please enter a line of text. Don't use any punctuation please.");


JOptionPane.showMessageDialog(null, "Your re-worded phrase is: " + output);


System.exit(0);
}
}</pre><hr />

Replies

  • sonic
    Offline / Send Message
    sonic polycounter lvl 18
    Does it have to be in a GUI? I assume so because of your code, but most of my intro classes used to use command line stuff only.
  • Striff
    Offline / Send Message
    Striff polycounter lvl 18
    It doesn't really matter. I would love help in which ever way I can get smile.gif
  • Keg
    Offline / Send Message
    Keg polycounter lvl 18
    All the help I am going to give: http://www.exampledepot.com/

    You don't learn by having someone else do your work. And generally command line is easier to start off with so avoid gui until you understand the basics of java itself.
  • sonic
    Offline / Send Message
    sonic polycounter lvl 18
    <font class="small">Code:</font><hr /><pre>import java.io.*;
    import java.lang.*;

    public class help
    {
    public static void main (String args[]) throws IOException
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String userInput = br.readLine();
    int wordends = userInput.indexOf(' ');
    String firstWord = userInput.substring(0, wordends);
    int stringLength = userInput.length();
    int beginNew = wordends + 1;
    String stringCheese = userInput.substring(beginNew, stringLength);
    stringCheese = stringCheese + " " + firstWord;
    System.out.println(stringCheese);
    }

    } </pre><hr />

    Since you couldn't use loops or conditionals that made it a pain and very messy tongue.gif

    The only reason I did it for you is so I can explain it to you. I found it a lot harder to learn without a programmer explaining to me what each thing does.

    On the first line of the main method I set up an instance of BufferedReader, and on the next line I set a string equal to the input taken by BufferedReader. On the next line I used the method indexOf to get the location in the string where the first space is used and set that to a variable (wordends). I then stored the first word of the input by assigning to a variable called firstWord using the substring method. The substring method works by grabbing whatever characters are between the locations you input (0, wordends). I then set an integer to the userInput string length using the length() method. Since we want the output to start after the first word along with the space, we set the starting location for the next substring to beginNew (which is wordends + 1). After we have the stringCheese string without the first word or the first space, we use basic concatenation to add the firstWord variable.

    Hope this helps!
  • Nilium
    Offline / Send Message
    Nilium polycounter lvl 18
    Fuck you, you gave him the answer. You should have explained how you would go about it and then let him try to write the code. But no, instead you did his homework for him.

    Fuck you.
  • Striff
    Offline / Send Message
    Striff polycounter lvl 18
    Sonic, THANK YOU so much for your help. I will defiantly read through the code and try to understand it. I appreciate it a lot. You just saved my weekend smile.gif

    Thanks for the link Keg. Looks like a good site.

    I would normally not ask for help like this, however my tutor was not able to help me this week and this assignment is due Monday. I don't have the time to read 100+ pages in a book when I cam carrying six other classes as well.
  • sonic
    Offline / Send Message
    sonic polycounter lvl 18
    [ QUOTE ]
    Fuck you, you gave him the answer. You should have explained how you would go about it and then let him try to write the code. But no, instead you did his homework for him.

    Fuck you.

    [/ QUOTE ]

    Wow Noel, your emoblog is true to your character. It sucks to learn programming when you have a shitty teacher and no one to guide you. I've always learned easier when I can see how a problem is done and have it explained to me, then I can do the exercise over myself. So calm down grandpa.
  • Keg
    Offline / Send Message
    Keg polycounter lvl 18
    I'm with Noel. You don't learn if you're shown the answer not to mention a route that's not taught to beginners. BufferedReaders and exception throwing are somewhat more advanced topics. A simple Scanner would have worked for reading input from the command line.
  • sonic
    Offline / Send Message
    sonic polycounter lvl 18
    Have you ever had a shitty college professor? Or even a shitty high school teacher? It is ridiculously frustrating when you have no direction and you are given a task and a book. I did it for him and explained each step so that he can learn from what I did. I had programmer friends in my beginning classes that would do the simpler things for me and show me exactly how they did it, and it helped me learn a lot quicker. Plus, I am here on my computer right now because I am finishing up some bullshit college work I shouldn't be doing on the weekend, so I feel his pain and wanted to help him out.

    And also I used BufferedReader in my very first Java class in high school many years ago when we were working on "Hello World" shit.
  • Striff
    Offline / Send Message
    Striff polycounter lvl 18
    Geez I didn't think it would be that big of a deal to come on here and ask for help.

    Don't people come on here and ask how to do something like normal mapping and people help them out? Whats the diffrence?
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    *Agrees with Sonic*

    I've been in numerous situations where teachers, instead of actualy doing their job and, well, teaching, just handed out assignments and told their students to figure it out on their own. Fuck them, if they dont want to do their job the student shouldnt be punished via poor grades and metal stress because of it.

    Also, whats wrong with showing someone how somethings done? Explaining in general terms how something works in any sort of programming language only works if the person who's having it explained to them has a good grasp of the fundamentals of said language. But if their just starting out then their going to need specifics, otherwise any minute mistake they make will break the whole thing. You can't tech a beginner the same way you teach a pro or someone in between. This is why its said that starting is always the hardest part for so many disciplins.
  • HarlequiN
    Offline / Send Message
    HarlequiN polycounter lvl 18
    I'm also with Sonic. It's not like we're talking 300 lines of code here - all Sonic's done is the code equivalent of a paintover.

    If we had someone in here asking for assistance with a texture would you give them a link to Ror's Journal and say "here you go, good luck"? Of course not, So why should it be any different for code.

    'm someone who's self taught (Javascript, not Java), and I've never asked for help with my code as I prefer to work it out myself. But I gotta tell you, if I wanted to know how something was done in a hurry I'd much rather someone just show me how to do what I need to do than piss about sending me on a wild goose chase.

    Should Striff look there and do other research first before coming to ask on here next time? Yes, I think he should, but I also think we shouldn't deny him straightforward asistance when he asks for it.

    "Fuck you" indeed. You can be such a twat sometimes Noel. smile.gif
  • Squid
    Offline / Send Message
    Squid polycounter lvl 18
    There is also the simple fact that Striff possibly learned a much more useful lesson than string manipulation in java. Interpreting and understanding other peoples code.

    I definately agree with the paint over analogy.

    smile.gif
  • Black_Dog
    Offline / Send Message
    Black_Dog polycounter lvl 17
    The thought of teaching programming fundamentals by having the student munge text into a dialogue box using Java is horrifying. Fucking horrifying.

    IMO newbies should be at the REPL hacking up Python (or Scheme, if they are bright).
  • Emil Mujanovic
    Offline / Send Message
    Emil Mujanovic polycounter lvl 18
    Good job Sonic, totally with you 100%.
    If you had posted just the answer, then that's a bit dodge (but in the end it would be up to Striff not to just cop out and just copy it straight). But you went step-by-step explaining how it all works and mad props to you for that!
    I too know what its like having teachers that just hand you a tute straight out of the application help file and send you on your way.
    Having said that, I'm on the same page as Harl, where I like to learn shit on my own. Though it is definitely handy having someone run you through it first. Saves you a whole lot of time trawling through pages and pages of useless crap.

    -caseyjones
  • HarlequiN
    Offline / Send Message
    HarlequiN polycounter lvl 18
    Per, I'm sorry, should I have given it a bigger smiley, or are you too not writing in all seriousness?

    (No smiley for you!)
Sign In or Register to comment.