CounterTester - Output Not Decreasing In The Counter?
Jan 17, 2014
I believe I have this program CounterTester.java down but in my output the program is increasing the way I want it to but it is not decreasing the way I want it to.
public class CounterTester
{
static int myCount;
static int myCount2;
public CounterTester(int inti) {
myCount = 1;
myCount2 = 10;
[Code] .....
View Replies
ADVERTISEMENT
Oct 30, 2014
I have a given array of numbers, and I have to find the longest decreasing sub-array, but the thing is that the elements don't have to be next to each other!
For example, the longest decreasing sub-array for this array : 546 -156 165 -156 -56 -13 5
is 3 (check the bold numbers)
Until now, I have nearly finished my code, but I have one problem...
private static int decreasing(int[] a) {
int result=1, temp=0, br=1;
//Checking all the elements one by one:
for(int i=0;i<a.length;i++){
temp=a[i]; //placing the element on a temp value
[Code] ....
The problem with this code is that it's not smart.. let's say I have : 100 -500 90 80 70
Once it hits -500, none of the other if's with pass....
View Replies
View Related
Jul 11, 2014
I am trying to make a code that copies the users String to a char array. However, I am in a predicament: since I would not know the exact size of the users String I am left with the options of either making my array large by default, filled in with, lets say 25, empty spaces per index OR starting out with a default size of 1, with an empty space, and then some how increase the size from there.
At this moment I am leaning on the first option, creating a large default array and then deleting the unused values. However, this brings me to my actual question: if I set the non used indexes to null, if that wont give me an error, would that change the size of my array?
Ex:
//lets say i finally copied all of the values and this is the result
char[] word = {'b', 'o', 'b', ' ', ' '};
for(int i = word.length(); i > 0; i--){
if(word[i] == ' ')//delete the value so the size decreases
word[i] = null;//if possible
}
View Replies
View Related
Nov 27, 2014
I am trying to sort the 5 cards in decreasing order and this is exactly what my professor gave us but it has errors.
int pos;
int max;
for (pos = 0; pos < hand.length; pos++){
max = pos;
for (int i = pos + 1; i < hand.length; i++){
if (hand[max] < hand[i]){
max = i;
}
}
if (max != pos){
int temp = hand[pos];
hand[pos] = hand[max];
hand[max] = temp;
}
}
}
Line 6 has an error with the < operator.
Line 11&13 says cannot convert from card to Int.
This method is passing in Card[] hand
View Replies
View Related
Jan 17, 2014
Ok, so I'm making a game with a space ship that flies around the universe and discovering new planets. It works fine so far, but I'm looking to make it perform better and be better compatible with lesser-processors.So, I'm trying to put in an FPS counter and an entirely new game loop so that my game can decide for me what FPS I should use.
I have two classes. Heres the big, main one: [Java] package cyentw.game.src; import java.awt.Color; import java.awt.Font; impor - Pastebin.com *I want to change the loop and put an FPS counter in around line 456, you can scroll past the rest if you'd like*And heres the init frame one, in case you'd like to see it for some reason.
Java Code:
package cyentw.game.src;
import javax.swing.JFrame;
public class Start extends JFrame{
public static JFrame frame;
public static int WIDTH = 500;
public static int HEIGHT = 500;
public Start() {
[code]....
how to make my game loop as quickly (or a bit slower) as it can, and my FPS is static.
View Replies
View Related
Apr 7, 2014
I have a timer where it counts down from 300 to 0 then does something. But I want the display for the clock to show the time in minutes. I tried:
double showTimeLeft = timeLeft / 60;
o.setDisplay(String.format("%.2f", showTimeLeft) + " Minutes");
But Every so many seconds it skips like:
Time = 3.38
Time = 3.37
Time = 3.35
Time = 3.34
It skipped 3.56
How to do this right?
View Replies
View Related
Mar 22, 2015
I have a question related to the code below, that I do not understand. The aim is to count all files and subdirectories in an ArrayList full of files and subdirectories. So I have to count every file and every subdirectory.
The code concerning counting files is clear to me - every time d is of the type file I have to increment n by one. However I thought that I have to do the same thing in case d is a directory, so I would have written the same code for directories.
So what does "n += ((Directory) d).countAllFiles();" mean? In my understanding the method countAllFiles() is applied again on the object Directory ( as Directory is the class that contains this method), but how is n incremented by this? I thought n should be incremented by one as we did with files.
public int countAllFiles() {
int n = 0;
for(SystemFile d : content) {
if(d instanceof File) {
n++;
[Code] ....
View Replies
View Related
Mar 29, 2014
This is the code I have written so far. This program calculates tax from multiple tax payers.
import javax.swing.JOptionPane;
public class CalcutateTax
{
public static void main (String [] args)
[code]....
The problem is I cant think how to ask the use if he wants to calculate tax due for another taxpayer. If the user says yes, keep calculating, otherwise exit from the program. And how do I keep count of how many people got their tax calculated? Say for example,
JOptionPane.showMessageDialog (null, " We calculated tax for " + xnumber + " number of people.");
This is the question asked on my assignment ask the user if he wants to calculate the tax due for another taxpayer if so, do it again.At the end of the main method, output a message in a dialog box that says: Hello, We calculated taxes for [number of taxpayers].replace [number of taxpayers] with the actual number of taxpyers you calculated taxes for.
View Replies
View Related
Mar 29, 2015
Is it possible to declare a counter with a value outside of a for loop?
I have a counter that will end prematurely in a while loop during various iterations and I want to pick it back up in a catch all for loop at the end
Let's say I have a while loop
while(something) {
total++
}
then after I have a for loop that I want to start at total but would rather do that then make a new counter variable.
for(total;total < 20;total++)
Is something like this possible or is this a horrible thing to want anyways?
View Replies
View Related
Jan 11, 2015
I'm having trouble with my program for my class. The program just has to be able to have a button and show how many times a user has clicked it.
Every time I compile it I get errors such as:
unable to find symbol x where the code is executed when the button is clicked
What can I do?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;
public class Program {
public static void main(String[] args){
int x = 0;
[code]....
View Replies
View Related
Dec 28, 2014
i would like to increment variable by one every x ms is there any type of counter method to do so?
View Replies
View Related
Apr 28, 2015
I am a student in an intro to computer science class working on my final project. This is essentially a game of connect 4, but only requiring 3-in-a-row for victory. We were given the base game and a sample file to work with to make an AI that beats our professor's ai in the base game. Here is the base game
package cs110.project3;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
[code].....
View Replies
View Related
Jan 21, 2015
I have 2 classes a main one and another class. In the other class I have a method that has:
String gInfo(){
String[] Behavior = {"Sleeping", "Running home", "Studying", "playing pool", "walking to class"};
int rNum = (int) (Math.random() * Behavior.length);
return Behavior[rNum];
}
I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and how to get it to work correctly.
View Replies
View Related
Mar 23, 2014
I have an fps counter in my game loop:
public void run()
{
long currentTime,timeDiff;
prevTime = System.nanoTime();
accumulator = 0;
boolean TRUE = true;
[code]...
When I print the fps variable to the terminal window, it show a value of ~59.9998 - very close to the frameRate of 60. That is to be expected, and works well. The problem is that when I deliberately make the game go really slow, by spamming a bunch of enemies, the game looks slow, but the FPS is still apparently ~59.9998. I thought that maybe the paint() method was not calling when it was supposed to, but that might not be the case.
This FPS counter should be working, I can't see where I have gone wrong. Is there a problem with the code, or is there another problem that might cause the screen to be redrawn 10 times a second with an FPS of 60?
View Replies
View Related
Mar 4, 2014
Create a WordCounter class with a constructor that takes a file name as a parameter. The class should have two fields: one for the file name and one for a HashMap to store word count information. The constructor should call a private method, countWords, that reads in the file and counts the word frequencies. The class should contain a get method for each field, as well as a print method that prints out the map in the following format:word:frequency. When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)You should include the sample text file on Blackboard
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class WordCounter
[Code] .....
View Replies
View Related
May 15, 2015
I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?
View Replies
View Related
Nov 11, 2014
The point of this program is to search for a specific character in a text file. I want the program to find a character in the file "letterCounter.txt".
package lettercounter;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
[code]....
View Replies
View Related
Jun 11, 2014
I have to create a code that can calculate the number of upper case letters in a string that is entered by the user (below.)
Java Code:
import javax.swing.JOptionPane;
public class mainClass {
public static void main (String [] args) {
String userInput;
userInput = JOptionPane.showInputDialog("Enter a string.");
[Code] ....
My issue is that I would like the program to be able to function properly when spaces are entered into the string. As it is right now, I believe it is only processing the first string entered into the input box.
View Replies
View Related
Apr 1, 2014
I have two txt view
I have a counter that it starts from 0
I want it keep on to 30 and then stop and next txt view start from 0 to 30...
View Replies
View Related
Feb 15, 2015
We are writing our own classes and methods. My instructor has provide the code
/*-------------------------------------------------------------------------
import java.util.*;
public class Assignment5 {
public static void main (String[] args) {
[Code].....
I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.
[public int getNumberOfQuestions(){
numQuestions = 0;
numQuestions ++;
return numQuestions;
}
View Replies
View Related
Mar 7, 2015
While reading head first java i encountered a problem(Pg. 90 chapter 4 - mixed messages).
Suppose in a class(say A) outside main() a counter variable is declared and initialized to 0.
In main() declared the array of objects of the class A.
Consider a while loop in which we increment the counter as follows:
public class A{
int counter = 0;
public static void main(String[] args){
A[] arr = new A[20];
int x = 0;
while(x<4){
arr[x] = new A(); //arr[] is array object
arr[x].counter += 1;
x++;
}
}
};
what is the final value of counter ? will it be the same for all array objects.
View Replies
View Related
Jan 3, 2015
My code compiles and runs just fine, i'd just like to get creating a small square box that shows number of words used next to the "word count = ". i'd wanto to press the count words button to count and show the number in the square box. here is my code.
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class wordCount extends JFrame implements ActionListener
[Code] .....
View Replies
View Related
Sep 28, 2014
I'm trying to create a switch statement inside of a counter controlled (while) loop that asks for an input of...
"How many characters would you like to convert?"
Then you type in a number > 0, and then it should convert letters into the "1337" equivalent.
This is an example on what it should do.
How many characters would you like to convert? 5
Enter character #1 to convert: !
!-
Enter character #2 to convert: $
$-
Enter character #3 to convert: #
#-
Enter character #4 to convert: *
*-
Enter character #5 to convert: ,
, -
Whenever i try to run the program, i only get the- How many characters would you like to convert- i input 5 but then nothing else prints..
My codes..
System.out.print ( "How many characters would you like to convert?: " );
int convertCounter = 1;
char ch;
ch = input.next().charAt(0);
while (convertCounter > 0)
switch ( ch ){
[Code] ....
View Replies
View Related
Apr 21, 2015
Most of my code is done for making this Jeopardy game, the only problem I seem to have is to have variables that retain values after going through a loop, in this case the variables counter and score in the method responsePrompt
After going through the 25 questions, the value counter remains at 1, and score is either 1 or -1, nothing more, nothing less. I've had the variables initialized at 1 both inside and outside of the for loop. Full code below just in case it's something outside the method
import java.util.*;
import java.io.*;
public class Project10
{
public static void main(String[] args)
throws java.io.IOException
[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
Mar 3, 2015
I am creating cash counter application. i want to generate a pdf receipt in new window and print it.
I am using jsp to take input from user and servlets to process the input.
I am able to generate a pdf but in same page. i want it to be a popup menu. How to implement it?
View Replies
View Related