/*program should allow user to enter a name for example John Doe Hue. it allows the user to print the name out in 3 different formats formal, reversed, pig latin. formal- John D. Hue reversed- nhoj eod euh pig latin- ohnjay eoday euhay //ohn + j+ ay
problem is im getting an error when i enter the name it just prints null. can anyone just copy and paste the code below into some editor, compile personname,it's sub classes & test. then just run test. */ //*******************************************************888
public class PersonName extends Object { // protected
public PersonName(String first, String middle, String last) { setName(first,middle,last); }
Ok, i have written some code for your problem. Can't gurantee thats right but you may check. Now if a person does not enter a middlename, you will get an exception. so if thats a criteria, you may want to include it. here's the basic code (i've used your gui code): hope that solves your problem :)
// This one makes the Strings separate and then processes it accordingly private String process(String str, String process){ String first = str.substring(0,str.indexOf(" ")); String middle = str.substring(str.indexOf(" ")+1,str.lastIndexOf(" ")); String last = str.substring(str.lastIndexOf(" ")+1,str.length()); String processed = "";
hey sorry i did not reply earlier but i want to thank you the code it fixed everything. middle name exception was not part of what the program should do but i'll throw it in there anyway since it makes sense. thanks again.