Where should I keep a collection of instances of my custom class? In the class itself in a static variable?
class Item {
int quantity;
static ArrayList<Item> list = new ArrayList<Item>();
Item(int q) {
quantity = q;
list.add(this);
}
// Some methods and whatnot.
}
Is it fine like this or should I implement the collection elsewhere? What say you?
I'm doubted regarding the implementation of Collections.binarySearch() method on an ArrayList of objects of a custom class Movie.
Here is the movie class :
public class Movie implements Comparable<Movie> { String movieName; String rating; String director; String theme;
[Code] .....
The sort/binarySearch in searchByMovieName function is done with natural sorting (and Comparable Interface in Movie class). I mean no comparators involved here. And the comparator that I used for sorting/binarySearching on Movies Director attribute in searchByMovieDirector function is :
public class MovieDirectorComparator implements Comparator<Movie> { public int compare(Movie movie1, Movie movie2) { return movie1.getDirector().compareToIgnoreCase(movie2.getDirector()); } }
But I was not able to implement binarySearch ?? How to implement the binarySearch here. I have google to see only binarySearch working on Arrays or probably ArrayList of String only, but not on ArrayList of custom objects.
How do you declare methods for a class within the class whilst objects of the class are declared else where?
Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).
I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.
Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?
I'm trying to create Web Services with Eclipse (Java Runtime 7 (also tried 8) Tomcat 7 (also tried 8).Web Service with parameter "byte[]" and return value "byte[]" works fine.Web Service with parameter "myOwnClass" and return value "myOwnClass" works also fine.But if I have a "byte[]" element in "myOwnClass" and I run my Client test program I get the following error:
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.lang.NumberFormatException: For input string: "MTExMTExMTExMQ=="
Why? I don't have any numeric element (such as int ...) in my class members!?
package core; import java.util.ArrayList; import org.lwjgl.input.Keyboard; public class Input{ public static final int num_key = 78; private static ArrayList<Integer> currrentkeys = new ArrayList<Integer>(); private static ArrayList<Integer> downkeys= new ArrayList<Integer>(); private static ArrayList<Integer> upkeys = new ArrayList<Integer>();
So for some reason my app works fine when I enter in the new expenses (option 2 when starting app).Then when I want to look up the total expenses in a month (case 5 then case 2), it doesn't show up and brings me back to the original option screen.So for some reason it must be breaking right back to it? I am really confused as to where this error could be coming from.
I'm trying to create a Texas hold'em Poker application. A rough idea of it would be similar to those poker games on the playstore e.g. Zynga Poker, however it will be a simplified version, more of a home-based application, for a small group of friends. This way, we can get to play poker on the go with each other, like a private table on the go. Anyway, right now how do I get started?
1) How should I even start this project? Do I start the GUI for the application first? Start designing the applications with photoshop? I figured I need a skeletal guide to start and follow.
2) How do I connect all the players together to a table? I know I could use my phone as a Server, where the rest could connect to mine. But I'm not sure what I should research on. Also, as I'm working towards a "Portable, On the go Application". So I would like to work this more based on 3G/4G networks.
3) Database, I would like something to keep a record on the buy-in, winnings & losings so we can keep track of it. However, if the server was my phone. When I turn off the server, would the database be gone? Maybe I might be able to save it on a notepad in a folder on my phone? I think this is possible.
To deploy my project into %TOMCAT_HOME%webapps folder. Right click on Project ->Export-> War File Project Name: Hello Destination: D:Program FilesApache Software FoundationTomcat 6.0webappsHello.war
Result found in web browser:
HTTP Status 404 - /Hello/first And Hello.war file is not found in webapps folder too after exporting as .war. I am using Apache tomcat 6.0.37, eclipse 3.7.2 release, tomcat plugin :com.sysdeo.eclipse.tomcat_3.3.0
So I have a class called Team that is a collection of players and managers for a baseball team, and one of my required methods is to calculate the total amount of Home Runs hit by the batters. Now along with the Team class I have an abstract Employee class, an abstract Player class and a Batter class that extends the Player class I thought this would be fairly easy but it is coming out to be pretty hard my code is as follow:
class Team { public int _numPitcher; public int _numBatter; public String _manager; public ArrayList<Player> team;
[Code] ....
The total salary works awesome but for some reason when I try and call up how many home runs a player has it wont call correctly I get this red line under my code that says: The method getHomeRuns() is undefined for type Player. I am trying to call this from the batter class which is an extension of the Player class...
So I'm still trying to get to grips with Java, and like to understand exactly why I'm doing something, so that I am not just regurgitating the code, If I want to create an object from class "Apples", I would use the following, right?
Apples MyAppleObject = new Apples();
From what I understand, MyAppleObject is the new object name, new -> creates a new instance of it in memory, and Apples() is the onCreate method that is called
So question 1: (just a quick aside question) Can I create an object without calling Apples()? i.e.
Apples MyAppleObject = new;
Question 2: - PARTLY SOLVED - I discovered that (Button) is a way of typecasting, so I understand that line a little better. What I don't understand is why we don't need to initialize the object with "new"
I've now looked at a bit of android development and xml and those declarations are all together different, and I'm not sure why. I haven't found a single explanation for the difference in format.
Java Code:
Button Add; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Add = (Button) findViewById(R.id.button1); mh_sh_highlight_all('java'); So the Button object is declared above the onCreate method, but initialized afterwards I guess....
But instead of using Button Add = new Button() they use Add = (Button) findViewById(R.id.button1);
Question 3:
then In XML they use the following:
Java Code:
public*static*void*main(String[] args){ ********* ********// Creates a DOM object in memory. Now you can access ********// data in the xml file ********* ********Document xmlDoc = getDocument("./src/tvshows5.xml"); mh_sh_highlight_all('java');
Once again, why didn't they have to use : Document xmlDoc = new Document()
Having trouble adding Class (Dollar) objects to a HashSet (money), i have done this before with arraylists and i understand that HashSets are different in that they cannot contain duplicates. Currently when this code is compiled i am getting "null" printed when I run the "howFullDatWallet" method.
import java.util.*; public class Wallet { private HashSet<Dollar> money; private int walletSize = 0; private int walletFiller = 0; /** * Constructor for objects of class Pocket */ public Pocket(int walletCap)
I've been unable to figure out how to access an objects data from another class. I ended up missing a lesson in java and haven't been able to catch up on this topic on my own through my textbook.
Error: has private access
Code:
public class TestCoffeeDrinker { public static void main(String[] args) { Coffee latte = new Coffee("Starbucks Tall Latte", 2.85); Coffee mocha = new Coffee("Starbucks Grande Mocha", 3.95); Coffee mcdonalds = new Coffee("McDonalds McCafe", 0.99); System.out.println(mcdonalds.toString());
I'm really new to object/class concepts and already having difficulties with applying them. How to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.
Java Code:
public Exam(String firstName, String lastName, int ID, String examType, int score) { this.firstName = firstName; this.lastName = lastName; this.ID = ID; this.examType = examType; this.score = score;
I'm really new to object/class concepts and already having difficulties with applying them. how to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.
public Exam(String firstName, String lastName, int ID, String examType, int score)
package com.Lists; public class EmployeeOffice implements EmpInterface { private double salary; private String name; private String postion; private double hoursWorked;
[Code] .....
So if i wanna sort this Generic class using comaparator what do i do... I cant find an answer to this... I wanna sort them on the basis of salary what to do ...
So I'm beginning to learn java with the book HeadFirst Java. The books says that all a tester class does is create objects of a new type and then use the dot operator...
I don't really understand what a tester class is and what it does ? and what is the Dot operator and how does it work ?