You are on page 1of 5

IST140-002 "Introduction to Application Development"

Fall 2016

Exam 3a
Name (first and last): _______________________________________________________

Instructions

Using Finder (for Mac OS X) or File Explorer (for Windows), rename this file
from
IST140-002_Exam_3.docx
to include your own name. For example, if your name is "Mary Smith", rename
this file to
Smith_Mary_Exam_3.docx

Write or copy and paste your answers directly into the renamed document,
under each question. Be sure to not include line numbers adjacent your Java
source code. Include source code and not images of source code in this
document. If applicable, use suitable user input prompts, user feedback, and the
most appropriate data type and identifier for each variable you create.

Submit the renamed document to the "Exam 3" dropbox before the due date and
time. Otherwise, a late submission penalty is applicable. Consult our course
syllabus for more details about making a late submission.

Special note: Submitting Exam 3 involves both a .docx file (that's the Exam 3a
exercises) and a .zip file (that's the Exam 3b exercises). Be sure both files reside
in your designated dropbox.

Exam
1. Using a flowcharting tool of your choice, build a flowchart that models a
complete Java program called StringSlicer that gets a String from the user at the
command line, and populates an ArrayList of Character data (the wrapper class),
with each char in the String represented as a separate Character element in the
ArrayList. Output each Character to the command line, each on a separate line.
The flowchart should be sufficiently detailed and follow the standards we've
showcased in our course. Capture an image screenshot of your flowchart and
paste it below this exercise. (1.25 points)

IST140-002 "Introduction to Application Development"


Fall 2016

IST140-002 "Introduction to Application Development"


Fall 2016

IST140-002 "Introduction to Application Development"


Fall 2016

2. Build the equivalent complete Java program you flowcharted in the previous
exercise. Be sure to research any methods you need more details on using the
various resources discussed to date in our course (e.g. optional textbooks,
"Lynda" videos). Paste your source code below this exercise. (2.75 points)
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class StringSlicer {
String userInput;
List<Character> charList = new ArrayList<Character>();
public StringSlicer() {
userInput="";
}
//////////////////////////////////////////////////////
void getStringFromUser()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter String: ");
userInput=keyboard.nextLine();

IST140-002 "Introduction to Application Development"


Fall 2016
if(userInput.equals(""))
{
System.out.println("Enter Valid String.");
getStringFromUser();
}
else
{
convertStringtoArrayList();
}
}

//////////////////////////////////////
public void

convertStringtoArrayList()

for(char c : userInput.toCharArray())
{
charList.add(c);
}
}
///////////////////////////////////////////
public void displayCharacterList()
{
for(int x=0;x<charList.size();x++)
{
System.out.println(charList.get(x));
}
}
/////////////////////////////////////
public static void main(String[] args) {
StringSlicer object=new StringSlicer();
object.getStringFromUser();
object.displayCharacterList();
}
}

You might also like