Program That Counts How Many Times A Letter Is Written

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


ADVERTISEMENT

Hangman Type Game - How Many Times Each Guessed Letter Occurs Within The Word

Jul 31, 2014

The game runs fine, however I have to include how many times each letter that is guessed occurs within the word. For example, if the guess is e, the program should print out: The character e occurs in 3 positions. How would I go about doing this??

/*
* A program that plays simple word guessing game. In this game the user provides a list of words to the program.
* The program randomly selects one of the words to be guessed from this list.
* The player then guesses letters in an attempt to figure out what the hidden word might be.
* The number of guesses that the user takes are tracked and reported at the end of the game.
*/

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

[Code] .....

View Replies View Related

Pythagorean Theorem Program - Code Isn't Working When Written In OOP Style

Feb 11, 2014

I'm attempting to make a simple Pythagorean Theorem program (A squared + B squared = C squared) but am running into problems when I write it as object oriented. The darn thing works when written as a simple process, but that isn't Java now is it? Here's the simple:

public class PythagoreanTheorem extends ConsoleProgram {
public void run() {
println ("Finding C from A and B.");
double a1 = readDouble("Input A: ");
double b1 = readDouble("Input B: ");
double aSq = (a1*a1);
double bSq = (b1*b1);
double cSq = (aSq + bSq);
double c = Math.sqrt(cSq);
println ("C = " + c);

[code]....

View Replies View Related

Method That Counts Registered Persons In A Program

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

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 View Related

Program That Continuously Asks For Alphabet Letter And Stops When Non-Alphabet Letter Entered

Oct 8, 2014

Write a program that continuously asks for an alphabet letter, and stops when a non-alphabet letter is entered. Then output the number of upper case letters, lower case letters, and vowels entered ....

View Replies View Related

Strings - Change Every Capital Letter Into Small Letter And Vise Versa

Oct 22, 2014

I have a problem with functions connected to strings.

I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.

lowercase= "abcde...z" and

uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.

There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".

How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.

View Replies View Related

How To Get 1st Letter Of Input (String) And Compare It To Single Letter Before Insert To DB

Apr 15, 2014

Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database

code = "A"001
name ="Angela"
= success this will inserted into database

else

code ="B"002
name="Angela"
=failed this will not inserted into database

else

code="A"003
name="Andy"
=success still accepts the input cause they have diff code number

What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?

View Replies View Related

Recursive Program To Change Two Four Letter Words Into Each Other?

Oct 28, 2014

SO for my project, we have to create a program where we input two four letter words, and using a list of words our teacher provided us and only changing one letter at a time, make the words match.For example, you input BALD and CALL and it would output BALD BALL CALLWe have to use recursion to do this, and I'm totally lost as to where to even begin.

View Replies View Related

How To Make A Program Run Multiple Times

May 18, 2014

I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.

package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {

[Code] .....

View Replies View Related

Program To Convert All Vowels To Capital Letter In A Sentence?

Jul 3, 2014

i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner. if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing

public class Demo2
{
public static void main(String[] args)
{
String s1="hi how are you";
s1=s1.replace('a', 'A');
s1 =s1.replace('e', 'E');
s1 =s1.replace('i', 'I');

[Code]...

this is working properly.

but when i trying with Scanner i am facing problem.

public class Demo2
{
public static void main(String[] args)
{
java.util.Scanner scn= new java.util.Scanner(System.in)
String s1=scn.next();
s1=s1.replace('a', 'A');

[Code]...

View Replies View Related

Java Program That Converts Number Grades To Letter?

Aug 3, 2014

I wrote a java application that coverts number grades to letter grades. Here is what it looks like:

/java application to That corresponds the letter grade with the number grade
import java.util.Scanner; //program uses the class scanner
public class gradescore{

[Code]....

View Replies View Related

Everything In ArrayList Written Twice

Mar 1, 2014

I am trying to read a file into an array list, change some things about it, and then write it to another file. Files are getting written with what was read repeating a second time. I've tested the read method by having it print everything which goes into the ArrayList object. I then did the same with the write method which seems to write everything twice, as if everything is in the ArrayList twice, but I'm not sure how this is possible, since the read clearly did everything only once. Perhaps the ArrayList isn't the best collection to use for this purpose.

The read method:

Java Code:

private ArrayList<String> read(File in) {
String line;
ArrayList<String> data = new ArrayList<String>();
try {
BufferedReader r = new BufferedReader(new FileReader(in));

[code]....

View Replies View Related

How To Get A Program To Repeat X Amount Of Times Automatically

Oct 27, 2014

Ii am trying run a do while loop on java a specific amount of times for example if i were to type in "Enter number of years" and enter 4. i need the loop to execute 4 times or if i said 6 times then i would be 6. the program i have repeats it and takes it back to reentering "Enter number of years" i need it to execute by its self x amount of times. here is what i have so far

System.out.println("Enter the number of years: ");
years = keyboard.nextInt();
rainfall = generator.nextInt(10) + 1;
System.out.println("Year " + "rainfall amounts were");;
for (int months = 1; months <= 12; months++)

[Code]...

View Replies View Related

Java Hangman Program - Replace Correct Letter With The Blanks

Apr 28, 2014

How to replace correct letter with the blanks in the program. Last method in program used to print correct letters.

import java.util.*;
import java.io.*;
public class Hangman {
public static Scanner keyboard;
public static final int MAXSIZE = 15000;
public static final int NUM_GUESS = 8;
public static final int WORD_LENGTH = 20;

[Code] ....

View Replies View Related

Write A Program That Translates A Number Between 0 And 4 Into Closest Letter Grade

Oct 8, 2014

Write a program that translates a number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B. Break ties in favor of the better grade; for example 2.85 should be a B. Use a class Grade with a method getNumericGrade. why when I type .3 it tells me "Exception in thread "main" java.util.InputMismatchException" Or if there is an easier way to do this.

import java.util.Scanner;
public class Grades {
public static void main(String [] args) {
System.out.println("Enter a number between 0 and 4");
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Unable To Set Text To A Label Multiple Times In Same Program

Aug 5, 2014

I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.

I am using java 1.7 sdk and pupy linux as OS. Below i am giving source code.

What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.

But what is happening is it shows welcome text and then directly Plzz wait..

Its not showing text Enter... because control is finished after last method gets executed.

My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.

public class BackgroundFrame extends javax.swing.JFrame {

JLabel setTitle1;
JLabel setTitle2;
JLabel setTitle3;
JLabel setTitle4;

[Code] ....

View Replies View Related

Program To Roll 1000 Times And Count How Many 7s Rolled

Nov 15, 2014

public class PairOfDice
{
private Die die1, die2;
public PairOfDice() {
die1 = new Die();
die2 = new Die();

[Code] .....

I am struggling with the final part of my code to get the dice to roll 1000 times and tell me how many times a 7 was rolled. I am getting these errors in jgrasp

----jGRASP exec: javac -g PairOfDice.java

PairOfDice.java:34: error: <identifier> expected
count = 0;
^
PairOfDice.java:35: error: illegal start of type
for (rep = 1; rep <= 1000; rep++) {

[Code] .....

22 errors

View Replies View Related

Create A Program That Will Deny Access To Browsers During Certain Times Of Day

Jan 2, 2014

My goal here is to create a program that will deny access to the browsers during certain times of the day. The research that I have done makes this out to be near impossible (using signal handlers in java). where to start, if its possible, or anything else im missing. (System is windows 7).

View Replies View Related

I/O / Streams :: Reading From And Writing To A File Then Read Again Including Data Written

Oct 11, 2014

I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)

1
FOR SALE:
Emmalaan 23
3051JC Rotterdam
7 rooms
buyprice 300000
energylevel C

The user gets (let's say for simplicity) 3 options:

1. Add a House to the file,
2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and
3. Close the application.

This is how I start:

Scanner sc = new Scanner (System.in);
while (!endLoop) {
System.out.println("Make a choice);
System.out.println("1) Add House");
System.out.println("2) Show Houses");
System.out.println("3) Exit");
int choice = sc.nextInt();

Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).

For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)

If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).

My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this

View Replies View Related

Counter Set Up For 20 People But Only Counts 19 If Error Inputted In GenreType

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

Minesweeper - Print Out MxN Game And Neighboring Bomb Counts

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

Java Code That Asks User For Integer And Then Counts Down From That Number To 0

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

Counts Ticket Objects In ArrayList - Accessing Private Fields

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

Three Letter Acronym

May 20, 2014

import javax.swing.*;
public class ThreeLetterAcronym{
public static void main(String[] args){
String phrase = "";
String firstWord = "";

[Code] ....

View Replies View Related

How To Print 5th Letter Of A String

Nov 11, 2014

So if I wanted to tell the user that the fifth letter they entered is "____" how would I do that.

I am prompting the user to enter a word and then displaying the length of the String. Now I want to display to the user what the fifth letter of the String they entered is.

import java.util.Scanner;
public class StringPractice
{
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
String word;
int lenght;

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved