my main program is logicaly simple , i just have to reverse a string and change it back,
the problem is this.. here's the codes
this first class will reverse the String that will be passed to each method //i dont have problems with this class
public class FirstReverse { private static String reversed; public FirstReverse(String word) { reverse(word); } private void reverse(String word) { reversed = new StringBuilder(word).reverse( ).toString( ); } public String getFirstReverse( ) { return reversed; } }
*Another Classs*
HERE IS THE PROBLEM:
--i want to revert back the strings that i have already reversed using the first class "FirstReverse"
public class SecondReverse { private static String secondReverse; public SecondReverse(FirstReverse firstReversedWord) { reverseAgain(firstReversedWord); } private void reverseAgain(FirstReverse firstReversedWord) { String tempReversedWord; tempReversedWord = firstReversedWord.toString( ); secondReverse = new StringBuilder(tempReversedWord).reverse( ).toString( ); } public String getSecondReverse( ) { return secondReverse; }
-----here's the main program that uses this two classes-----
import java.util.*; public class SampleReverse { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { String word, firstReversedWord, secondReversedWord; System.out.print("Enter word: "); word = scanner.nextLine( ); FirstReverse firstRev = new FirstReverse(word); firstReversedWord = firstRev.getFirstReverse( ); SecondReverse secondRev = new SecondReverse(firstRev); secondReversedWord = secondRev.getSecondReverse( ); System.out.println("First Reverse: " + firstReversedWord); System.out.println("Second Reverse: " + secondReversedWord); } }
the problem is the secondReversedWord and its method only diplays a String represtentaion of
a memory address .(in the main program)
that's the problem
---
*I SOLVED IN IN THIS WAY* "BUT BUT BUT BUT..."
public class SecondReverse { private static String secondReverse; public SecondReverse(String reversedWord) { reverseAgain(reversedWord); } private void reverseAgain(String reversedWord) { secondReverse = new StringBuilder(reversedWord).reverse( ).toString( ); } public String getSecondReverse( ) { return secondReverse; } }
*BUT BUT IF I DID IT THIS WAY THEN THIS CLASS CAN HANDLE ANYTHING BY ITSELF*
*IT DOES DO THE THINGS THAT THE "FirstReverse Class" do
my point is this
1st: I want to reverse A String by passing it to the firstClass "First Reverse" //this part is easy
2nd: I want to revert it back by PASSING THE object of the "FirstReverse" class INTO the
"SecondReverse class" that has alreay the reversed String
-----------------------------------------------------------------------------------------------------
in other words. the "SecondReverse Class" CANNOT GENERATE ANYTHING IF I'M NOT YET REVERSING A STRING
USING THE "FirstReverse Class"
or in other words.
THE "SecondReverse CLASS" IS USELESS IF THE USER IS NOT USING THE "FirstReverse CLASS" FIRST
*FirstReverse --------->>> SecondReverse*
-----
i want to connect the second class from the first class, something like that....
is my program possible?
-----
i hope you understand the logic that i want to make on this program..
please help... tnx