Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Print a given sentence forwards, backwards and every other word.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Print a given sentence forwards, backwards and every other word.

    Hello!

    I am doing a task and wondered if someone could help me.

    Here is the task:

    Create a program that allows a user to enter 10 words.

    The program will prompt each user to show how far she has come, for example: "Enter the word number 6:"

    The program will then print all the words forwards, backwards and every other word.

    Program code should have high cohesion. It should therefore consist of three classes. Class names should be the start point, Dialog and Printing.

    One class will be responsible for being the entry point.

    The second class will be responsible for the dialogue with the user entering keywords, and to manage printing.

    The third class will be responsible for printing.


    Clarification: By "backwards" here means "in reverse" in relation to the order of the words were written in.


    My code:
     
     
    public class Startpunkt {
     
    	public static void main(String[] args) {
    		new Dialog();
    }
     
    }
     
     
     
    import javahjelp.Konsoll;
     
     
    public class Dialog {
     
    	public Dialog(){
    			String[] rekke = new String[10];
    			for (int i=0;i<10;i++)
    				rekke[i] = Konsoll.readLine("Write a word "+i);
    			int i;
    			for (i=0;i<10;i++)
    				new Print();	
    		}
     
    }
     
     
    public class Print {
     
    	System.out.println("You wrote " +rekke[i])
     
    }

    The last class is my problem. How do i print something from class Dialog ? And print the other way I'm supposed to (watch task)? I need help


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Print a given sentence forwards, backwards and every other word.

    These so-called classes should be methods, but there may be some 'method' to the instructor's madness. If you figure it out someday, let me know.

    I had an idea I was going to suggest for the Printing class, but the more I thought about it, the more I hated it. If I think of something I'm not ashamed to suggest, I'll come back.

Similar Threads

  1. Replies: 7
    Last Post: March 29th, 2013, 07:38 AM
  2. Replies: 1
    Last Post: December 3rd, 2012, 02:35 PM
  3. How to print numbers using do while, for loop and if else statement?
    By techlover in forum Loops & Control Statements
    Replies: 1
    Last Post: October 30th, 2012, 02:13 PM
  4. Replies: 5
    Last Post: August 20th, 2012, 01:01 AM
  5. Program to take name as input and write it backwards
    By snake101 in forum Java Theory & Questions
    Replies: 7
    Last Post: June 10th, 2009, 04:35 AM

Tags for this Thread