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
I have separated characters into an array that can be accessed from any method, however, when I try to compare the inputed guess to the computers random sequence, the counter always comes back as 0 (the comparison occurs in the checkColour method).
Java Code:
package mastermind; import java.util.Scanner; /** * Program Description: play a game of mastermind versus the computer */ public class Mastermind { private static int block1, block2, block3; private static String blockColour1, blockColour2, blockColour3;
[Code] ....
The counter is called colourCorrect.. But I think the problem lies more in me converting the strings (input and computerGuess) into char arrays, as if I output the values at position in the array, I get numbers (but the numbers are not character values from the ascii table).
I'm trying to create an algorithm that compares the first names of two people, which goes ahead and cancels similar characters and then counts the remaining characters to give a 0 if the remaining characters are even and a 1 if the remaining characters odd.
I want to create a program that takes n number of people (String vector) and assigns them a random group number (int) the range from 1 to k. The number n is evenly divided by k.
I have created a program that associates every String with a random int number. There is however the problem that the random generator just gives a random number, but doesn't make an equal number of people for each group. Which means even if the numbers are random, some of the numbers happen to come up more times than others.
How can I write, to make sure that each number is generated the same amount of times?
I need to make a program that keeps track of peoples names, allows you to add a note to each name and preferably would reorganize whatever you put in by date or by spelling. (I suppose the phonebook application in cell phones is a good match, a supermarket's list of foods and prices would work as well).
i need to write a method, that passes in an arraylist and a keyword,and display the name of all the people in the arrayList whose name contain the keyword (irrespective of uppercase or lowercase). how to write such a method ??
I am starting a program that is dealing with arrays. My issue, allowing a user to enter 'x' number of people into an array. How do I first allow them to enter the size of an array, and then enter strings (list) into that array. In addition to this, I need to specify the number of boxes of cookies sold by each person and keep a tally of the number of people selling cookies in each category (e.g. 1-10, 11-20...etc). Instead of having a number 100000, I want the user to enter that size, 'x'.
import java.util.Scanner; public class cookie { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = 100; double saleCount[] = new double [x]; String[] girlScout = new String[100000];
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.
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
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!!!
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?
I am experimenting with messages in JOptionPane and I was wondering why this program does not display anything when the choices are inputted.
*note: I tried putting "JOptionPane.showMessageDialog(null, "This is an information message", "Information", JOptionPane.INFORMATION_MESSAGE);" after the "int i = 0;" and then the messages displayed.
Scanner scan = new Scanner(System.in); int i = 0; while (i != 6) { System.out.println("1. Information message"); System.out.println("2. Error message"); System.out.println("3. Question message"); System.out.println("4. Plain message"); System.out.println("5. Warning message");
I'm having some trouble with my project. I have filled the getters using an array and what I now need to do is get the user to type in a day and print the corresponding getters to the lines the day is on in my text file.
{ File file = new File("DailyJobs.txt"); Job newJob = new Job(); try (Scanner scanner = new Scanner(file);)/> { while(scanner.hasNextLine()) { String line = scanner.nextLine();
[Code] ....
This is what I've attempted in terms of entering the day. It recognises the number of lines that has the inputted day but prints out only the very last job ID in the text file.
So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.
import java.util.Scanner; public class Random { public static void main(String [ ] args) {
public class Puppy{ int puppyAge; public Puppy(String name){ // This constructor has one parameter, name. System.out.println("Passed Name is :" + name ); } public void setAge( int age ){ puppyAge = age;
[Code] ....
How do I put 3 values of the each variable without replacing the last inputted one?
Like when I input "Tommy" and input another name "Gerald", "Tommy" won't be replaced by "Gerald" when I input again.
In this code, I have to do a series of tasks to change a String using specialized codes that are inputted. The one that I am having trouble with is as follows:
MC-SLXD: Circulates the sub-string in position S with a length of L, rotate the string X characters over in the direction of D. All the arguments (S,L,X and D will be one character in length. The direction will be either L or R for Left or Right.Example: MC-332R/COMPUTER = COPUMTER.
I can't seem to understand how to change certain line of text, inputted from a file. For this I really don't know where to begin. I have got the input from the file. But I want to change like very other line in the file. Can't seem to understand how this could be done. Is there away to access specific lines from the file and edit them? So far, i have this:
import java.util.*; import java.io.*; public class ChangeEveryOtherLine { public static void main(String[] args){ //Constructing file object representing input file File inputFile = new File("input.txt");
Conditions : Need to print all the inputted data(name,score) and the average.
import java.util.Scanner; public class Case2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] score = new int[5]; String[] name = new String[5]; int ave = 0;
The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?
Here is the main class:
public class MorseCode { public static String myInput; public static String[] myMorse; public static String myUserInput; public static char[] myAlph = {'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; public MorseCode()
I am writing a program that is supposed to take 3 numbers inputted by the user and sorting them out in an ascending order. I believe my code is correct but can't figure out why the program isn't behaving as expected.
import java.util.*; //Required to use the scanner console public class Week3_Programming_Problem { static Scanner console = new Scanner(System.in); //Allows for user input
I am trying my code which catches exception when mismatch variable is inputed as i read it with Scanner. It seems right for me but whenever i run it, it keeps leaking memory or something like that
Code :
import java.util.*; public class Exercise10_1 { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { boolean exception; do
I've been working on this problem for a while now and continue to get an error when I try to subtract one user inputted integer from another. It seems to compile fine for adding, dividing, and multiplying. Why it might be making that error and how to resolve it? (As an aside, I have no idea if I did the whole program right but am just trying to figure out why a declared int would come back with an error it's a string.)
import java.util.Scanner; public class Calculate2 { public static void main(String[] args) { int firstInt; int secondInt; int choice;