The following program is aiming to extract from a simple text file an analysis of the content such as:



Similar documents
Sample CSE8A midterm Multiple Choice (circle one)

Introduction to Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Install Java Development Kit (JDK) 1.8

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

J a v a Quiz (Unit 3, Test 0 Practice)

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Chapter 2 Introduction to Java programming

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Basics of Java Programming Input and the Scanner class

Topic 11 Scanner object, conditional execution

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Introduction to Programming

Building Java Programs

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

(Eng. Hayam Reda Seireg) Sheet Java

JAVA ARRAY EXAMPLE PDF

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Introduction to Java. CS 3: Computer Programming in Java

Building Java Programs

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Course Intro Instructor Intro Java Intro, Continued

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

AP Computer Science Static Methods, Strings, User Input

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

6.1. Example: A Tip Calculator 6-1

CS 121 Intro to Programming:Java - Lecture 11 Announcements

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Chapter 3. Input and output. 3.1 The System class

CS 106 Introduction to Computer Science I

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.

Programming in Java Course Technology, a part of Cengage Learning.

Building Java Programs

Contents. 9-1 Copyright (c) N. Afshartous

Part I. Multiple Choice Questions (2 points each):

Some Scanner Class Methods

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

Programming and Data Structures with Java and JUnit. Rick Mercer

Using Files as Input/Output in Java 5.0 Applications

Arrays. Introduction. Chapter 7

Programming Languages CIS 443

Comp 248 Introduction to Programming

Crash Course in Java

Introduction to Object-Oriented Programming

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

ECE 122. Engineering Problem Solving with Java

AP Computer Science Java Mr. Clausen Program 9A, 9B

Moving from CS 61A Scheme to CS 61B Java

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Form Validation. Server-side Web Development and Programming. What to Validate. Error Prevention. Lecture 7: Input Validation and Error Handling

Lecture 5: Java Fundamentals III

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Building Java Programs

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.

Example of a Java program

CS 106 Introduction to Computer Science I

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

D06 PROGRAMMING with JAVA

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

LOOPS CHAPTER CHAPTER GOALS

Building Java Programs

Object-Oriented Programming in Java

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Chapter 2 Elementary Programming

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Computer Programming Tutorial

Week 1: Review of Java Programming Basics

Building Java Programs

CS114: Introduction to Java

8.1. Example: Visualizing Data

public static void main(string[] args) { System.out.println("hello, world"); } }

Software Engineering Techniques

Arrays in Java. Working with Arrays

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

13 File Output and Input

Chapter 2 Basics of Scanning and Conventional Programming in Java

CSE 308. Coding Conventions. Reference

Line-based file processing

Using Two-Dimensional Arrays

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

More on Objects and Classes

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Continuous Integration Part 2

Building a Multi-Threaded Web Server

Java Programming Fundamentals

Transcription:

Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of consonants Frequency of each vowel PseudoCode This is the original Pseudocode I had noted down for my original code ideas. Start End IF no file or text is entered in programme, request file from users ELSE continue SORT the text in the file COUNT the number of characters and variations OUTPUT the count When I started trying to put code to paper as it were, I came across a number of stumbling blocks and so I went and did some research in various sources to try and over come these issues. One of the main issues I had was in trying to get the programme to read in the text from a simple text file (my original aim was to use something in the same feel as page 464 of Java in two semesters) and so I resorted to requesting an input from the keyboard. Upon completion of my research, I found that the Pseudocode used in my original ideas was not very similar. Cormac O'Connell Page 1 of 7 5/14/2007

This is the revised Pseudocode: Start END INPUT string of characters COUNT text length COUNT vowels COUNT consonants (length vowels) COUNT white space (space bar & tabs depressions) OUTPUT counts Cormac O'Connell Page 2 of 7 5/14/2007

The Code The following is the print out of my java code. I have highlighted using comments the bits that were my own work and the bits that were the work of someone else (The code was found during my research into the problems I was having). // my bit import java.util.*; // required for Scanner public class textanalyser // the main class that will do all the work static char[] vowel='a', 'e', 'i', 'u', 'o'; // set the definition of a vowel. This could easily be changed to consonants by just replacing the characters present public static void main(string[] args) System.out.println("Enter a word, or phrase (Maximum 300 words):"); // request the user input the text to be analysed Scanner sc = new Scanner(System.in); // read the input from Scanner into sc String text = sc.nextline(); // read the text input by the user into the Scanner sc System.out.println("You entered the following text: "+text); // display the number of characters typed System.out.println("Number of characters: "+text.length()); // display the number of printable characters System.out.println("Number of vowels: "+countvowels(text)); // display the number of vowels System.out.println("Number of constanants: "+(text.length()-countvowels(text))); // display the number of consonants System.out.println("Number of spaces: "+countspaces(text)); // display the number of white spaces // end of my bit // bit from http://java.sun.com static int countvowels(string s) // method to count the number of vowels input char[] array = s.tochararray(); int counter=0; for (int i = 0; i < array.length; i++) if(isvowel(array[i])) counter++; return counter; static boolean isvowel(char c) for (int i = 0; i < vowel.length; i++) if(c==vowel[i]) return true; return false; spaces static int countspaces(string s) // method to count the number of white int count=0; char[]a=s.tochararray(); for (int i = 0; i < a.length; i++) if(32==(int)a[i]) //32 = (int)' ' count++; return count; // end of the bit from http://java.sun.com Cormac O'Connell Page 3 of 7 5/14/2007

Testing Unfortunately, I was unable to create a test rig to test this programme. However I tested it by hand and it seems to work okay. One thing I have realised is that although my program seems to work okay, it detects symbols as consonants. This will require a little bit of work to rectify. The following is the code I am trying to use to rectify the issue, however it doesn t work in it s current state. // my bit import java.util.*; // required for Scanner public class textanalyser1 // the main class that will do all the work static char[] vowel='a', 'e', 'i', 'o', 'u'; // set the definition of a vowel. This could easily be changed to consonants by just replacing the characters present static char[] consonant='b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'; // set the definition of a consonant public static void main(string[] args) System.out.println("Enter a word, or phrase (Maximum 300 words):"); // request the user input the text to be analysed Scanner sc = new Scanner(System.in); // read the input from Scanner into sc String text = sc.nextline(); // read the text input by the user into the Scanner sc System.out.println("You entered the following text: "+text); // display the number of characters typed System.out.println("Number of characters: "+text.length()); // display the number of printable characters System.out.println("Number of vowels: "+countvowels(text)); // display the number of vowels System.out.println("Number of constanants: "+countconsonants(text)); // display the number of consonants System.out.println("Number of symbols: "+(text.length()- countvowels(text)-countconsonants(text)); // display the number of consonants System.out.println("Number of spaces: "+countspaces(text)); // display the number of white spaces // end of my bit static int countconsonants(string s) // method to count the number of consonants input char[] array = s.tochararray(); int counter=0; for (int i = 0; i < array.length; i++) if(isconsonant(array[i])) counter++; return counter; static boolean isconsonant(char c) for (int i = 0; i < consonant.length; i++) if(c==consonant[i]) return true; return false; // bit from http://java.sun.com static int countvowels(string s) // method to count the number of vowels input Cormac O'Connell Page 4 of 7 5/14/2007

char[] array = s.tochararray(); int counter=0; for (int i = 0; i < array.length; i++) if(isvowel(array[i])) counter++; return counter; static boolean isvowel(char c) for (int i = 0; i < vowel.length; i++) if(c==vowel[i]) return true; return false; static int countspaces(string s) // method to count the number of white spaces int count=0; char[]a=s.tochararray(); for (int i = 0; i < a.length; i++) if(32==(int)a[i]) //32 = (int)' ' count++; return count; // end of the bit from http://java.sun.com Cormac O'Connell Page 5 of 7 5/14/2007

References During the course of my research and code I made general reference to the following: Java in two semesters, 2 nd Edition, Charatan & Kans, McGraw Hill publishing http://java.sun.com and the forums found there in. Direct reference was made to http://java.sun.com forums in my code and these sections have been highlighted with comments. Cormac O'Connell Page 6 of 7 5/14/2007

Cormac O'Connell Page 7 of 7 5/14/2007