user3267449
user3267449

Reputation:

Arrays and Output in Java

So I am trying to write a program that automates making an Operations Order (or OPORD). It is pretty straight forward, but I am having some issues with my arrays, more specifically how to get them to display properly in the output. Here is my code:

import java.util.*;
import java.util.Scanner;
public class opord {
    public static void main(String[] args){

    //Variables
    int opord_type, phase_a = 0, n = 1, tasks = 0, phase_b = 0, phase_c = 0;
    //Strings for paragraph 1
    String area_interest = " ", area_ops = " ", enemy_forces = " ", weather = " ", terrain = " ", friendly_forces = " ", civil_consid = " ", attach_detach = " "; 
    //Strings for paragraph 2
    String who = " ", what = " ", where = " ", when = " ", why = " ";
    //Strings for paragraph 3
    String commander_intent = " ", phases;
    Scanner keyboard = new Scanner(System.in);
    //Array Lists
    ArrayList alist = new ArrayList();
    ArrayList blist = new ArrayList();
    ArrayList clist = new ArrayList();
    //Page One

    System.out.println("Welcome to Automated OPORD");
    System.out.println("Please choose which type of OPORD you want: (1:Garrison, 2:Tactical)");

    opord_type = keyboard.nextInt();
    if(opord_type == 1){
        //Page Two
        System.out.println("Paragraph One: ");
        System.out.println("Situation: ");
        //Indent One
        System.out.println("Enter area of interest: ");
        area_interest = keyboard.next();
        System.out.println("Enter area of operations: ");
        area_ops = keyboard.next();
        //Indent Two
        System.out.println("Enter weather: ");
        weather = keyboard.next();
        System.out.println("Enter terrain: ");
        terrain = keyboard.next();
        //End Indent Two
        System.out.println("Enter enemy forces: ");
        enemy_forces = keyboard.next();
        System.out.println("Enter friendly forces: ");
        friendly_forces = keyboard.next();
        System.out.println("Enter civil considerations: ");
        civil_consid = keyboard.next();
        System.out.println("Enter attachments and detachments: ");
        attach_detach = keyboard.next();
        //End Indent One

        //Page Three
        System.out.println("Paragraph Two: ");
        System.out.println("Mission");
        //Indent One
        System.out.println("Enter who: ");
        who = keyboard.next();
        System.out.println("Enter what: ");
        what = keyboard.next();
        System.out.println("Enter where: ");
        where = keyboard.next();
        System.out.println("Enter when: ");
        when = keyboard.next();
        System.out.println("Enter why: ");
        why = keyboard.next();
        //End Intent One

        //Page Four
        System.out.println("Paragraph Three: ");
        System.out.println("Execution: ");
        //Indent One
        System.out.println("Enter commander's intent: ");
        commander_intent = keyboard.next();
        System.out.println("Concept of Operations");
        //Indent Two
        System.out.println("Enter number of phases: ");
        phase_a = keyboard.nextInt();
        for (int ph=0; ph<phase_a; ph++) { 
            System.out.println ("Enter phase " + (ph+1)); 
            alist.add (keyboard.next()); 
        }//End Indent Two
        System.out.println("Scheme of Movement and Maneuver");
        //Indent Three
        System.out.println("Enter number of phases: ");
        phase_b = keyboard.nextInt();
        for (int p=0; p<phase_b; p++) { 
            System.out.println ("Enter phase " + (p+1)); 
            blist.add (keyboard.next());
        }//End Indent Three
        System.out.println("Task to Subordinate Units");
        //Indent Four
        System.out.println("Enter number of tasks: ");
        tasks = keyboard.nextInt();
        for (int h=0; h<phase_b; h++) { 
            System.out.println ("Enter task " + (h+1)); 
            clist.add (keyboard.next());
        }
    }else if(opord_type == 2){



    }
    //Output for Garrison
    System.out.println("Output for Garrison");
    for (int ph=0; ph<phase_a; ph++){
        System.out.println("Phase " + n++ + ": " + alist.get(ph));
    }
    for (int p=0; p<phase_b; p++){
        System.out.println("Phase " + n++ + ": " + blist.get(p));
    }
    for (int h=0; h<phase_c; h++){
        System.out.println("Phase " + n++ + ": " + clist.get(h));
    }

    //Output for Tactical




    }
}

I need the output of the phases and the tasks to look like this:

Concept of Operations: 
Phase One: Here is some text that the user input
Phase Two: Here is some text that the user input
Phase Three: Here is some text that the user input
Phase (whatever the number the user input): Here is some text that the user input

Scheme of Movement and Maneuver:
Phase One: Here is some text that the user input
Phase Two: Here is some text that the user input
Phase Three: Here is some text that the user input
Phase (whatever the number the user input): Here is some text that the user input

Task to Subordinate Units:
Task One: Here is some text that the user input
Task Two: Here is some text that the user input
Task Three: Here is some text that the user input
Task (whatever the number the user input): Here is some text that the user input

Tactical is mostly mirrored with some changes so don't worry about that, I just need to fix this code so that. I just have to get this code finished, any help would be wonderful!

Thank you!

Upvotes: 0

Views: 105

Answers (1)

Scherling
Scherling

Reputation: 1390

If I'm understanding you correctly, this is a question about how to create line breaks in the console output of a Java application.

The Character for this is "\n". Put that into print command when you want to do a line break.

   //Page Three
    System.out.println("\nParagraph Two: ");
    System.out.println("Mission");
    etc...

Further more, looking at your expected output (I don't know if this is important) but if you want to user input to be next to the text strings, rather than below, use System.out.print (without the ln at the end)

.println will do a line break after finishing the regular print operation

Upvotes: 3

Related Questions