Program That Counts Number Of Individual Letters In A File
Dec 3, 2014
What my program needs to do:
1) accepts a filename from the user that indicates the input file
2)obtains a filename to use as the output file
3)the program then reads the file and reports how many of each letter are there in the file.
4)if the file could not be opened, you must ask the user for valid file name until one is given
5)once a valid file name is given, print all of contents and store the analysis of the file in the output file name specified
You will be reading the input from a file and printing the output to another file. For example, if the file input.txt contains:
This file contains lett3rs.
YoU counT Only lEtTers, not numb3rs.
How many h's are in "Ohhhhhhhhhhh no!"?
The program should ignore white spaces, new lines and other special characters or numbers. It should count only the letters (a-z and/or A-Z) in the input file.
An example execution might look like this:
Input a file name: notAFile.txt
Invalid filename given. Input another.
Input a file name: alsoNotAFile.txt
Invalid filename given. Input another.
Input a file name: input.txt
[Code] ....
1)The last try/catch block was given by my professor, however the only thing it does is print out "hello java" into an out file. How would I make it print out similar to that of the given example?
2)I figured out how to make the array print out ABCDEFG... etc...how to count the amount of them.
View Replies
ADVERTISEMENT
Mar 21, 2015
Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa.
For example, Alb34eRt will be converted to aLB34ErT.
View Replies
View Related
Oct 23, 2014
Write a java code that asks the user for an Integer and then counts down from that number to 0. Printing each number. For example:
Enter an Integer: 5 (enter) <--- user hits the enter key
5
4
3
2
1
0
import java.util.Scanner;
public class Exam{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
View Replies
View Related
May 7, 2015
Any method or two that counts, for example, registered persons in a program?
I have this insurance program that have different insurance registered on persons.
I really want a history class that counts registered persons, and theirs insurance.
View Replies
View Related
Sep 29, 2014
I can't get my code to print it like it's on the picture.
import javax.swing.JOptionPane;
import java.util.*;
public class BokstavTeller
{
public static void main( String[] args ) {
String input = JOptionPane.showInputDialog(
[Code] .....
View Replies
View Related
Feb 26, 2015
I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output?
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
[code]....
View Replies
View Related
Feb 26, 2015
I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output?
import java.io.IOException;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;import org.w3c.dom.Element;
[Code] ....
View Replies
View Related
Feb 2, 2015
Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.
import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;
[Code] ....
View Replies
View Related
Oct 19, 2014
I had to write a program for class using the method definition "public static char getNumber(char upperCaseLetter)" It compiles and runs but wont print out my final answer.
import java.util.Scanner;
public class Phone_0104730303 {
public static char getNumber(char upperCaseLetter)
{
char return_val = 0;
[Code].....
View Replies
View Related
Jan 12, 2014
for example if the given string is: The world is running java technology?
Ans:
T is =2
h is=2
e is=2
w is=1
n= 4
like wise i need out put of the program?
View Replies
View Related
Dec 4, 2014
I have devised a simple program that reads a file and then adds up al the integers in the file and print the result, for example if the file had the numbers
1 2 3 4 5 6 7 8 9 10
then the program would print 55
However i have trouble when non integers are put into the file for example if it was
1 2 3 string 4 5 6 test 7 8 9 10
then i get:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Week7.Task3.filereader(Task3.java:25)
at Week7.Task3.main(Task3.java:14)
my code is as follows
package testing;
import java.util.*;
import java.io.File;
import java.io.IOException;
public class summingInts {
public static void main(String[] args)
throws IOException {
Scanner textfile = new Scanner(new File("intSum.txt"));
[code]....
View Replies
View Related
Mar 21, 2015
Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa. For example, Alb34eRt will be converted to aLB34ErT.
View Replies
View Related
May 13, 2013
I have a text file that has the results of rock paper scissors game.
R P
S R
P P
I need to have the first letter in each line assigned to player1 and the second letter in each line assigned to player 2. where to start. I have the file input correct. It is reading the file and I can separate ints from strings. I just don't know how to separate the strings.
View Replies
View Related
Mar 28, 2015
I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.
-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:
Welcome to this first-ever mind-guessing program!
Please pick a range (higher than 1 and no larger than 50): 32
You will choose a number between 1 and 32... and I will try to guess it.
With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.
-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:
My fourth guess is 17: h
My guess is too high?
My fifth guess is 16: h
*** I am unlucky this round. I give up.
Let's play!
My first guess is 10:
etc..
import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;
[Code] ....
View Replies
View Related
May 5, 2014
trying to write a program that takes a user inputted number and converts it to a binary number.
Here's what I have:
package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();
[Code]...
Bugs on:
Line 13
Line 17
Line 23
View Replies
View Related
Dec 29, 2014
ex
Sample input:2340980
Sample Output:23498
this is the program i have tried but is dosent work
import java.util.*;
class zero
{
public static void main(String args[])
{
[Code]....
View Replies
View Related
Oct 15, 2014
This is a piece of a program I am trying to write,my only problem is when an incorrect input is entered in "genreType" it still counts as a loop and therefore I do not end up with 20 results I am looking for..I have tried multiple different ways but nothing seems to work for me.
package assignment_1;
import javax.swing.*;
public class Assignment_1 {
public static void main(String[] args) {
int rockCounter=0;
int popCounter= 0;
int danceCounter= 0
[Code] ....
View Replies
View Related
Jan 17, 2015
/*****************************************************************
* Creates an MxN minesweeper game where each cell is a bomb with probability p.
* Prints out the MxN game and the neighboring bomb counts.
*
* Sample execution:
*
* % java Minesweeper 5 10 0.3
* * . . . . . . . . *
* . . . . . . * . . .
* . . . . . . . . * *
* . . . * * * . . * .
* . . . * . . . . . .
*
* * 1 0 0 0 1 1 1 1 *
* 1 1 0 0 0 1 * 2 3 3
* 0 0 1 2 3 3 2 3 * *
* 0 0 2 * * * 1 2 * 3
* 0 0 2 * 4 2 1 1 1 1
*
*
*************************************************************************/
public class MineSweeper
{
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]); //columns
int s = Integer.parseInt(args[1]); //rows
int p = Integer.parseInt(args[2]); //max number of bombs
[Code] .....
Console:
. . * . *
. * . . .
. . * . *
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Stefan.Minesweeper.main(Minesweeper.java:85)
Every time the compiler shows me this Array Index Out Of Bounds and shows me in the witch line i have error but i just don't get it how to fixed it and why compiler printing me this mistake because there is enough space in array field[][] because i provided a n+2 X s+2 fields in array and i am using just 1 to n ,including and 1 to s ,including m, so i have not used fields from field[0][0] to field[0][s+1] and field[0][0] to field[n+1][0], field[n+1][0] to field[n+1][s+1] ,field[n+1][s+1] to field[0][s+1] ,so i suppose i can check their values and do not get out of array bounds,but compiler claims otherwise!!!
View Replies
View Related
Nov 4, 2014
I am trying to create a method for my "ticketmachine" object that counts ticket objects in an arraylist of "ticket" objects with a specified field "route". The method works if i change the field type of the ticket class to public, however according to the homework task "route" of the ticket class needs to remain a private field.
Here is my code for the method.
public int countTickets(String route) //HAD TO CHANGE Ticket class FIELD "ROUTE" TO PUBLIC!!!!
{
int index = 0; //returns the number of Ticket objects in the machine with the specified "route".
int ticketCounter = 0;
while (index < tickets.size())
[Code] ....
Is my general approach to the problem wrong? also is there a way to access a private field?
View Replies
View Related
Oct 12, 2003
I'm trying to figure out how to read in an integer and break it down into a sequence of individual digits in reverse order. Example: an integer input of 12345 gives an output of54321.
View Replies
View Related
Mar 16, 2014
i want create little program which enter the number, ant program says triangle exist or not. So code :
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[code]...
So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.
View Replies
View Related
Feb 11, 2014
We have a large applet based application with a current client-side minimum jar download size of ~4MB. If we put ALL of our class files into jars, that size will probably double. Most users only use a small portion of the class files for their particular tasks. Having ALL users download ALL the classes, compressed in jars, is extremely time consuming and a major problem after application updates due to the large number of users and the network load it would cause.
So after downloading some basic jars other needed individual class files are downloaded as and when requested by user. For signing applet, applet class files are moved to jar and this jar is signed with following attributes in manifest.
Jar file manifest:
Permissions: all-permissions
Codebase: *
Application-Name: XYZ
Application-Library-Allowable-Codebase: *
Trusted-Library: true
When applet is invoked from browser with JRE 1.7.51, there is a security blocked exception for individual files which are accessed from the signed applet jar. Why individual class files are blocked? Is it necessary to move all individual class files in a jar?
View Replies
View Related
Jan 9, 2015
I'm currently learning Java and have been set an assignment that requires me to do the following:
Write an application that reads in a line length followed by individual lines containing text. No input line will be longer than the read in line length. In the text lines each word will be separated by a single space. The lines of text to be reformatted and then output so that the output lines of text have straight left and right margins. The last printing character in each line will be at character position (line length). In the text output the character '.' is to be used to represent the space character.
Page 1 - Gyazo - d4f7da28285f16a2a0069ac1631290fa.png
Page 2 - Gyazo - 470cf689a3126b7ab6c64bb14ae80a0d.png
I'm trying to take this task on, but I'm unsure as to what exactly I'm supposed to do with part of it. For one of the methods I need to "work out how many extra spaces will need to be added to make the line width characters long.", how would I go about doing this?
View Replies
View Related
Mar 11, 2014
Write an application that inputs one number consisting of five digits from the user, separates the number into in individual digits and prints the digits separated from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each.
For example, if the user types in the number 42339,
the program should input 4 2 3 3 9.
Here is my code so far but I am stuck.
mport java.util.Scanner;
public class Seperating {
public static void main ( String[] args) {
Scanner input = new Scanner(System.in);
int number = 0 ;
System.out.printf("%d" , number );
System.out.print("Enter integer");
number = input.nextInt();
}
}
but I am not getting the result I wanted what am I doing wrong
View Replies
View Related
Sep 7, 2014
I have huge PDF files which are in booklet format. Example:
Assume a booklet pdf file has 24 pages which each page contains 2 pages which is in two sides - left side and right side.
The first page has 48th page number on the left side and 1st page number on the right side
The second page has 2nd page number on the left side and 47th page number on the right side
The third page has 46th page number on the left side and 3rd page number on the right side
I have vertically cut the Booket PDF files in to separate individual PDF files using bulk operation in separate folder.
for example, the cutted PDF file will be as follows in the above case
1st pdf file - 48th page
2nd pdf file - 1st page
3rd pdf file - 2nd page
4th pdf file - 47th page
5th pdf file - 46th page
6th pdf file - 3rd page..
Similarly for other PDF files too....if a PDF file has 95 pages....
the first page has 95th page number on the left side and 1st page number on the right side
Now the issue is how to rename and arrange the files correctly in the sequence for EACH PDF file so that we can merge the PDF file as one at last for each PDF file...
After renaming correctly in the proper sequence for the above file
1st pdf file should point to 1st page
2nd pdf file should point to 2nd page
3rd pdf file should point to 3rd page...
The problem is all the PDF files which we are planning to split will have different set of pages..example
PDF1 file - has 48 pages as above -> files should be renamed and arranged as 1, 2, 3, 4...48 correctly
PDF2 file - has 96 pages -> files should be renamed and arranged as 1, 2, 3, 4.....96 correctly
PDF3 file - has 56 pages -> files should be renamed and arranged as 1, 2, 3, 4.....56 correctly
Program which will rename the vertically cutted files in a proper sequence??
View Replies
View Related
Oct 28, 2014
import java.util.Scanner;
public class pdonahue_Perfect
{
public static void main (String args[])
{
int test;
int value=0;
Scanner input = new Scanner(System.in);
[code]....
i have just a couple of issues when running my program.
-First, When i enter 0 it should print..
Please enter a possible perfect number: 0
0:NOT PERFECT
-Second, when i get a perfect number. it should show the answer in descending order..
Please enter a possible perfect number: 6
6:3 2 1
mine shows: Please enter a possible perfect number: 6 6: 1 2 3
**everything else compiles correctly with no errors
View Replies
View Related