I am currently take a class, and trying to increment the count of employees I enter into an ArrayList by 1 for every entry. However, instead of incrementing by 1 each time, the current number of employeeIDs adds itself to itself, then adds 1, giving a non-sequential number (i.e. an employeeID of 75 will add itself to 75 + 1 to get a new employeeID of 151).
The following code is what I have done in terms of incrementing. (More coding has been done, but it is not used to increment, so I have omitted it.
public class Employee
{
// instance variables
private String firstName;
private String lastName;
private int employeeID;
static int newEmployeeID = 0;
public Map<Integer , String> Timeinterval(int value) { int i = 1440/value ; Map<Integer, String> timeInt = new HashMap<Integer, String>() ; DateTimeFormatter formatter = null ; for(int a=0 ; a< i ; a++) {
[Code] .....
The argument value gets it value from jsp at rumtime
The moment the control reaches at :- formatter = DateTimeFormat.forPattern("HH:mm");
it could not go beyond this . I executed this part
DateTimeFormat.forPattern("HH:mm"); by pressing cntrl+shift+I
and got this message :- could not resolve type: org.joda.time.format.DateTimeFormat
Basically what I want to do is increment time for eg: if time is 09:00 and I want to increment it by 30 then it should become 09:30 and this goes on till the time loop condition is satisfied, when i researched on net, I found out that Joda library is easirer to work with for such tasks.
I have an assignment where I need to increment an alphanumeric string by one. For example AAA123 + 1 = AAA124. I'm okay with incrementing alpha or incrementing numbers, but incrementing them all together is where I am stuck. Should I just convert the entire string to ascii and increment there?
I am trying to understand the following code.This return statement should actually return the char at myArray[index] first, then increments the index afterwords correct?
I have an array with the following characters {'E', 'L','E','P','H','A','N','T','P','O'}
now, I need an array that will store the first array such that only the occurence occurs e.g {'E','L','P','H','A','N','T','O'} Notice that the characters 'E' and 'P' occur twice and as a result were not repeated the second time in the new array.
How would one go about this using the counting elements technique?
I tried this but not sure how to use the counting elements technique.
char [] arr = new char{'E', 'L','E','P','H','A','N','T','P','O'}; char[] bucket = new char[(arr[0] * arr.length)]; for (int i = 0; i < len; i++) bucket[arr[i]]++;
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700 Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc { public static void main(String[] args) { double hours, minutes, length; double temp; int time = 2400; hours = time / 100; System.out.println("Hours are: " + hours);
I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner { public static void main(String str[]) throws IOException { Time time1 = new Time(14, 56); System.out.println("time1: " + time1); System.out.println("convert time1 to standard time: " + time1.convert()); System.out.println("time1: " + time1); System.out.print("increment time1 five times: "); time1.increment();
[code]....
The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time { private int hour; private int minute; public Time(int h, int m) { if(h > 1 && h < 23) hour = h;
I made this "lesson" to get the result of a pyramide which I succeded but not understand why im affraid..The thing is I dont understand exactly how to count it.. Isnt "j" incrementing every loop ?? In my head it should be just one star per line( the height is set to 3)how to count from the first loop to the last?I understand that println change the line though, but not why j would loop more than one time on each line..
I'm trying to count the number of elements in an ArrayList which also have duplicates. So for example, in an ArrayList of strings which contains cat, cat, dog, horse, zebra, zebra, the answer should be two.
If an element is found to be a duplicate, that element should then be exempt from the search so if that element is found again it should not increase the duplicate count.
Here is my code:
public int countDuplicates() { int duplicates = 0; // TODO: Write the code to get the number of duplicates in the list for (int i = 0; i < list.size()-1;i++) { boolean found = false;
[Code] ....
I know it's wrong because right now it's still increasing the duplicate count for elements that have already been detected as duplicates. How can I make it stop doing this?
I have having some trouble on counting the primitive operations on the pseudocode given below:
Algorithm 4. MaximumArray(Arr) Input: A 1-D numerical array Arr of size n 1) Let CurrentMax = a0 2) For i = 1 to n-1 3)If ai > CurrentMax Then CurrentMax = ai 4) End For Output: CurrentMax, the largest value in Arr
As of now, I know that for Line 1 there are 2 operations (one set and one read). I don't know how to figure out the for loop and If statement (line 2 and line 3 too).
I am currently trying to count and display all the vowels in a set of given strings and can't seem to figure out what to do. I was able to print the line with the most vowels, but i also need to display them. The code is listed below and the given output.
public class Strings { public static void main(String[] args) { String sentence = "I am currently studing Computer Science." + "My name is whatever and I am orginaially from the state of Virginia." + "I recenetly separated from the Air Force where I served on the Presidental Honor Guard.";
[Code] ....
The output that i am getting is:
I am currently studying Computer Science . My name is whatever and I am originally from the state of Virginia. I recently separated from the Air Force where I served on the Presidential Honor Guard.
The line with most vowels is:
I recently separated from the Air Force where I served on the Presidential Honor Guard.
(Count occurrence of numbers) Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Here is a sample run of the program:
Enter the integers between 1 and 100: 2 5 6 5 4 3 23 43 2 0 2 occurs 2 times 3 occurs 1 time 4 occurs 1 time 5 occurs 2 times 6 occurs 1 time 23 occurs 1 time 43 occurs 1 time
Note that if a number occurs more than one time, the plural word "times" is used in the output.
why exactly this isn't printing out the correct way.I'm supposed to print out 100 elements from an array but assign them random integers between 0 and 9.I've tried troubleshooting the issue and when I do it seems i'm only getting one element assigned.
public class Exercise_6_7{ public static void main(String[] args){ int[] counts = new int[100]; for(int i=0; i<counts.length; i++){ counts[i] = (int)(Math.random()*10);
In this array so many values are duplicates means 33 comes twice & 5 also comes twice & 9 comes three times. But I want to count the first value which is duplicate means 33 is first value which comes twice so answer would be 2.
I try:
public class FindFirstDuplicate { public static void main(String[] args) { int c=0; int[] a = {33,33,5,5,9,8,9,9}; outerloop: for(int i = 0; i < a.length; i++) {
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.
So I have 2 args[] one that reads the file name in the same directory and the other that tries to count how many of any letter (maybe even words) in the txt file ....
We have been given an assignment to create a small library, with the following classes Library, Book, Author and Copy. With a given class Biblio which has predefined code and adds the books to the class book in an arraylist in Class Copy.
The UML Domain is attached so you know the flow of the classes Everything is working fine and the generated output is correct.
There is just one method in class Library that is not working, the int method has to count the number of Copy's based on the Class Book (String):
I have to go through the Arraylist in Class Copy and look for a specific book and return the number of copy's.
I have tried multiple steps using a for loop Now I have found a similar post the uses hashset, I have tried below code but the return comes back with 0. (There are 3 copy's)
I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:
hello world how are you There are 0 words of length 0 There are 0 words of length 1 There are 0 words of length 2 There are 3 words of length 3 There are 0 words of length 4 There are 2 words of length 5
This is my code so far it sort of does the job but not the way i want it too
import java.util.Scanner; import java.util.StringTokenizer; public class Brown_Matthew_13117002{ public static int count(String s, int len){ int result=0; StringTokenizer st=new StringTokenizer(s,"[ ,;]");
[Code] ....
The output would end up being :
hello There are 0 words of length 0 world There are 0 words of length 1 how There are 0 words of length 2 are There are 3 words of length 3 you There are 0 words of length 4
I'm trying to get a timer to work to decrease the value of a stats bar (like Hunger Level, Energy Level), but it won't paint the bars in the first place, it won't let me start the timer (the start after t.start() is underlined) and now I'm getting an error that won't let me run it at all without putting public static void main (String [] args), even though adding it anywhere is causing other errors
public void hungerTimer () { int delay = 300; int period = 300; interval = 100; hungerBar.setValue(100); hungerBar.repaint(); timer = new Timer();
I have to write a program that takes an array of grades and calculate the average and then count the number of grades that are above average and also count the number of grades that are below average. This is what I have so far, it calculate the average and tells me how many are above average... where and how do I get to count how many are below average
public class arrays{ public static void main(String[] args) { final int grades = 5; double[] numbers = new double[grades]; double sum = 0;
Aeparated by blanks in a string. For simplicity, use strings without punctuation or other white space characters(tabs, newlines etc). Use a JTextArea to allow the user to enter the text and allow the text area to scroll if necessary. when the user clicks a button to count the words , the total number of words counted is displayed in a textbox that cannot be modified by the user.
now my problem is that i am not getting the counted number to display in the un-editable textbox. i also have the problem where the cusrsor is showing in the middle of the input screen instead of at the top.
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*; import java.util.*; public class WordCounter extends JFrame implements ActionListener
I am attempting to count the unique strings (a.k.a flowers) in the array along with a count of any duplicates. An example is embedded in my code below. I've only pasted the part of the program I am having trouble with. I can't figure out what I am doing incorrectly.
private void displayFlowers(String flowerPack[]) { // TODO: Display only the unique flowers along with a count of any duplicates /* * For example it should say