Display Name Of All People In ArrayList Containing Passed In Keyword
Dec 8, 2014
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 ??
View Replies
ADVERTISEMENT
Jun 14, 2014
I've come across something that i'm not overall sure about regarding the static keyword in Java.I'm making a vertical scrolling game where the player simply shoots enemies and they shoot back as they fall, dropping items if they die such as power ups and coins. I have an enemy called Bat and this is the bullet creation code in the update method:
if(oldPlayerY + 220 > posY && getBulletDelay > 0.90f){
batBullets.add(new Bullet(posX + 10, posY - 10));
getBulletDelay = 0;
}
The method is creating a new bullet object and it then adds that to the arraylist called batBullets, which is simple enough. I then need to access this arraylist in the main game update class so I can render those bullets on the screen, even if the bat dies. I was always taught that you use the static keyword when you need to access something from the class that doesn't require an object. Because of this, I have the following code.
for(Bullet bullet : Bat.batBullets){
bullet.setY(bullet.getY - 5); // Set the bullet to fall
renderMap.getSpriteBatch().draw(bullet.batBullet(), bullet.getX(), bullet.getY()); // render the bullets
}
This seems perfectly fine to me because I need to access the batBullet arraylist and it doesn't make sense to create a new bat object as I already have random spawning in place for them.
View Replies
View Related
Oct 11, 2014
my arraylist is declared in my main method. A string that i will be calling on is declared in my main method as well. The arraylist and string is passed to a method outside the main. I am to search for the beginning of a string and end of the string, remove those items. Then i am to pass the string with the removed items to arraylist that is called in my main with an enhanced for loop. The for loop then displays what is needed from the string and the method i created. I will posting an example of my main and method that is used in my program.
public class ExampleUrl {
public static void main(String[] args) throws MalformedURLException, IOException {
ArrayList<String> urlList = new ArrayList();
String url = "";
[Code].....
View Replies
View Related
Oct 7, 2014
What is the difference between the static keyword and transient keyword?
View Replies
View Related
Feb 9, 2015
I'm trying to get my output to be displayed without the brackets.The output looks like this
22 ([1, 2, 11])
33 ([1, 3, 11])
44 ([1, 2, 4, 11, 22])
55 ([1, 5, 11])
66 ([1, 2, 3, 6, 11, 22, 33])
77 ([1, 7, 11])
But I want it to have no brackets displayed so it looks like this
22 (1, 2, 11)
33 (1, 3, 11)
44 (1, 2, 4, 11, 22)
55 (1, 5, 11)
66 (1, 2, 3, 6, 11, 22, 33)
77 (1, 7, 11)
import java.util.ArrayList;
public class Palindrome {
public static void main(String[] args) {
int e = 0;
// palindromic composite number
int drome = 0;
[Code] ....
View Replies
View Related
Nov 6, 2013
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.
View Replies
View Related
Apr 2, 2015
I need assigning the selected hashmap values into a list and to display the values in a jsf page. The user will select certificates and will be stored in the below list:
private List<String> selectedCertificates = new ArrayList<String>();
The selectedCertificates will have the values ("AA","BB"). Now I will be passing the list into a hashmap in order to get the names and to display them on the jsf page.
My code is below:
Map<String, String> CertificatesNames =
new HashMap<String,String>(selectedCertificates.size());
CertificatesNames.put("AA", "Certificate A");
CertificatesNames.put("BB", "Certificate B");
CertificatesNames.put("CC", "Certificate C");
for(String key1: selectedCertificates) {
System.out.println(CertificatesNames.get(key1));
}
I want to display in my jsf page :
Certificate A
Certificate B
Now my issue is that is how to display all the values of the CertificatesNames.get(key1) in the jsf page as I tried to do the below and it printed all the values when I used the #{mybean.beans} using the :
List beans =
new ArrayList(CertificatesNames.values());
So how to do this?
View Replies
View Related
Jan 13, 2014
I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).
Resizing component; boolean dragging = false; // Give user some leeway for selections.
final int PROX_DIST = 3; Path2D.Double selectedPath; public Resizer(Resizing rz) {
component = rz; component.addMouseListener(this);
component.addMouseMotionListener(this);
[Code] .....
View Replies
View Related
Jan 18, 2014
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?
View Replies
View Related
Jan 13, 2015
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).
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
Feb 5, 2014
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];
[code]....
View Replies
View Related
Feb 14, 2014
Suppose I have
class A {
public void speak() {
System.out.println("I am class A");
}
}
class B extends A{
public void speak() {
System.out.println("I am class B");
}
}
class C extends B{
public void speak() {
System.out.println("I am class C");
}
}
Why this doesn't work while A is a super type of B ?
public static void insertElements(List<? super B> list){
list.add(new A()); //not OK, why?
}
View Replies
View Related
Feb 22, 2015
Why java uses the keyword extends when setting the bound of a type parameter(Generic) to an interface. I think using the keyword implements is more intuitive.
public static <T extends Comparable<T>>
why use extends? and not implements.
int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)
if (e.compareTo(elem) > 0)
++count;
return count;
}
I know if I want to set multiple bounds I will use extends keyword, and I will concatenate the bounds using & operator.
Is this a design decision to always use extends keyword to set bounds?
View Replies
View Related
Dec 2, 2014
I am attaching a document which shows the current state of my registry.What I want to know is if I can [safely] delete the JavaSoft folder with all lower subfolders, then re-install jdk1.6/0_31 which, I am told, is the current version being used here by developers.According to others on the development team (not my team), there COULD be something in the registry that is preventing both the installation of java jdk AND its uninstallation.Since I cannot seem to attach any kind of document.
View Replies
View Related
May 23, 2014
I need creating a java keyword program that can encipher and decipher a message using the provided keyword.
The keyword is :javbean
I have attached the message text as well...
public class Caesarcipher
{
public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args)
{
String theKey = "JAVBEANDEFGHIJKLMNOPQRSTUVWXYZ";
String text= "message.txt";
[Code] ....
message.txt (763bytes)
View Replies
View Related
Jul 9, 2014
The super keyword when used explicitly in a subclass constructor must be the first statement but what about if i have a this(parameters) statements ? As the this one must also be the first statement... Does this means that i can have only one or the other ? What about when the super constructor is not explicit (aka implicit ) , can i use the this( parameters) in the same constructor ?
View Replies
View Related
Nov 7, 2014
I've been trying for a while to get my exception output to print in a particular form to System.err.
What I'm looking for as output is
KeywordException: edu.cofc.csci221.KeywordException: **Keyword Not Found**
I'm getting
Keyword Exception: edu.cofc.csci221.KeywordException
at edu.cofc.csci221.CheckLine.checkForInvalidKeyword(CheckLine.java:101)
at edu.cofc.csci221.ReadLogFile.main(ReadLogFile.java:47)
The code:
line = scan.nextLine();
try { check.checkForInvalidSymbols(line); } catch (SymbolException sEx) { System.err.print("Symbol Exception: "); sEx.printStackTrace(); }
try { check.checkForInvalidKeyword(line); }catch (KeywordException kEx) { System.err.print("Keyword Exception: "); kEx.printStackTrace(); }
if(check.checkFirstKeyword(line) && line.split(" ")[0].equals(keywords[0])) { System.out.println(line); }
[Code] ....
I'm just unsure of where to go/what to do.
View Replies
View Related
Jan 3, 2015
//constructor
class Base
{
Base(int a) {
System.out.println("in base"+a);;
}
}
class Cons extends Base
[Code] .....
View Replies
View Related
Feb 20, 2015
How does the keyword this in the CoffeeSize class refer to the size of the coffee ? I am also confused as to how the CoffeeSize constructor comes into play to determine the cost.
public class Test
{
public static void orderCoffee(CoffeeSize size)
{
size.print();
}
public static void main(String[] args)
{
orderCoffee(CoffeeSize.SMALL);
}
[code]....
View Replies
View Related
Mar 7, 2014
I have a simple classes here one is interface and another one is abstract class when i try to compile them abstract class is givving compilation error.
public interface MyInterface{
public void getName();
public void getName(String s);
}
public class HelloWorld{}
abstract class SampleClass{
[code]....
View Replies
View Related
Feb 7, 2014
I am trying to test the instanceof keyword. To do this, I've made a method with a simple logical test like so:
Java Code:
Vehicle vehicle1 = new Vehicle();
public void Type(){
if (vehicle1 instanceof Vehicle) {
System.out.println("Type = Vehicle");
}
else if (vehicle1 instanceof Car) {
System.out.println("Type = Car");
}
else if (vehicle1 instanceof Truck) {
System.out.println("Type = Truck");
}
}
} mh_sh_highlight_all('java');
I wanted to try implementing it into the class definitions for Vehicle, then extend that to Car and Truck, but I'm not sure how to use this test in a general case.
The only way this method works is if I set the test to specifically accept a specific object as a parameter.
I want to test multiple objects, but I'm not really sure how else to do this without simply copy-pasting the logical test multiple times and changing the respective objects that are used as parameters.
View Replies
View Related
Feb 12, 2014
I need to search a txt file for a specific keyword and then output all the lines that contain that keyword. Right now I I think I have my search done but I don't know how I would print the whole line.
TextIO.readFile("xxx.txt");
String search;
String word;
int count=0;
TextIO.put("Please enter your search word: ");
search = TextIO.getln();
while (!TextIO.eof()) {
word = TextIO.getln();
count = count+1;
if (search.equalsIgnoreCase(word)==true){
TextIO.put(count + "-");
TextIO.put(word);
Right now it doesnt even let me enter in any values for the search. Not sure what I've done wrong..
View Replies
View Related
Jun 2, 2014
I have this very annoying issue with Eclipse (I have the latest version installed). For some reason, every time I use the "default" keyword in an interface, it gives me an error similar to "Syntax error on token default", I deleted the "default" keyword, the error is gone. The same thing happens with "Lambda expression as well", say I have this object like this :
Actions myActions = () -> {System.out.print("Blah blah blah");}; ,
Eclipse also displays the error message similar to "Method body expected after (), delete '->' ". I checked the Java version I have, it is the latest one also ....
View Replies
View Related
Oct 20, 2014
The only problem I am having is I cannot get my string plainText to go through the encode and prepareString methods.
Is there something in my methods that is wrong, or is it the way that I am calling them?
What is happening is if I enter "this is a test" as a plainText I am getting the samething back with no changes.
View Replies
View Related
Sep 29, 2014
I have this class:
package model;
import java.awt.Color;
import shapes.Oval;
import shapes.Rectangle;
import shapes.Shape;
import java.awt.Container;
import java.lang.reflect.Array;
[Code] .....
And as it is now, the values are not being passed into the shapeArray array. If I "hard code" two shapes into the array in this class, everything works fine later on, but I do not manage to pass values into the array from the createShape() method. I tried several approaches, nothing works.
View Replies
View Related