Could anyone help me please?

I have a problem in a program I have to write for school. Is there a place where I could send my work and someone could help me out. My
problem is a very big one and I have no idea how I could solve
it on my on.
Thank you,

I want to use the info I recived in class F674913 in class func but it's such a mess, I woren you it's a big problem here is my program.
Sorry in advance, Riki
import java.io.*;
import java.util.*;
class F674913
     public static void main (String [] args) throws IOException
     Element pw=new polyElement(2,3);
     Element po=new polyElement(7,3);
     Element plus=pw.addElement(pw,po);
     Element mult=pw.multElement(pw,po);
     pw.printElement(plus);
     pw.printElement(mult);
          double ran = Math.random();
     Func first = kelet1(ran);
     Func second = kelet2(ran);
     first.addFunc(first,second);
     public static Func kelet1(double ran) throws IOException
          Func first=null;
          BufferedReader stdin = new BufferedReader
     (new InputStreamReader (System.in));
     String str1;
     StringTokenizer input1;
     StringTokenizer exp1;
     StringTokenizer selfexp1;
     if(ran>=0.5)
          System.out.println("PLEASE ENTER 2 POLYNOMIALS");
          System.out.println("ENTER THE FIRST ONE: ");          
str1=stdin.readLine();
input1 = new StringTokenizer(str1,"+");
Element [] arr1 = new Element[input1.countTokens()];
System.out.println("num of tokens: "+arr1.length);
for(int i=0;input1.hasMoreTokens();i++)
String oreh=input1.nextToken();
if((oreh.indexOf("x^")==-1)&&(oreh.indexOf("x")==-1))
System.out.println("Token "+i+" has the coef: "+oreh+" and has the power: 0");
arr1=new polyElement(Integer.parseInt(oreh),0);
else
String del=" \t\n\rx^";
exp1=new StringTokenizer(oreh,del);
selfexp1=new StringTokenizer(oreh,del);
int y = selfexp1.countTokens();
System.out.println("y: "+y);
switch(y)
     case 0:
     arr1[i]=new polyElement(1,1);
     System.out.println("Token "+i+" has the coef: 1 and has the power: 1");
     break;
     case 1:
     if(oreh.indexOf("^")!=-1){
     arr1[i]=new polyElement(1,Integer.parseInt(selfexp1.nextToken()));
     System.out.println("Token "+i+" has the coef: 1 and has the power: "+Integer.parseInt(exp1.nextToken()));
     else{
     arr1[i]=new polyElement(Integer.parseInt(selfexp1.nextToken()),1);
     System.out.println("Token "+i+" has the coef: "+Integer.parseInt(exp1.nextToken())+" and has the power: 1");
     break;
     case 2:
arr1[i]=new polyElement(Integer.parseInt(selfexp1.nextToken()),Integer.parseInt(selfexp1.nextToken()));
System.out.println("Token "+i+" has the coef:"+Integer.parseInt(exp1.nextToken())+"and has the power:"+Integer.parseInt(exp1.nextToken()));
     break;
}//end switch
}//end else
}//end for
first=new Func(arr1,"polynomial");
}//end if
else
System.out.println("PLEASE ENTER 2 POWER FUNCTION");
          System.out.println("ENTER THE FIRST ONE: ");
          str1 = stdin.readLine();
          input1 = new StringTokenizer(str1,"+");
Element [] arr1 = new Element[input1.countTokens()];
System.out.println("num of tokend: "+arr1.length);
for(int i=0;input1.hasMoreTokens();i++)
String oreh = input1.nextToken();
if(oreh.indexOf("^x")==-1)
System.out.println("Token "+i+" has the coef: "+oreh+" and has the base: 1");
arr1[i]=new powerElement(Integer.parseInt(oreh),1);
else
     String del = " \t\n\r*^";
     exp1=new StringTokenizer(oreh,del);
selfexp1=new StringTokenizer(oreh,del);
int y = selfexp1.countTokens();
switch(y)
     case 2:
arr1[i]=new powerElement(1,Integer.parseInt(selfexp1.nextToken()));
System.out.println("Token "+i+" has the coef: 1 and has the base:"+Integer.parseInt(exp1.nextToken()));
     break;
     case 3:
     arr1[i]=new powerElement(Integer.parseInt(selfexp1.nextToken()),Integer.parseInt(selfexp1.nextToken()));
     System.out.println("Token "+i+" has the coef: "+Integer.parseInt(exp1.nextToken())+" and has the base:"+Integer.parseInt(exp1.nextToken()));
     break;
}//end switch
}//end else
}//end for
first=new Func(arr1,"power function");
     }//end else
     return first;
     public static Func kelet2(double ran) throws IOException
          Func second=null;
     BufferedReader stdin = new BufferedReader
     (new InputStreamReader (System.in));
     String str2;
     StringTokenizer input2;
     StringTokenizer exp2;
     StringTokenizer selfexp2;
     if(ran>=0.5)
          System.out.println("ENTER THE SECOND ONE: ");
str2 = stdin.readLine();
input2 = new StringTokenizer(str2,"+");
Element [] arr2 = new Element[input2.countTokens()];
System.out.println("num of tokend: "+arr2.length);
for(int i=0;input2.hasMoreTokens();i++)
String oreh=input2.nextToken();
if((oreh.indexOf("x^")==-1)&&(oreh.indexOf("x")==-1))
System.out.println("Token "+i+" has the coef: "+oreh+" and has the power: 0");
arr2[i]=new polyElement(Integer.parseInt(oreh),1);
else
String del=" \t\n\rx^";
exp2=new StringTokenizer(oreh,del);
selfexp2=new StringTokenizer(oreh,del);
int y = selfexp2.countTokens();
System.out.println("y: "+y);
switch(y)
     case 0:
     arr2[i]=new polyElement(1,1);
     System.out.println("Token "+i+" has the coef: 1 and has the power: 1");
     break;
     case 1:
     if(oreh.indexOf("^")!=-1){
     arr2[i]=new polyElement(1,Integer.parseInt(selfexp2.nextToken()));
     System.out.println("Token "+i+" has the coef: 1 and has the power: "+Integer.parseInt(exp2.nextToken()));
     else{
     arr2[i]=new polyElement(Integer.parseInt(selfexp2.nextToken()),1);
     System.out.println("Token "+i+" has the coef: "+Integer.parseInt(exp2.nextToken())+" and has the power: 1");
     break;
     case 2:
arr2[i]=new polyElement(Integer.parseInt(selfexp2.nextToken()),Integer.parseInt(selfexp2.nextToken()));
System.out.println("Token "+i+" has the coef:"+Integer.parseInt(exp2.nextToken())+"and has the power:"+Integer.parseInt(exp2.nextToken()));
     break;
}//end switch
}//end else
}//end for
second=new Func(arr2,"polynomial");     
}//end if
else
          System.out.println("ENTER THE SECOND ONE: ");
          str2 = stdin.readLine();
          input2 = new StringTokenizer(str2,"+");
Element [] arr2 = new Element[input2.countTokens()];
System.out.println("num of tokend: "+arr2.length);
for(int i=0;input2.hasMoreTokens();i++)
String oreh = input2.nextToken();
if(oreh.indexOf("^x")==-1)
System.out.println("Token "+i+" has the coef: "+oreh+" and has the base: 1");
arr2[i]=new powerElement(Integer.parseInt(oreh),1);
else
     String del = " \t\n\r*^";
     exp2=new StringTokenizer(oreh,del);
selfexp2=new StringTokenizer(oreh,del);
int y = selfexp2.countTokens();
switch(y)
     case 2:
arr2[i]=new powerElement(1,Integer.parseInt(selfexp2.nextToken()));
System.out.println("Token "+i+" has the coef: 1 and has the base: "+Integer.parseInt(exp2.nextToken()));
     break;
     case 3:
     arr2[i]=new powerElement(Integer.parseInt(selfexp2.nextToken()),Integer.parseInt(selfexp2.nextToken()));
     System.out.println("Token "+i+" has the coef: "+Integer.parseInt(exp2.nextToken())+" and has the base: "+Integer.parseInt(exp2.nextToken()));
     break;
}//end switch
}//end else
}//end for
second=new Func(arr2,"power function");     
return second;
}//end kelet2()
}//end class F
abstract class Element
     public abstract Element addElement(Element el1,Element el2);
public abstract Element multElement(Element el1,Element el2);
public abstract void printElement(Element el);
public abstract boolean canBeAdded(Element pl,Element po);
public abstract int getPower();
public abstract int getCoef();
class polyElement extends Element
     private int coef;
private int power;
public polyElement(int c, int p)
     coef=c;
     power=p;
}//end constructor
public int getPower()
return power;
}//end getPower
public int getCoef()
     return coef;
}//end getCoef
public boolean canBeAdded(Element pl,Element po)
     return(pl.getPower()==po.getPower());
}//end canBeAdded
public Element addElement(Element pl,Element po)
{System.out.println("addElement");
     Element plus=null;
     if(canBeAdded(pl,po)==true)
     int     c1=pl.getCoef();
          int c2=po.getCoef();
          int p=po.getPower();
          plus=new polyElement(c1+c2,p);
     }//end if
     else
     System.out.println("cannot be added!");
     return plus;
}//end addElement
public Element multElement(Element pl,Element po)
int c1 = pl.getCoef();
int c2 = po.getCoef();
int p1 = pl.getPower();
int p2 = po.getPower();
     Element mult = new polyElement(c1*c2,p1+p2);
          return mult;
}//end multElement
public void printElement(Element pl)
     System.out.println("("+pl.getCoef()+","+pl.getPower()+")");
class powerElement extends Element
     private int base;
private int coef;
public powerElement(int c, int b)
coef=c;     
base=b;
}//end constructor
public int getPower()
     return base;
}//end get the base
public int getCoef()
     return coef;
}//end getCoef
public boolean canBeAdded(Element pw,Element po)
return(pw.getPower()==po.getPower());
public Element addElement(Element pw,Element po)
     Element plus=null;
     if(canBeAdded(pw,po)==true)
     int     c1=pw.getCoef();
          int c2=po.getCoef();
          int b=po.getPower();
          plus=new powerElement(c1+c2,b);
     }//end if
     else
     System.out.println("cannot be added!");
     return plus;
public Element multElement(Element pw,Element po)
     int c1 = pw.getCoef();
int c2 = po.getCoef();
int b1 = pw.getPower();
int b2 = po.getPower();
     Element mult = new powerElement(c1*c2,b1*b2);
          return mult;
public void printElement(Element pw)
     System.out.println("("+pw.getCoef()+","+pw.getPower()+")");
class Func
     private int len;
private Element [] array;
private String typefunc;
public Func(String expression , String type)
     typefunc=type;
public Func(Element[] arr , String type)
     //System.out.println(arr[1]);
     array=arr;
//     System.out.println(array[1]);
     typefunc=type;
     /*for(int i=0;i<=array.length;i++)
     array[i]=arr[i];
     System.out.println(array[1]);*/
public Func addFunc(Func f1,Func f2)
Element [] arr1=f1.getArr(f1);
Element [] arr2=f2.getArr(f2);
Element [] arr3=null;
if(typefunc=="polynomial")
     arr3=new polyElement[(arr1.length+arr2.length)];
     for(int k=0;k<arr3.length;k++)
     {System.out.println("!");     
          for(int i=0;i<arr1.length;i++)
          {System.out.println("!!");
           for(int j=0;j<arr2.length;j++)     
            arr3[k]=arr1[i].addElement(arr1[i],arr2[j]);
     System.out.println("!!!");
     if (arr3[k]==null)
          arr3[k]=arr1[i];
          System.out.println("!!!!");
}//end for[i]
}//end for [k]
}//end if
for(int i=0;i<arr3.length;i++)
arr3[i].printElement(arr3[i]);
Func third = new Func(arr3,typefunc);
return third;
}//end addFunc
public Func multFunc (Func f)
{return null;
public void printFunc( )
private Element [] getArr(Func f)
     System.out.println("SSS");
     System.out.println(array[0]);
     return array;
}//end getArr
}// end Func

Similar Messages

  • After installing Mavericks on my MacBook Pro 2009 (japanese keyboard) the layout doesn't work. I mean if I press the @ button the è symbol comes out. I tried to change the layout in Preferences but doesn't work. Could anyone help me please?

    Hi there
    after installing Mavericks on my macbookpro 2009 (Japanese keyboards) the layout doesn't work anymore. I mean, if I press the "@" button the "è" symbol comes out. I did already change the layout in the Preferences but it didn't work.
    Could anyone help me please?

    Apple has changed the way Kotoeri keyboard layouts work.  You should be able to get normal behavior if you activate the US layout and switch to that just before using Kotoeri.  Here is also an Apple note on the topic with another suggestion:
    http://support.apple.com/kb/TS5284
    Be sure to tell Apple you want this changed back to the way if was in 10.8 and earlier via
    http://www.apple.com/feedback
    If you know Japanese well, you might ask on the Japanese discussions whether someone has found a better fix for this:
    https://discussionsjapan.apple.com

  • Hi, recently my MacBook pro 13" late 2011 model stopped powering up. I did looked into the internet they were saying memory problem. when I took it to Apple service center they said mother board needs to be replaced. could anyone help me please?

    my late 2011 MacBook pro stopped powering up. Service people are saying motherboard needs to be replaced. The worst part is motherboard cost is 2/3 of the laptop cost. Could anyone help me to understand the issue please?

    The issue is simple. Your Mac computer has failed because of a faulty Logic, Mother, board. Happens all the time with many make and model notebooks
    Yes Apple Mac computers, even though more expensive than most any other brand, have these problems just like all the rest.
    Only thing you can do is either pay to have the logic board changed or buy a new computer.

  • I bought an used ipod touch gen 4 but I can't check the warranty status of my device. Could anyone help me please!

    I did use the serial number of my ipod to check on Apple website but there is no result for my ipod. They required me to provide the purchase date, which I don't know because my ipod is a 2nd hand device. I tried to reset my ipod and activate it again but it doesn't work and itunes gives me an error message.
    How could I check my warranty status and the purchase date?

    You can try contacting Apple:
    Apple - Support - iPod touch - Contact Us
    Maybe we can help you with the problem. What is the wording of the error message you are getting? The following lists the common errors and their resolution.
    http://support.apple.com/kb/TS3694

  • My 160gb 7th generation shows "127gb" Could anyone help me please??

    OK! it's not like im going to fill up the classic, iv'e only used 15gb! but basically.. my ipod broke like a month ago.. due to super glueing on the case and destroying the battery connecter.. but the hard drive has been lying around for some time.. so it turns out that the 120gb 6th generation ipod classic works with the 160gb 7th generation.. the motherboards are the exact same.. so I got a used 120gb and poped my hard drive in there.. works fine.. but had to restore it.. before that I backed it up.. eureka.. I had my classing back
    Only one problem is this.. why is 127gb come up? Im using a brand new windows 7 laptop? could this be a computer issue?

    Woow I am searching quite a while on this board
    this is a good similare issue I have created.
    I seems (for now self inflicted) by inserting a 160Gb disc into an 120GB ipod and having NOT LESS but more then120 yeah.....127 GB it works. (I noticed most people ran right over the facts....its more than 120.....)
    Happiness for me here as well. But is there a way back ?
    Firmware issues prevent me from going back.
    Also the disc came from a grey 160 going into a grey 120 and now showing grey in a black 160. (as 127) and not working.  But I can read as a external disc. Still iTunes can't read (it says......I can)
    Hope this helps a bit.

  • [b]Hi could anyone help me - Grid on image[/b]

    Hi could anyone help me please it is URGENT.
    I am trying to create a grid in a Panel which has a image. I want to strech the image by using the grid. Here is an exmple of what i mean
    http://www.ssec.wisc.edu/~curtis/stretch.html
    Thank you

    try searching the forum, this issue was discussed earlier

  • I have just tried to connect my Mac book pro to an LG Plasma TV via an iWires Mini DisplayPort to HDMI cable. All I get on my TV is the Mac wallpaper and nothing else. I am missing something really silly, could anyone help please.

    I have just tried to connect my Mac book pro to an LG Plasma TV via an iWires Mini DisplayPort to HDMI cable. All I get on my TV is the Mac wallpaper and nothing else. I am missing something really silly, could anyone help please.

    Hi there. I also bought an iWires mini Display port to HDMI cable and have an LG LED/LCD TV. I plugged it in to my MB Pro and followed the very small writing that came in the package and got both audio and video going. You need to change the audio settings from within System Preferences on your Mac to select your TV as the audio output.
    My concern is the data latency - do you experience a delay between moving your mouse on the MBPro and the TV displaying the movement? It is only a fraction of a second, but certainly enough to be annoying, especially in a cable as expensive as the iWire.

  • HT1338 Hello, i currently acquired a Mac Book Pro and running Mac Os X 10.8.3, but i have failed to get the driver for my canon inkjet printer. could anyone help me out please? Thank you

    Hello, i currently acquired a Mac Book Pro and running Mac Os X 10.8.3, but i have failed to get the driver for my canon inkjet printer. could anyone help me out please? Thank you

    You may be able to download it fom here:
    Printer and Scanner software available for download:
    http://support.apple.com/kb/HT3669?viewlocale=en_US

  • I erase my mac book pro to factory setting and cannot re-install the software. I received a message saying my Apple ID has not yet used with the App store. Please review your account information. Could anyone help please. I need to re-install my os.

    I erase my mac book pro to factory setting and cannot re-install the software. I received a message saying my Apple ID has not yet used with the App store. Please review your account information. Could anyone help please. I need to re-install my os.

    Use Internet Recovery. You shouldn't need an AppleID. http://support.apple.com/kb/ht4718
    Internet Recovery will install the OS that shipped with the Mac. You can then upgrade to Mavericks if that was not it.
    Do you have an App Store account? Did you ever use it to install the OS?

  • Could anyone help me out with this please?

    Hi all,
    I have always had a little problem messing with gradients, when creating images using them I tend to try and make things to perfect and then get very frustrated. This is the case again today
    I have attached two images, one light and one darker. Could anyone help me out recreating these using FW please?
    I am not after the letters in the center, I am just trying to create the background and the floor of the image with all its gradients and shadows.
    Any help greatly appreciated

    No I don't, never heard of that

  • HT4967 "In the ICLOUD section of iCal" - I don't have this on my Mac iCal. How would I get it? I currently have an empty iCal on iCloud. I urgently need to back up my iCal, Could anyone help please? This is SO frustrating.

    Sorry. This is where my question should be....
    "In the ICLOUD section of iCal" - I don't have this on my Mac iCal. How would I get it? I currently have an empty iCal on iCloud. I urgently need to back up my iCal, Could anyone help please? This is SO frustrating.

    Have you enabled iCloud syncing for calendars on your mac, which requires OS X Lion (10.7.2)? See http://www.apple.com/icloud/setup/mac.html.

  • I phone4 is dead, not carging, not turning on, doing absolutely nothing!  have tried all the buttons etc and linked it up to my computer, no nothing...its just dead!? whats going on, could anyone help please?? its only 3 months old, poor thing.. Mel

    could anyone help, just baffled, my i phone is literllly dead for no reason. i thought the battery had ran out, thou it had plenty left... i have tried to charge it and no life. also have plugged it in with my computer, again no life or aknowledgement... why? how can i fix it? Can i or is it the end of the road for my 3 month old Iphone 4???

    My 3GS did the exact same thing today at about the same time. Thanks for the advice, because Apple was about to charge me $30 to tell me that!

  • My iPhone 5 rear camera was not working, now the rear camera is also not working. I have procured the phone in 2012 from San Fransico. USA Can anyone help me, please?

    My iPhone 5 rear camera was not working, now the rear camera is also not working. I have procured the phone in 2012 from San Fransico. USA Can anyone help me, please?

    No one here can help you. If your phone is no longer under warranty, a third-party repair shop will most likely be your best bet. You can't mail the phone to Apple, in the US, as Apple does not accept international shipments. You could mail it to a friend/relative, in the US, & they could take it to an Apple store for you. Some Apple stores repair iPhones. Otherwise, you're looking at an out of warranty replacement.
    Good luck.

  • Hi, Could anyone help me with variables in BEx

    Hi,
      I want to know what a Variable is,when and how it is used in BEx Reporting. I am aware that Variables are very important in BEx, but i don't know where to use it. I know how to create a query report,but where will i use this variables and how,while creating one.
    Could anyone help me through this step by step.
    With Thanks,
    Siva.

    Hi Siva,
    Please go through the info here. It is very helpful:
    http://help.sap.com/saphelp_nw04/helpdata/en/f1/0a56a7e09411d2acb90000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/ac/789b3c4d4d8d15e10000000a114084/content.htm

  • ReadString problem!! could anyone help me take a look

    hi... i am doing a music Cd list program. there are two operation i need to do 1) insertion and 2) deletion. i have implemented my own sortList to do it... i work fine when i do the insertion to the list but it can`t perform well on deletion.. However, i am sure that my list deletion algoritm is totally correct... i perform two test as following to ensure my deletion is correct..but i think the problem is on my readString fucntoon ...could anyone help me take a look!!
    public class SortedListTesting
         SortedList musicCdList = new SortedList();
         ReadOperation theRo = new ReadOperation();
         //ErrorCheckingOperation theEco = new ErrorCheckingOperation();
         MusicCd temp;
         public void insertCdWithReadStringFunction()
              String musicCdsTitle;
              //try to prompt the user `s cd `s title for insertion to our List
              musicCdsTitle = theRo.readString("Please enter your CD`s title : ");
              musicCdList.insert(new MusicCd(musicCdsTitle));
              System.out.println("Number of items in the list: "
                                         + musicCdList.getNumberOfItems() + "\n" + musicCdList.toString() );
         public void deleteCdWithReadStringFunction()
              try
                   //try to prompt the user `s delected cd `s title
                   String keyword = theRo.readString("Please enter CD `s title to be delected from SMOA : ") ;
                   // System.out.println("The CD that you just deleted is " + keyword);
                   temp = musicCdList.delete(keyword);
                   System.out.println("Number of items in the list: "
                                  + musicCdList.getNumberOfItems() + "\n" + temp );
              catch ( InvalidDataException errorMsg )
                   System.out.println( errorMsg.getMessage() + "\n" );
                   System.out.println("Now, We have " + musicCdList.getNumberOfItems() + " items in the list, and the items as following  :\n" + musicCdList.toString() );
         public void insertCd()
              String musicCdsTitle;
              //try to input the string directly to our list
              musicCdsTitle = "ann";//theRo.readString("Please enter your CD`s title : ");
              musicCdList.insert(new MusicCd(musicCdsTitle));
              System.out.println("Now, the number of items in the list: "
                               + musicCdList.getNumberOfItems() + "\n" + musicCdList.toString() );
         public void deleteCd()
                            try
                              //try to input the String directly
                              String keyword = "ann"; //theRo.readString("Please enter CD `s title to be delected from SMOA : ") ;
                              System.out.println("The CD that you just deleted is " + keyword);
                              temp = musicCdList.delete(keyword);
                                 //System.out.println("Number of items in the list: "
                                 //                     + musicCdList.getNumberOfItems() + "\n" + temp );
                         catch ( InvalidDataException errorMsg )
                              System.out.println( errorMsg.getMessage() + "\n" );
                        System.out.println("Now, We have " + musicCdList.getNumberOfItems() + " items in the list, and the items as following  :\n" + musicCdList.toString() );
         public static void main(String[] args)
              SortedListTesting st = new SortedListTesting();
              //These two testing i am trying to show that my list is working fine for inseting and deleting
              //i try to input the cd `s title name " ivan " by my readString function, it work fine for insertion
              //but it is fail in delete fuction..it shows that "ivan not found: cannot be deleted" ...At first,
              //i think it is my delete function problem..but it is not my delete function problem...cos it work fine if
              //input the string directly from the function...i think the issues works on my readString fucntion
              //i try a milllion of time but i still got the same problem ...pls help....
              System.out.println("\t...Testing for input from readString fuction...\t");
              st.insertCdWithReadStringFunction();
              st.deleteCdWithReadStringFunction();
              //it work fine for input the string directly in the function, it show as following...
              System.out.println("\t...Testing for input the string directly ...\t");
              st.insertCd();
              st.deleteCd();
    javac SortedListTesting.java
    Exit code: 0
    java SortedListTesting     ...Testing for input from readString fuction...     
    Please enter your CD`s title : ivan   <<-inserting the cd`s title to our list
    Number of items in the list: 1     <<- sucessfully insert to our list
    Title: ivan 
    Please enter CD `s title to be delected from SMOA : ivan  <<- try to delete from our list, i type "ivan" here
    ivan not found: cannot be deleted    <<- problem occur , it should be fine in there
    Now, We have 1 items in the list, and the items as following  :
    Title: ivan         <<- it should not be shown
         ...Testing for input the string directly ...     
    Now, the number of items in the list: 2
    Title: ann   <<- i pass "ann" String directly to insertion function
    Title: ivan   <<- it is the left over from the preivous process
    The CD that you just deleted is ann   <<- i pass " ann" String directly to my deletion
    Now, We have 1 items in the list, and the items as following  : <<- it successfully delete .... it prove that my deletion function is working properly....i think it is on readString problem..
    Title: ivan
    Exit code: 0*/
    //it seems that the readString function read the string
    //at the first time does not match the second time
    //reading, it makes it can`t find the stuff from the list ..
    import java.util.*;
    public class ReadOperation{
         //pls help check here....thx
         public String readString(String userInstruction)
              String aString = null;
              try
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aString = scan.nextLine();
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aString;
         public char readTheFirstChar(String userInstruction)
              char aChar = ' ';
              String strSelection = null;
              try
                   //char charSelection;
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   strSelection = scan.next();
                   aChar =  strSelection.charAt(0);
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aChar;
         public int readInt(String userInstruction) {
              int aInt = 0;
              try {
                   Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aInt = scan.nextInt();
              } catch (InputMismatchException e) {
                   System.out.println("\nInputMismatchException error occurred (the next token does not match the Integer regular expression, or is out of range) " + e);
              } catch (NoSuchElementException e) {
                   System.out.println("\nNoSuchElementException error occurred (input is exhausted)" + e);
              } catch (IllegalStateException e) {
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aInt;
    public class SortedList extends ShellSortedList implements SortedListInterface<MusicCd>
         public SortedList()
              super();
         public void insert( MusicCd aCd )
              MusicCdNode cdNode = new MusicCdNode( aCd );
              cdNode.setNext( head );
              head = cdNode;
              numberOfItems++;
         public MusicCd delete(String aCdsTitle)
                                                throws InvalidDataException
              MusicCdNode current = head;
              MusicCdNode previous = null;
              while( current != null
                    && current.getMusicCd().getCdTitle() != aCdsTitle)
                   previous = current;
                   current = current.getNext();
              if (current == null ) //not found
                   throw new InvalidDataException(aCdsTitle
                                 + " not found: cannot be deleted" );
              else
                   if( current == head )
                        head = head.getNext(); //delete head
                   else
                        previous.setNext( current.getNext() );
                   numberOfItems--;
                   return current.getMusicCd();
         public MusicCd modify(String anExistedCdsTitle, String aModifyCdsTitle)
                                   throws InvalidDataException
              MusicCdNode current = head;
              while( current != null
                    && current.getMusicCd().getCdTitle() !=  anExistedCdsTitle)
                   current = current.getNext();
              if ( current == null )
                   throw new InvalidDataException( anExistedCdsTitle
                                 + " not found: cannot be deleted" );
              else
                   MusicCd tempCd = new MusicCd();
                   tempCd.setCdTitle(aModifyCdsTitle);
                   current.setMusicCd(tempCd);
                   return current.getMusicCd();
    }//for better understand of my program
    public interface SortedListInterface<T>
         //public SortedList();
         public void insert( T anElement );
         public T delete(String searchKey)
                                         throws InvalidDataException;
         public T modify(String searchKey, String aModifyTitle)
                             throws InvalidDataException;
    public abstract class ShellSortedList
         protected MusicCdNode head;
         protected int numberOfItems;
         public ShellSortedList()
              head = null;
              numberOfItems = 0;
         public int getNumberOfItems()
              return numberOfItems;
         public boolean isEmpty()
              return( numberOfItems == 0 );
         public boolean isDuplicate(String newCD)
                boolean found = false;
                MusicCdNode current = head;
                for( int i=0; i < numberOfItems; i++)
                   if(current.getMusicCd().getCdTitle().equals(newCD))
                   System.out.println("Duplicate Cd is found !!");
                            found = true;
                   current = current.getNext();
                    return found;
         public String toString()
              String listString = " ";
              MusicCdNode current = head;
              for( int i=0; i < numberOfItems; i++)
                   listString += current.getMusicCd().toString() + "\n";
                   current = current.getNext();
              return listString;
    public class MusicCdNode
         private MusicCd cd;
         private MusicCdNode next;
         // Default constructor
         public MusicCdNode()
         // Description: Initialize the reference for the cd object and the value of next to null.
         // Postcondition: cd = null; next = null;
              cd = null;
              next = null;
         // Parameterized constructor
         public MusicCdNode(MusicCd aCd)
         // Description: Set the reference for the cd object according to the parameters and value of next to null.
         // Postcondition: cd = aCd; next = null;
              cd = aCd;
              next = null;
           public MusicCd getMusicCd()
              return new MusicCd(cd.getCdTitle());
         public MusicCdNode getNext()
              return next;
         public void setMusicCd(MusicCd aCd)
              cd = new MusicCd(aCd.getCdTitle());
         public void setNext(MusicCdNode aCd)
              next = aCd;
    // File: MusicCd.java
    // Author: Chi Lun To (Ivan To)
    // Created on: June 5, 2007
    // Class Description
    // The MusicCd class defines a music cd object that contain the CD`s title, CD`s artist/GroupName,
    //  CD`s yearOfRelease , Cd`s music genre, and any comment of the Cd`s. This class provides functions
    //  to access the musicCdsTitle, artistOrGroupName, yearOfRelease, musicGenre, and aComment variable.
    //  Class Invariant: All MusicCd objects have a  string musicCdsTitle, string artistOrGroupName, integer yearOfRelease
    //  String musicGenre, and String aComment. A string type musicCdsTitle,artistOrGroupName, musicGenre,or aComment of "None"
    //  indicates no real name specified yet. A integer yearOfRelease of 1000 indicates no real years specific yet.
    public class MusicCd
         String theCdTitle;// the CD`s Title
         // Default constructor
         public MusicCd()
         // Description: Initialize theCdTitle to empty string
         // Postcondition: theCdTitle = " ";
              theCdTitle = " ";
         }//end constructor
         // Parameterized constructor
         public MusicCd(String aCdTitle)
         // Description: Set theCdTitle according to the parameters
         // Postcondition: theCdTitle = aCdTitle;
              theCdTitle = aCdTitle;
         } // end constructor
         // Accessor function : getCdTitle( ) function
         public String getCdTitle()
         // Description: Method to return the theCdTitle
         // Postcondition: the value of theCdTitle is returned
              return theCdTitle;
         }// end  getCdTitle( ) function
         // Mutator function: setCdTitle( ) function
         public void setCdTitle(String aCdTitle)
         // Description: Method to set theCdTitle according to the parameter
         // Postcondition: theCdTitle = aCdTitle;
              theCdTitle = aCdTitle;
         }// end setCdTitle( ) function
         // toString( ) function
         public String toString()
         // Description: Method to return the theCdTitle
         // Postcondition: the value of theCdTitle is returned as String
                   return("Title: " + theCdTitle );
         }// end  toString( ) function
    // File: InvalidDataException.java
    // Author: Chi Lun To (Ivan To)
    // Created on: June 5, 2007
    // Class Description
    // The InvalidDataException class is a self- defined exception class which handles
    // the issues that may arise with return value of the deleted and modify function.
    // For example,  the issue will occurs if the user try to delete the music cd from a empty list
    // or deleting a music cd that does not exist on the list. it would return null to the user. But, the user
    // expected to return an obeject reference of the music cd.Therefore, we instantiate InvalidDataException
    // class to handle this issue.
    //  Class Invariant:
    //  InvalidDataException class is a self-defining exceptional class which
    //  inherits the existing functionality of the Exception class.
    public class InvalidDataException extends Exception
         //Parameterized constructor
         public InvalidDataException( String s )
              super( s ); //inherits the existing functionality of the Exception class.
    }Message was edited by:
    Ivan1238
    Message was edited by:
    Ivan1238

    thx for your suggestion ..but i did try to skip my code..but i am sure if u guy understand what i am trying to ask ..so i try to show my all program for u guy better undrstand my problem ...the first three paragraph of code i hope u guy could focus on it ....i try ask the user to input the cd`s title to our insert list by using a function call readString( ) and i use this method to ask the user what cd they want to be delete from the list ...but it doesn`t work when i try to perform the delete cd funtion. At first, i think it should be my deleteCd( ) problem ..but i do some testing on it..it works fine if i pass a String directly to my function instead of using readString() function to perform ...therefore, i am sure my delete function working fine....i am thinking if it is my readString() problem make my deletion does not perform well...thx for u guy help

Maybe you are looking for

  • What changed in recent Droid update?

    I had an update pushed to my Droid 2 yesterday. Is there a page somewhere that describes what changed? My version info says: - System Version: Version 2.3.20.A955.Verizon.en.US - Android Version: 2.2 Thanks.

  • The Case of Missing ID3 Tags... and non-Apple devices, like the Sonos

    Ever since the debut of iTunes 6, devices other than my Mac and my iPod have been unable to find the ID3 tags associated with .mp3 files. If I rip a CD in iTunes 6 or 7, artist/album/track data (and album artwork) display properly in iTunes and on my

  • Incrementing a variable in memory

    I have an older application that is querying a list, pulling out an AD from the list, then incrementing the database by +1 with every pull. The site has grown very popular and now the traffic is creating a ton of deadlocks. I tried using CFLOCK but t

  • Financial extension sets and flb1 post processing items are not there

    "Forum moderators, if you reject this post please tell me exactly what is incorrect about it in your rejection message". Hello experts, We are currently in 4.7 and have activated financial extension set EA-FIN.  I tested electronic lockbox programs b

  • WLS 10.0: WebDAV methods are rejected

    Hi,           WebDAV methods are rejected with status code 501. There is no basis for this in the specification. The only indication is the strict definition of the "http-method" element in the deployment descriptor, but it has been relaxed again in