[Solved] Calling an array in constructor in Java [closed]

You seem to have the assignments reversed, public ChangePlane(String name, int[] array1){ this.name = name; this.array1 = array1; x1 = array1[0]; y1 = array1[1]; x2 = array1[2]; y2 = array1[3]; x3 = array1[4]; y3 = array1[5]; x4 = array1[6]; y4 = array1[7]; } Assuming you are passing an int[] array1 = new int[8]; (since array1[7] … Read more

[Solved] Need help to understand code [closed]

PizzaT array[] = new PizzaT[2]; //Would this be an instance? No, this is an array of PizzaT PizzaT pizzaList = new PizzaT(” “, “”, -1); //Would this be an instance? Yes, this is a PizzaT instance PizzaT(String n, String d, int m) //This must be the constructor Yes. A constructor looks like a method but … Read more

[Solved] How can I read a file and randomly pull information from it and add it to an array list? [closed]

Read the file sequentially – thats the easiest route. Then randomly shuffle the collection. Actually, another question. Could you use math.random() to look at the lines of the text file and if, lets say, the line 5 comes up then you remove it from the parameters you set for math.random()? It would pick from 0-9 … Read more

[Solved] Read data from mongodb using java [closed]

You should be able to cast DBObject to one of it’s implementation (see all implementations here : https://api.mongodb.com/java/3.0/com/mongodb/DBObject.html), in this case BasicDBList, which extends ArrayList , so you can use all methods from arrayList there. Mongo mongo = new Mongo(“localhost”, 27017); DB db = mongo.getDB(“test”);// Use DB DBObject allQuery = new BasicDBObject(); DBCollection collection = … Read more

[Solved] Why Random random = new Random()? [closed]

Just a note, the first commenter is correct, you probably could have found this through a bit of Googling, but here’s the answer as best as I can explain it: Let’s take that code: Random random = new Random(); The first random just says what type of data the variable is going to store – … Read more

[Solved] How to handle requests without or with incorrect query parameters [closed]

The best way to handle this would be: @RequestParam(name=”currency”, defaultValue=”EUR”) String currency or @RequestParam(name=”currency”, required=false) String currency In second case your should check the existance of currency in your in your controller. solved How to handle requests without or with incorrect query parameters [closed]

[Solved] how to test if Long ends with a number pattern on JAVA?

i agree with @shmosel solution. But it’s true just when second number has only 3 digits. boolean compareTail(long one, long two) { int digits =(int) Math.log10(two)+1; long formated = one % ((long) Math.pow(10, digits)); return formated == two; } 0 solved how to test if Long ends with a number pattern on JAVA?

[Solved] Java Class and Object

Actually from the example that you provided I can see that you don’t understand concept of object programming and even concept of functions. So please, start from begining. And if you want to print carry variable in method user() then you must change this method like this: void user(int a) { System.out.print(a); } and then … Read more