I'm having trouble with "this" and method dependence

For my Data Structures course, we have to create a simple Word Processor. The constructor contains two stacks, left and right. The way the class populates the strings is pretty straight forward. Any text to the left of the cursor gets pushed onto the left stack and any text to the right of the cursor gets pushed onto the right stack (in reverse order). For example, the phrase "hello" with the cursor between the l's, would push h, then e, then l onto the left stack. o then l is pushed onto the right stack. Follow me so far?
Next, we have to implement several methods, such as moveLeft, moveRight, delete, insert, and moveToStart. There is also a toString() method which prints the two stacks as a String. The way I have my toString() method mapped out, is first to call the moveToStart() method. This method then pops all values from the left stack and pushes them onto the right stack (left: empty, right: h-e-l-l-o). So now, I simply pop each value from the right stack and store the values in a char[] array. The array is then returned as a String.
This data structure converts the stacks to a String fine, the only problem is preserving the original stacks. So I tried to copy the value of "this," which should correlate to the EditableString es2 (declared in main), to a temp EditableString, tempEs. I then call moveToStart on tempEs, and pop values from tempEs.right. This is all in hopes to preserve the original es2. However, as you could see from the output at the bottom is that toString() modifies es2. If it didn't, "Hello, how are you" would have printed twice. Instead, an empty string is printed.
There is obviously something wrong with my moveToStart(). Any suggestions? I apologize for not providing any comments in the code, it's just that I tried to save space. If any further explanation is necessary, don't hesitate to ask. Thanks.
public class EditableString {
private Stack left;
private Stack right;
private JavaStack l = new JavaStack();
private JavaStack r = new JavaStack();
private char[] text;
private static String cursor = new String("|");
private EditableString tempEs;
private Character characterObject;
private char test1;
public EditableString() {
left = new JavaStack();
right = new JavaStack();
public EditableString(String left, String right) {
new EditableString();
for (int i=0; i < left.length(); i++) {
characterObject = new Character(left.charAt(i));
l.push(characterObject);
for (int i = right.length(); i > 0; i--) {
characterObject = new Character(right.charAt(i-1));
r.push(characterObject);
this.left = l;
this.right = r;
public void moveToStart() {
while (! this.left.isEmpty())
this.right.push(this.left.pop());
public String toString() {
tempEs = this;
tempEs.moveToStart();
text = new char[(tempEs.right).size()];
for (int i=0; i < text.length; i++)
text[i] = ((Character) (tempEs.right).pop()).charValue();
return new String(text);
public static void main(String args[]) {
System.out.println("Starting Word processor!");
System.out.println("----------");
EditableString es2 = new EditableString("Hello, how", " are you");
System.out.println("es2: " + es2.toString());
System.out.println("es2: " + es2.toString());
/* Output:
Starting Word processor!
es2: Hello, how are you
es2:
*/

Ok, I tried to create a copy(Es) method and modified the toString() method as follows, but I am having the same problem. Ok, in order to test my methods, I print the various sizes of several stacks. In the toString() method, right after tempEs is declared, this.left=10, this.right=8 and tempEs.left=tempEs.right=0. After the copy method is invoked and assigned to tempEs, this.left=tempEs.left=10 and this.right=tempEs.right=8. Follow me?, this is where I have trouble.
I try to "pop" one value from tempEs.right to see if the action occurs on tempEs and not this. Well, it does. Right after the pop() method, this.left=tempEs.left=10 and this.right=tempEs.right=7. I need this.right to stay at 8. Why are these Editable Strings dependent?
And for the record, I'm not trying to "pay" anyone to do my homework. I am simply trying to pass, and in turn, graduate. This is the second time I am taking this course (failed it with style the 1st time) and desperately need to pass. I have VERY little Java background and this class is unfortunately required for my engineering degree. So, I am simply looking for some help with my 30+hour homework assignments.
public EditableString copy(EditableString ES) {
        EditableString xTemp = new EditableString();
        xTemp.left = ES.left;
        xTemp.right = ES.right;
        return xTemp;
    public String toString() {
        EditableString tempEs = new EditableString();
        tempEs = copy(this);
        tempEs.right.pop();
        tempEs.moveToStart();
        text = new char[(tempEs.right).size()];
        for (int i=0; i < text.length; i++)
            text[i] = ((Character) (tempEs.right).pop()).charValue();
        return new String(text);

Similar Messages

  • Several of us have a iPhone 6s and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Several of us have a iPhone 6plus and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Not having the problem, don't personally know anyone who is.

  • Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Hi FuzzyDunlopIsMe,
    Welcome to the Support Communities!
    It's possible that resetting your password multiple times has triggered this security.  Click on the link below for assistance with your Apple ID Account:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Here is some additional information regarding your Apple ID:
    Apple ID: 'This Apple ID has been disabled for security reasons' alert appears
    http://support.apple.com/kb/ts2446
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Click on My Apple ID to access and edit your account.
    Cheers,
    - Judy

  • Anyone having trouble with Splashtop and Maverick?

    Splash top will not run since installing Maverick.  I have uninstalled and reinstalled, but still no go.  Anyone else?

    I've been having trouble with this since I upgraded to iOS 7.0.2! Logged on tonight to see where I could log the problem with apple to get to fix in the next update! Seen on Facebook that others having same issue.
    I've also had a problem that when I put phone in to airplane mode it isn't reconnecting to the network afterwards!

  • I'm Having trouble with OWA and Certs after the Rollup 7 for SP3 installation. any idea? update 2961522-

    Hi, everyone.
    I'm Having trouble with OWA and Certs after the Rollup 7 for SP3 installation. any idea? update 2961522-
    after running get-OWAVirtualDirectory or test-OWAConnectivity i'm getting a message that says "OWA it's Orphan, No Metadata information can be found."
    I only have the OWA users impacted.- anywhere users, and ActiveSync are working well.-
    Thanks,
    Fabian Alberto Campo
    MCT-MCSA 2012-MCITP365-MCTS
    Fabián A. Campo H. Consultor tecnico @ IXO Ltda. MCT MCP MCTS MCSA HP-APS Cra. 67 No. 167 – 61 of 303 Bogotá, Colombia

    Hi Fabian,
    Is there any error code when user access their mailbox on OWA. Please confirm if there is no results returned in EMS when you run Get-OWAVirtualDirectory cmdlet. Also check whether there is any Event Logs related to OWA in Exchange.
    In IIS manager, make sure the OWA virtual directory is listed in the Default Web Site. In EMC, we can navigate to Server Configuration > Client Access, select server and turn to Outlook Web App tab. Then we can click Reset Virtual Directory in the right
    Actions pane to reset OWA virtual directory.
    Additionally, please restart IIS service by running iisreset /noforce from a Command Prompt window.
    Regards,
    Winnie Liang
    TechNet Community Support

  • I have an iPhone and just goy I pad but no computer I'm trying to synch them together but having trouble with iCloud and I can't seem to subscribe for iTunes match from either devise

    I have an iPhone and just goy I pad but no computer I'm trying to synch them together but having trouble with iCloud and I can't seem to subscribe for iTunes match from either devise

    You first have to subscribe to iTunes Match through iTunes on your computer and have your music library in iTunes uploaded/matched before you can enable it on your iOS devices (see http://www.apple.com/itunes/itunes-match/).  Without a computer you won't be able to use iTunes Match.

  • Importing photos from Iphone to computer and there is a message it is having trouble with this part way through on a phot and then stops

    I am having trouble importing photos onto my Mac book Pro from my Iphone...in the middle of the import I get a message stating that they are having trouble with one of my photos and then stops importing...want to save photos and clear the phone storage

    Hello cindysc
    Try importing the photos using Image Capture and see if that changes things. If it still gets stuck, try and email the photo to your self and download it that way.
    iOS: Unable to import photos to computer
    http://support.apple.com/kb/ts3195
    Regards,
    -Norm G.

  • I am having trouble with safari and most apps shutting down when I'm in the middle of stuff what do I need to do to resolve this?

    I am havering trouble with safari and apps shutting down on me all the time what can I do to resolve this problem. Thanks :-)

    Make sure you have enough free space on your iPad. With iOS 7 it is recommended that you have 15-20% of the storage space on the device free.  For a 16 GB device that is 2.4-3.2 GB free. For a 32 GB device that is 4.8-6.4 GB free. For a 64 GB device that is 9.6-12.8 GB free.
    Also try a reset. Press and hold the Home and Sleep buttons simultaneously until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.

  • Having trouble with Dreamweaver and fireworks willing to pay for support

    I'm new to the forum and i was hoping to get some help with
    dreamweaver and fireworks.
    I built a site on my own using dreamweaver 3 years ago but
    have forgotten almost everything. I am planning on building a new
    web site and have been messing with dreamweaver for over a week
    trying to figure it out, with little success. I bought a web
    building package years ago that included fireworks, dreamweaver,
    freehand and maybe more, but i lost my books on dreamweaver and
    fireworks somehow.
    Anyways, I was trying to learn dreamweaver 3 and fireworks
    and was having a lot of trouble with it. The dreamweaver bible
    assumes you know how to make a navigation bar using fireworks and
    that simply isnt the case for me. So I need help with that.
    Also, i have been having trouble with my template. This is
    how you save your basic page correct? For some reason it doesnt
    save the whole page for me. I figured out the editable regions
    part, I think, but since i didnt know how to make a navigation bar
    I made my own links out of text, and this part isnt saving with the
    template.
    I have a lot more questions but i think ive taken enough of
    your time. I am willing to pay someone to help me build this site,
    i cant afford a lot but i think my questions are pretty basic.
    Thanks

    There is a recent thread on the FW forum that may interest
    you - it's called
    "Firworks and HTML". The advice there applies in your case,
    too.
    One problem with your use of DW3 is this -
    the browser world has changed quite a bit in the almost 10
    years since DW3
    was released. Some (many?) of the behaviors in DW3 simply
    won't work any
    more because of these (significant) changes. Are you
    absolutely locked into
    using DW3?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "jfmalewitz" <[email protected]> wrote in
    message
    news:[email protected]...
    > I'm new to the forum and i was hoping to get some help
    with dreamweaver
    > and
    > fireworks.
    > I built a site on my own using dreamweaver 3 years ago
    but have forgotten
    > almost everything. I am planning on building a new web
    site and have been
    > messing with dreamweaver for over a week trying to
    figure it out, with
    > little
    > success. I bought a web building package years ago that
    included
    > fireworks,
    > dreamweaver, freehand and maybe more, but i lost my
    books on dreamweaver
    > and
    > fireworks somehow.
    > Anyways, I was trying to learn dreamweaver 3 and
    fireworks and was having
    > a
    > lot of trouble with it. The dreamweaver bible assumes
    you know how to make
    > a
    > navigation bar using fireworks and that simply isnt the
    case for me. So I
    > need
    > help with that.
    > Also, i have been having trouble with my template. This
    is how you save
    > your
    > basic page correct? For some reason it doesnt save the
    whole page for me.
    > I
    > figured out the editable regions part, I think, but
    since i didnt know how
    > to
    > make a navigation bar I made my own links out of text,
    and this part isnt
    > saving with the template.
    > I have a lot more questions but i think ive taken enough
    of your time. I
    > am
    > willing to pay someone to help me build this site, i
    cant afford a lot but
    > i
    > think my questions are pretty basic.
    > Thanks
    >

  • Having trouble with itunes and windows 8

    anyone else having trouble with windows 8 and itunes?  My computer doesn't seem to recognize my shuffle.

    A simple search would have answered such a silly question.

  • Having trouble with flash and linking to Sliding panels - PLEASE help

    Having trouble with Sliding panels and flash. Otherwise everything works fine but when I'm trying to implement the link
    <a href="#" onclick="sp1.showPanel('panel1'); return false;">Panel1</a>
    to a flash button I get confused. I have tried following
    on (press) {
    getURL("javascript:sp1.showPanel('panel1');");
    and it did not work. What would you suggest? I am desperate. Please help me! Any suggestions are highly appreciated!!!!

    Thanks for your answer!
    I have tried both sp1.ShowPanel('panel1'); and window.sp1.ShowPanel('panel1'); they both give blank window with [object]
    I have found a solution that works in other browsers, but not in IE. Well basicly it works, but after a few clicks IE freezes.
    on (press) {
    getURL("javascript:sp1.showPanel('panel1'); void(0);");
    Would you happen to have a solution other than that? I believe that the void(0); causes the IE to freeze.

  • TO ALL THOSE HAVING TROUBLE WITH ICHAT AND AIM ON MACBOOKS

    I've had a lot of trouble with AIM and iChat on my new Macbook, but I believe I've figured out the answers to all the problems I and others have encountered.
    Firstly, for those who's AIM continually crashes and displays the message "The application AIM unexpectedly shut down," my answer to your problem is too many sent messages. Watch the bar in the bottom left of your chat window, when it reaches red, your application will probably shut down.
    Secondly, for those experiencing difficulties with iChat, it's most likely a problem with communitcation between your wireless router and your computer. Try these steps:
    1. From the Apple menu, choose System Preferences.
    2. From the View, choose Sharing.
    3. Click the Firewall tab.
    4. Click New.
    5. From the Port Name pop-up menu, choose Other.
    If you have a Macbook, you'll probably have a TCP Port Number Bar and a UDP Port Number Bar. Try these steps:
    1. In the TCP Port Number(s) Bar, type: 5190, 5298
    2. In the UDP Port Number(s) Bar, type: 1024-5219, 5221, 5223-65535
    3. In the Description Bar, type: iChat AV
    4. Click OK
    5. Click Start above the window with your firewall settings, and make sure the box next to iChat AV is checked
    6. Relaunch iChat
    Good Luck! I hope this solves some of the problems that people have been encountering.

    Rob
    My Linksys is the WAG54G, which might be different from your WRT54G. Currently, UPnP is disabled and the Router ports are a bit of a mystery, because they're forwarded to an IP address that's outside of the current DHCP Address Range! Once I got it working, I was reluctant to change it even though it looked anomalous.
    The Firewall is on, with the iChat ports open that I listed in the previous post.
    My two regular buddies are my sons, who both use Trillian Pro on a Windows machine. Works pretty well despite occasional freezes or garbled sound.
    Hope you get sorted soon.
    Dave

  • Having trouble with pse7 and opening jpg files

    I have been using pse7 for quite some time and today I have started having trouble.  It is as if the program is "not responding" for a time.  So here is what is going on . . . I can open a file or group of files (jpg images) and then when I ctrl+o to open something new I can't see what is in the folders . . . and eventually it won't even let me open anything.  I will ctrl+o and the little blue circle will move, but then go back to the arrow without going to my folders.  I'm not sure if this is making any sense, but it is REALLY frustrating me!!!  I have restarted my computer several times today and it is not helping.  Last week I did update the driver for my printer and now I'm not able to print anything from PSE . . . I don't know if this is part of the problem.  I was getting the "not enough memory (RAM)" message last week as well.  I don't know if all of this is together, but it is driving me crazy!!!  I am in the process of downloading the pse9 trial and I'm hoping that this will help.
    I am working with windows7.
    thank you!!!

    You might have opened several images of large sizes.
    You can go to Edit menu > Preferences > Performance
    Move the slider to the right to increase the memory allocated to PSE
    Also, increase the Cache level.
    Restart PSE Editor
    The problem also can be, that you have several programs running on your system. You might want to close unwanted programs while working on several images in PSE. This also reduces the available memory for PSE to work on.
    Hope this solves your problem

  • Having trouble with rounding and if/else

    I am trying to write a program that reads 2 floating-point numbers and test if they're the same when rounded to 2 decimal places and whether they diff by less than 0.01. I'm having trouble compiling it, with errors such as
    "C:\Documents and Settings\John\My Documents\Test2.java:24: 'else' without 'if' else"
    C:\Documents and Settings\John\My Documents\Test2.java:18: cannot find symbol
    symbol  : method round(double,int)
    location: class java.lang.Math
         double round1 = Math.round(firstinput,2);
                             ^
    C:\Documents and Settings\John\My Documents\Test2.java:19: cannot find symbol
    symbol  : method round(double,int)
    location: class java.lang.Math
         double round2 = Math.round(secondinput,2);Here is the code:
    import java.util.Scanner;
    import java.text.NumberFormat;
    import java.math.*;
    import java.lang.Math;
    public class Test2
         public static void main( String args[] )
         Scanner sc = new Scanner( System.in);
         System.out.println("Enter your first floating-point number: ");
         double firstinput = sc.nextDouble();
         System.out.println("Enter your second floating-point number: ");
         double secondinput = sc.nextDouble();
         double round1 = Math.round(firstinput,2);
         double round2 = Math.round(secondinput,2);
         double total = round1 - round2;
        if(round1 == round2);
        System.out.print("They are the same when rounded to two decimal places. \n");
        else
        System.out.print("They are not the same when rounded to two decimal places. \n");
         if(total<1.01 && total>0.99)
         System.out.print("They differ by less than 0.01. \n");
         else
         System.out.print("They do not differ by less than 0.01. \n");
    }

    Are you restricted to Math.round()? Try reading about DecimalFormat:
    http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html
    Your code with DecimalFormat:
    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Test2 {
        public static void main(String[] args) {
            DecimalFormat df = new DecimalFormat("#.##");
            Scanner sc = new Scanner( System.in);
            System.out.println("Enter your first floating-point number: ");
            double firstinput = sc.nextDouble();
            System.out.println("Enter your second floating-point number: ");
            double secondinput = sc.nextDouble();
            double round1 = Double.parseDouble(df.format(firstinput));
            double round2 = Double.parseDouble(df.format(secondinput));
            double total = round1 - round2;
            if(round1 == round2)
                System.out.print("They are the same when rounded to two decimal places. \n");
            else {
                System.out.print("They are not the same when rounded to two decimal places. \n");
                if(total<1.01 && total>0.99) //<== Rather redundant, why not just use total == 1
                    System.out.print("They differ by less than 0.01. \n"); //<== From the above if statement, it seems if you are looking to see if the 2 numbers differ by less than 1.00, and not 0.01. The same goes for the else statement below
                else
                    System.out.print("They do not differ by less than 0.01. \n");
    }Also, when I ran your program with the latter code and entered two same floating point numbers, it also printed out "They do not differ by less than 0.01." I've added curly brackets around the outer else statement to ensure that it does not happen. It's best to use curly brackets in structured statements if their function exceeds more than one line; for stability and legibility.
    Also, read my comments.

  • So sick of having trouble with Java and Mac!

    I bought myself a brand new MacBook Pro OS X 10.5.8 for around a year ago. Since the first month I've had so many problems with my Java. It's eighter not working, or its is so slow that you can't work with it, at all.
    Yesterday I was playing a game, were you're in need of Java. It worked perfectly. Then suddenly, it stopped again. And I tought, since I had not used it for a while, I just had to update it. So I clicked at the "software update" and updated everything. I don't think Java was at the list. Still wasn't working. So I went to Apple.com and searched for the "Mac OS X 10.5 update 10" and found it. I downloaded it, and installed it about five times or something, still not working. I've tried everything that came to my mind to try fixing it, but nothing works. What can I do? I'm so sick of having this problem every time I'm in use of the mac. Realy start to regreat the expensive bought of this mac.
    Please, someone help me. I hate the tought of wasting 16 000,- Nok at this pc, when it's not working the way I'm using it..
    And sorry for the bad english, I'm only 15..

    Hei Kristine, er engelsk ikke så ille!
    Very Important, how much Free Space is on your Hard Drive first of all? Click on the Macintosh HD on the Desktop, then do a Get Info on it.
    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

Maybe you are looking for

  • OSB Service Deployment

    I am trying to expose web services from EJB as OSB proxy services. Basically, what I have done so far is, import WSDL of web services from URL, create business service and proxy service, and export the project as sbconfig.jar. But when I deploy the s

  • Link to bookmark

    I have a web site and I would like to insert a link that says bookmark this page and have the favorites automatically pop up. Is this possible? Thanks again!

  • Hwnd and acrobat plugin

    I'm using opengl and i have a question : is possible to get an hwnd from a pdf document that can use it for draw with opengl through a plugin? How i can render with opengl in acrobat sdk? thanks.

  • Regarding migration

    Hello Gurus I want to migrate some of my databases to another server at one client.The client is asking for minimum downtime. Like i have a database with 200GB.Now i have below options to migrate. 1)USE rman as downtime would be less.I need to take b

  • Problem During Part-2

    hi all, i do part-1 after '103' and after that i do MIGO and then i do PART-2, but problem is that when i m going to do PART-2 then it is giving message 'No Part-1 Exists for availing credit in Excise Invoice 186 2009.'. can anyone please tell me the