troubleshooting Question

getSandwich java challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
Programming Languages-OtherProgrammingJavaJava App ServersJava EE
22 Comments2 Solutions647 ViewsLast Modified:
I am working on below challenge
I tried my code as below
public String getSandwich(String str) {
  String Str1 = new String("Welcome to");
  //String str2=str.replaceFirst("bread", "" );
  //System.out.println(Str.replaceFirst("Tutorials", "" ));
//String strNew= str.repalceFirst("bread", "xyzzz");
String str3=str.replaceAll(".*bread*.", "" );

  return str3;

 //                        "AMROOD" ));

 //     System.out.print("Return Value :" );
 //     System.out.println(Str.replaceFirst("Tutorials", "AMROOD" ));
I am getting below result
Expected      Run            
getSandwich("breadjambread") → "jam"      ""      X         
getSandwich("xxbreadjambreadyy") → "jam"      "y"      X         
getSandwich("xxbreadyy") → ""      "y"      X         
getSandwich("xxbreadbreadjambreadyy") → "breadjam"      "y"      X         
getSandwich("breadAbread") → "A"      ""      X         
getSandwich("breadbread") → ""      ""      OK         
getSandwich("abcbreaz") → ""      ""      OK         
getSandwich("xyz") → ""      "xyz"      X         
getSandwich("") → ""      ""      OK         
getSandwich("breadbreaxbread") → "breax"      ""      X         
getSandwich("breaxbreadybread") → "y"      ""      X         
getSandwich("breadbreadbreadbread") → "breadbread"      ""      X         
other tests

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
Information Technology Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros