At a loss with some simple java classwork. Please help.

Hello. I'm having a problem with some work that I wasn't able to finish in class. I am not very good at java AT ALL, and I'm really at a loss on how to finish up the program and get it to print what I want it to.
My task is:
"Write a program that asks for two words and then eliminates the second word from the first word.
For example:
forgot - go = fort
bedevil - bed = evil
bedevil - evil = bed
stupid - is = Hey, is is not found in stupid."
This is my code so far:
public class wordSubtraction
     public static String big = "bedevil";
     public static String small = "bed";
     public static void main(String[] args)
          elimWord(String big, String small);
     public static void elimWord(String big, String small)
          if(big.indexof(small)==-1)
               System.out.println(small + " isn't found in " + big);
          else
               big.substring(0, indexOf(small));
               small.substring(indexOf(small)+small.length());
               System.out.println(small + " + " + small.substring + " = " + big);
I keep getting this error:
/Users/mewmew/Desktop/wordSubtraction.java:8: ')' expected
          elimWord(String big, String small);
                                ^
1 errorI don't understand what this error means or how to fix it, it looks like I have all the parenthesis in there to me. Deleting or adding semi-colins, parethesis, brackets, or curly brackets just seems to give me more errors.
Any help is appreciated!

No it's not JJEdit. The errors are a good thing -
and each one has to be
dealt with. When you call a String method various
things have to be
correct:
(1) The name of the method - case is important.
(2) The arguments - the things in the parentheses -
have to be exactly
the sort of thing that the method expects. For
example if the method
expects an int argument and you give it a String
there will be problems
(3) The methods must be called using a String
variable and a dot. If
you just say "substring(whatever)" that's an error.
The compiler is
saying "substring of what?" You have to write
"something.substring(whatever)"
Also - because it will be important later - both
substring() and indexOf()
return a value. It is up to you to do something with
that value. Usually
you assign it to a variable.
Just for the record I got the follow from the String
API doumentation here:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Stri
ng.html
public int indexOf(String str) Returns the index
within this string of the
first occurrence of the specified substring.
public String substring(int beginIndex) Returns a new
string that is a
substring of this string. The substring begins with
the character at the
specified index and extends to the end of this
string.
public String substring(int beginIndex, int
endIndex)Returns a new
string that is a substring of this string. The
substring begins at the
specified beginIndex and extends to the character at
index endIndex - 1.
I would suggest you write elimWord() along these
lines:public static void elimWord(String big,
String small)
int pos = // find the index of small in big
if(pos == -1)
System.out.println(small + " isn't found in "
und in " + big);
else
String before = // find the bit before small
re small in big
String after = // find the bit after small in
small in big
System.out.println(big + " - " + small + " =
ll + " = " + before + after);
Thank you! That's very helpful and I feel that I'm THAT much more on my way to understanding what the heck I'm doing.
I'm trying, though...
Now I just gotta find out how to get the bits before and after small in big and solve these errors:
/Users/audreyeckel/Desktop/wordSubtraction.java:24: '.class' expected
          int pos = big.substring(0, int indexOf(small));
                                               ^
/Users/audreyeckel/Desktop/wordSubtraction.java:24: ')' expected
          int pos = big.substring(0, int indexOf(small));
                                                              ^
2 errorsI just hope I can finish it before it gets TOO late...it's about 2:26 AM here and this is due...TODAY!

Similar Messages

  • I need help with some simple code! Please read!

    hi everyone.
    I'm having problems with a piece of code, and i'd be extremely greatful if somebody could give me a hand with it. I'm totally new to java and have to make a program for my university degree, but i'm finding it extremely difficult, mainly due to my total lack of apptitude for this type of thing. I know this is easy stuff, but the books I have are no use so any help would be greatly appreciated.
    I have to write a program which uses two class files. I want one with the code to produce a simple button, and one to invoke it several times at different locations. I decided to write the program as one class file at first, and thought i'd be able to split it up at later. The program works fine when it is one class file. My book said that to split the two classes up, all i needed to do was change the second class to public, although this seems to not work at all. I'm at my wits end on this, and if anyone could correct my code I'd be eternally greatful.
    Here is the first class... (sorry about the lack of indentation)
    >>>>>>>>>>
    import java.awt.*;
    import java.applet.Applet;
    public class Phone extends Applet {
    private Image image;
    public void init() {
    setLayout(null);
    image = getImage(getDocumentBase(), "phone.jpg");}
    public void paint (Graphics g) {
    g.drawImage(image, 0, 0, 700, 530, this);
    PhoneButton myButton;
    myButton = new PhoneButton(20,20);
    >>>>>>>
    This is the second class....
    >>>>>>>
    public class PhoneButton {
    private Button butt;
    public PhoneButton(int a, int b, int c){
    setLayout(null);
    butt = new Button();
    butt.setBounds(a,b,20,20);
    add(butt);
    >>>>>>>>
    My compiler generates errors relating to Button, but i can't do anything to please it.
    Also, could anyone give me some pointers on how to add a different number or symbol to each button. That is what I added int c for, but i couldn't get it to work.
    Cheers in advance.
    Michael Morgan

    I found that there are 5 error in your code.
    1. You should import the "java.awt" package to the PhoneButton.java
    2. The PhoneButton is not a kind of Component. You cannot not add it to the Phone class
    3. the myButton = new PhoneButton(20, 20) does not provide enough parameters to create PhoneButton
    4. You cannot add a Button to a PhoneButton. Becaue the PhoneButton is not a kind of Container
    Fixed code:
    import java.awt.*;
    public class PhoneButton extends Button {
    public PhoneButton(int a, int b, int c){
         setBounds(a, b, 20, 20);
         setLabel(String.valueOf(c));
    ===========================================
    import java.awt.*;
    import java.applet.Applet;
    public class Phone extends Applet {
    private Image image;
    public void init() {
    setLayout(null);
    image = getImage(getDocumentBase(), "phone.jpg");}
    public void paint (Graphics g) {
    g.drawImage(image, 0, 0, 700, 530, this);
    PhoneButton myButton;
    myButton = new PhoneButton(20,20, 1);
    ======================
    Visual Paradigm for UML - Full Features UML CASE tool
    http://www.visual-paradigm.com/

  • Apple Airport newbie with some questions before purchasing - please help...

    Hello all,
    Please excuse my ignorance but despite looking through the relevant online manual I wish to check a couple of things before I purchase the Aiport Express (and then possibly regret it).
    I have a Windows XP laptop which connects to the internet through a wi-fi connection (access to the physical router is not available me) and I want to be able to play iTunes on my laptop through my hi-fi (wirelessly).
    Am I correct in thinking the Aiport Express will do this for me? If so is any extra equipment besides the necessary hi-fi to Airport express cable required?
    The Airport Express doesn't need to physically connect to the router does it? Or it doesn't need to become the router providing the wi-fi does it?
    How does 'AirTunes' factor into the setup and what is better about e.g. Aiport Extreme and why would you ever need an Airport card?
    I have no desire for using the Airport equipment as a router or home hub for printing etc. but just streaming iTunes to my hi-fi.
    Any help/clarification would be most appreciated. Many thanks in advance,
    Daniel

    djsuk43, Welcome to the discussion area!
    Am I correct in thinking the Aiport Express will do this for me?
    Yes
    The Airport Express doesn't need to physically connect to the router does it? Or it doesn't need to become the router providing the wi-fi does it?
    No and no.
    How does 'AirTunes' factor into the setup...
    It is simply the term Apple uses for streaming music via iTunes through the AirPort Express (AX).
    ...what is better about e.g. Aiport Extreme...
    The AirPort Extreme base station (AEBS) does not have an audio out port therefore you can't use it to stream music.
    The AEBS however does support Ethernet clients, multiple USB printer and multiple USB hard drives.
    ...and why would you ever need an Airport card?
    If you have an older Mac without built-in wireless you would add the appropriate AirPort card to give it wireless ability.

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

  • Hi, iam facing proble in synchronizing 4 ni 4472 cards input with pxi -6052e analog output. please help me out to sort out this problem

    hi, iam facing problem in synchronizing 4 ni 4472 cards input with pxi -6052e analog output. please help me out to sort out this problem

    Hi achyuth,
    Thank you for posting on the National Instruments forum.
    I am not sure what you are trying to do.  Are you trying to input and output at the
    same time?  Are you just trying to
    synchronize all of your inputs?  Do you
    want them to run off the same clock?  If
    you could, give me some more information so I can understand your problem
    better.
    In the meantime, this might help you:
    PXI Timing,
    Triggering, and Synchronization Capabilities of E-Series Multifunction Data
    Acquisition ...
    PXI Timing and Synchronization
    Thank You,
    Nick F.
    Applications Engineer

  • I can't see the animations on the website or access most of the options when I log in.Works perfect with Internet explorer though! Please help

    I can't see the animations on this page (looks like a very small image) and when I log in can't access/see some of the options in the website . The page however works perfect with Internet explorer though! Please help identify the kind of plugin/add-on needed to make it work.

    If you're using it in bright light, you may be getting sunlight through the back of the machine which can wash out the display.  The Apple logo on the back of the lid is actually a cut-out that uses the systems back light to make it glow.  Bright light (especially sunlight) can actually shine through the back.  As the users in the login are typically in the middle of the display, this is the area most likely to be washed out as that is where the Apple logo is.  You can try just putting your hand over the Apple logo on the back to block the sunlight when trying to log in.

  • How can i download old settings with firefox sync ? i formatted my computer thinking that the data will be restore on login , but it's only letting my sync firefox with mobile device , can someonr please help my ?

    how can i download old settings with firefox sync ? i formatted my computer thinking that the data will be restore on login , but it's only letting my sync firefox with mobile device , can someonr please help my ?

    '''Did you backup whatever bookmarks you did have on the computer ? '''
    Remember any restoring of bookmarks overwrites whatever he current set is, and you may not want to loose them.
    Even if up until now you have not made any backups of Desktop bookmarks Firefox will have backed up some of them into sets of daily bookmark backups. Once you have backed up your current set you could look at what it has by restoring those bookmarks, you may find one of those sets is fairly complete.
    By the way if you look at the profile files and folders that you should now have on the desktop you should see it contains a bookmarks backup folder, the size of the files within should indicate whether they contain anything.
    You need to go into the bookmarks library and try the restore option. Backup each set that you look at if it has anything of use in it, before trying the next set. With look one of those will be a fairly complete set of bookmarks.
    * USE '''Show All Bookmarks -> Import and Backup -> Restore '''
    ** see [[Restore bookmarks from backup or move them to another computer#w_restoring-from-backups]]_restoring-from-backups
    I do not use Firefox on mobiles, but before you try anything further you do need to backup the desktop bookmarks and learn what existing backups you have. Unless you master that you are in continual danger of overwriting and loosing bookmarks.
    Presumably you have already found this listing of help articles for mobiles
    * [/products/mobile/bookmarks]

  • HT4972 i have updated my itunes but when im restoring my iphone 5 phone it keeps coming up with 'unknown error occurred (3) please help as i cannot even turn my phone on now

    i have updated my itunes but when im restoring my iphone 5 phone it keeps coming up with 'unknown error occurred (3) please help as i cannot even turn my phone on now

    Hello there, BundyA.
    Error 3 is usually associated to security software settings. The following Knowledge Base article provides some great information and links for troubleshooting the issue:
    Resolve specific iTunes update and restore errors
    http://support.apple.com/kb/ts3694
    This section should prove useful:
    Configure your security software
    Check your security software and settings, which can block ports and prevent connection to Apple servers during update and restore.
    Common errors: 2, 4, 6, 9, 1000, 1611, 9006, 9807, 9844. Sometimes as a result of this issue, a device might stop responding during the restore process.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • My ipad mini does not restart when i press and hold the home and power buttons for a minute or more. what do i do? i really need to access some information on it. please help.

    my ipad mini does not restart when i press and hold the home and power buttons for a minute or more. what do i do? i really need to access some information on it. please help.

    You need to connect to iTunes and restore.
    iOS: Not responding or does not turn on
    You may need to put the device into recovery mode, this is covered in the link on this page.
    Did you back up the device?

  • Cannot install windows 7 on brand new mac mini with 256 g sdd? Please help.

    Cannot install windows 7 on brand new mac mini with 256 g sdd? Please help.
    Have tried all tricks found on the net and followed every advice from apple support.
    Still black screen with blinking curser when mini is rebooting following partitioning via bootcamp.
    Very nice and fast mashine, wouldnt like to return it.
    thanks allan

    Is that an Apple SSD?
    what model is it?
    Is there a firmware update if non Apple?
    Lion is not server version.
    Windows is ? ISO or retail?
    Google macmini Windows 7 SSD Apple Boot Camp

  • HT2953 i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    I was not complete clear.
    Since you never changed the settings in the advanced section of iTunes preferecnes, you have to chech that your music is really in the location setted in the folders reported in the advanced section.  If not you have 2 ways: reset the position of this folders or in the actual disk organisation or in the pointing on the preferences.
    If you press the reset button you just give to itunes its default setting as for the position of the music files: probably this will be a good choice if you have never changed any default preference.
    But before I would check the folders and see if the songs are really there
    In my iTune I have this, and I believe it is the default.
    Users/YOURHOMEFOLDERNAME/Music/iTunes/iTunes Music

  • Hi, All. Iam using Adobe Document Cloud. After saving a pdf document to this cloud, I am able to see my PC folders . How to disable this? Does my PC folders are also available across other PC's to access them with my Adobe ID? Please help me. Thanks

    Hi, All. Iam using Adobe Document Cloud. After saving a pdf document to this cloud, I am able to see my PC folders as well with a browsing option  . How to disable this? Does my PC folders will  also available across other PC's to access them with my Adobe ID? Please help me. Thanks in advance.

    Hi indi68632954,
    I can understand your concern & you need to worry about this, as your PC folders won't be available on other PC's as this option is just to browse through the files of the specific system on which you are working as shown in the screenshot below.
    Only the files uploaded on the Document cloud will be available over Internet using Adobe Document Cloud service upon the authentication of your Adobe ID & password.
    I hope this will answer your query.
    In case if you have any further query please let us know, we will be happy to assist you.
    Regards,
    Aadesh

  • My iPad 2 won't receive text messages and is not sharing any data with my iPhone 4. Please help!

    My iPad 2 won't receive text messages and is not sharing any data with my iPhone 4. Please help!

    The iPad receives Text Messages through Apple's iMessage feature. Make sure this is turned on on your phone. Also, text messages received at your phone number are not shared with the iPad. Make sure that iMessage texts are being sent to your EMAIL ADDRESS

  • TS1424 err = 3150 - this issue has started recently and continues to persist with all of my downloads - please help

    err = 3150 - this issue has started recently and continues to persist with all of my downloads - please help

    Is it error 3150 or -3150 ? If -3150 then have you tried the troubleshooting for that error number on this page : http://support.apple.com/kb/TS3297 ?
    "Error -3150"
    This alert is often related to a lost connection to the iTunes Store.
    If you encounter this alert and you have verified you have a connection to the Internet using Wi-Fi, please review AirPort and Bluetooth: Potential sources of wireless interference.
    If the issue persists, and you're using iTunes for Windows, you may need to flush your DNS and remove pop-up or ad-blockers.
    Finally, this can occur due to timeouts caused by security software.

  • HT4882 hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    Hello Kian,
    This may sound silly but if you put your hand over the isight camera, do the lights change on the keyboard?
    Ryan

Maybe you are looking for

  • Call ABAP function module from script?

    Hi, I have an ABAP function module, which works fine when I call it in a transformation. Since I don't need to execute this function for each record but rather for each file I process, I would like to move the call from the DataFlow to a script in th

  • How do I get audio from compressor to Studio Pro?

    I used the Compressor preset "DVD: Best Quality 90 minutes" "MPEG-2.6Mbps 2 pass" on my 8 minute video in order to create a movie to import into Studio Pro. I end up with a m2v file with no audio. If I try using the Dolby setting it makes a ac3 file

  • Location is WAY off, by half the world.

    the iphone location settings (time, maps) and all apps using them (yelp, google latitude, etc.) are all showing my location as being on the other side of the world. In Istanbul, Turkey when I am actually located on the east coast of the USA. I have r

  • List of psa tables

    Hello BW Experts, If I need a list of PSA tables. I can get it using /bic/b0000* in the se11 rite. please correct me if i am wrong. Thanks, BWer

  • Multi Approval "approverObjects" parameter

    We're trying to use the "Multi Approval" WF and it's asking me to put a parameter called "approverObjects"; for the "approvers" parameter we�re adding the List of approvers but for this one(approverObjects), it's different because it's expecting a li