I am doing the sorting of multiple fields. This sorting requires to sort the emergency numbers first followed by queue time. However, the sorting is fail, which is the emergency numbers are sorted correctly only but not the queue time. I try to figure out the problem but unfortunately I cannot find where the problem is. Below are the codes for my assignment (Please take note that there is no need to check both ListInterface and LList class) :
public interface ListInterface<T> {
public boolean add(T newEntry);
public boolean add(int newPosition, T newEntry);
public T remove(int givenPosition);
public void clear();
[code]....
This is the attachment of the result that I ran earlier:
Capture.jpg
The first list is before sorting while the second list is after sorting.
I am trying to find a concise way to write the sort methods for my class. I am supposed to make a program that can sort objects by a number of fields: year, rank, artist and title.
I used an idea from this thread : java - Sorting a collection of objects - Stack Overflow
And I am trying to use the custom comparator for my sort methods. However for some reason, the sortingBy variable fails to recognize any of the enum types.
Whenever I try to set the sortingBy variable equal to one of them, for example:
Java Code:
private Order sortingBy = Year; mh_sh_highlight_all('java');
I get a "Year cannot be resolved to a variable" error.
What I want to be able to do is make it so every time a specific method is called, say, for example sortTitle(), sortingBy will change to Title, then the SongComparator will sort using the case Title.
Is it possible to do this? I can't figure out how to modify SongComparator's object variables that way.
Java Code:
import java.util.Comparator; public class SongComparator implements Comparator<Song> { public enum Order {Year, Rank, Artist, Title} public Order sortingBy;
This was shown in class the other day and I'm still not sure of how exactly it works, even after looking at it through a debugger.
public void sort(){ for (int i = 0; i < size; i++) { Node temp1 = head; Node temp2 = head; Node temp3 = head; while(temp2.next!=null){ temp3 = temp2.next;
[Code]...
Again, I didn't write this code I'm just trying to understand it. Why specifically do three different temp values need to be used instead of just one like in most sorts?
It is part of a larger program that can be found below.
import java.util.Random; public class MyQueue implements IntegerQueue{ class Node{ Node next; Integer data; Node(Integer data){ this.data = data;
I have done one program, that calculates the Least Common Multiple. The idea is to use WindowsBuilder on Ecplise in order to run it in a separate window. But when I started nothing happens. The code is:
Just wondering what could I do to make it happen. One thing came up on my mind - this is that need to connect the button with the function of the method, but still not sure will work.
how to differ between fields that are not exists to fields that are null? because in my api when someone wants to delete a field he sends null instead of a value. and if he doesnt want to effect this feild he doesnt send it.
I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class FaceTest { public static void main(String[] args) { String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
This is the link [URL] and it says One significant difference between classes and interfaces is that classes can have fields whereas interfaces cannot.How can this be possible?
At the end of my main method, I want it to print out the input given that should have been stored in my sandwich class fields, but it didn't.
import java.util.*; import java.lang.*; public class SandwichBuilder { public static void main(String[] args) { Scanner inputDevice = new Scanner(System.in);
I am unsure of something. In the following class, which is read first; the static field or the main method?
class Test{ static int a = 3; public static void main(String args []) { //some code} }
I put some code in Eclipse and have tried to look at the hierarchy. It would point to all static fields being initialized in order from top to bottom, including the main method.I had thought that the main method was always the first thing in a public class to be initialized, regardless of where in the code it resides. Am I reading the Eclipse hierarchy wrong? I find Eclipse very difficult, especially since I typically code in Textmate. I just want to see how my code is operated upon,
If I define a class which contains a few static fields, and then have a few classes who inherit this class, then all these classes would have the static field as well. Now my question is the following: would all those sub classes (and the base class itself) share the same object, or would each class have one object for all it's instances?
I have a simple class, called InputManager, which has methods that communicate with another class DatabaseManager which has access to Database which is actually object that contains information about actual database.
My JFrame has Navigation class (extends JPanel). There I put all needed JButtons, JLists and so on.. This class has instance of InputManager and when user interacts with GUI components inside of it, Navigation calls InputManager methods, it then analyses the call and calls needed methods on DeviceManager, which then sends queries to Database and etc.
The problem is, that at the beginning (when user runs a program), I want to get information (which is actually values for my GUI components ) from Database. It could, for example, create another DatabaseManager and connect to the Database to get information, but it is okay to have two objects?
I was also thinking about sending same DatabaseManager object through InputManager to Navigation, but it seems strange for me to have two objects, which can interact with each other in both directions(Class A has instance of Class B, and Class B has instance of Class A). Is there anything bad this can do?
Also what I noticed that it seems odd that GUI class would have to get information from database. (Logic in GUI class).
I have a button in which I need to do the following:
After I click it It reads the values given in a jtextfield1 and in the other jtextfields I need it to settext in them from the database I mean if I have for example id=1 when I click the button it goes to the database and find the id 1 then write the infos in the other textfields
i need to seek all data in result set one by one.i excuted a query which i don't know the result of it...it could be have one result in result set or 10 result.i tested this code :
PHP Code:
Query = "select * from book" while (Rs.next)) { row.add(new Book(Rs.getString(i)));
//Book is a class
}
but didn't work. do we have any other way we seek the result set without rs.next() ???
I have a web application. I want to generate the UI part(basically html/jsp pages) to be generated dynamically using drag and drop of elements.So is there is any way that I can:
1: Have drag and drop of elements in jsps? 2: How I can create and store back the form attributes dynamically?
Here is my code for an inventory program. No matter what I do, I can't get the text fields to display in the program.
The Inventory Program Class
import java.awt.GridLayout; // required to create a grid layout import java.awt.BorderLayout; // required to create a border layout import java.awt.event.ActionEvent; // required for click events
So I have an Enum file with 119 constants and each constant of that type has 20 fields that come with it. All the fields are the same type and named the same (e.g. there are 119 of Object obj, one for each constant), and I want to run the same methods over them. Since the Objects of the same type are named the same for each constant, I just have them named explicitly in get-er methods.
This worked fine when I just put all 20 fields through the constructor and set them as fields under all the constants. But I realized that if I wanted to make an instance of this Enum class, I'd have to enter in all 20 fields when they are all a set of Objects with unique values. So I then put them as fields under their own respective constant to make it easier to create instances of this enum. But now my methods don't work.
A) I don't really understand why they don't work anymore? B) Is there a way to fix it without putting all the methods under each constant?
Example:
public enum MyEnum { AAA { private MyObject obj = new MyObject (3.0); }, BBB { private MyObject obj = new MyObject (1.5); }, CCC { private MyObject obj = new MyObject (6.5); }, DDD { private MyObject obj = new MyObject (3.5); };
public double getObjVal() { return obj.value(); // it can't find this obj should I move it up to where the constants are declared? } }
What should be the code if i want to input a different string in case of the typed string. The case is : I have a predefined string S = "Peter,please answer my question" and now when i input another string inside the text field character by character i want characters from the string S to enter instead of the input string. In short, the input string should be disguised as string S.
My code's objective is to serialize and deserialize to a file. I'm in the process of revising the code to allow multiple serializations and deserializations, but for now the code's limited to one serialization and deserialization. I'm also debugging one error, before I debug several others. I've limited my debugging question by accessing the field of one deserialization.
This is the code on pastie: [Code] ....
How to display the code on coderanch? I don't understand how to use the code widget.
I can successfully serialize an object, but I cannot deserialize it and access its fields. If you execute the program, create a new file, add ONE FullTimeEmployee object to the file and then read its firstName field, you'll be returned null.
I'm certain I initialized the field by using a constructor. I'm also pretty sure that I correctly casted Object (if I'm not mistaken,the generic type for a deserialization) into FullTimeEmployee
I have an assignment to write a Payroll class that uses the following arrays as fields:
-employeeID - An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 -hours - An array of seven integers to hold the number of hours worked by each employee -payRate - An array of seven doubles to hold each employees hourly pay rate -wages - An array of seven doubles to hold each employees gross wages
The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeID array. That same employee's pay rate should be stored in element 0 of the payRate array. In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employee's identification number as an argument and returns the gross pay for that employee. Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employee's hours and pay rate. It should then display each employee's identification number and gross wages. Input Validation: Do not accept negative values for hours or numbers less than 6.00 for pay rate.
I'm off to a great start, however I'm stumped on how to pass the payrate for each employee into the array, then grab that data in order to calculate the gross wage for each employee and store THAT in its own array. THEN I'll have to output that data to each employee.
Code is shown below.
import java.util.Scanner; import java.text.DecimalFormat; public class PayrollProgram { public static void main(String[] args) { Scanner userInput = new Scanner(System.in); DecimalFormat df = new DecimalFormat("0.00");
Which is considered clearer and better for naming?
class SpeedAnimation { //rate to increment frames at 0 speed public float baseIncrementRate; //additional rate to increment frames at, scaled by the speed public float speedIncrementMultiplier; //current fractional frame index public float currentFrameIndex; //give the upper and lower index bounds to animate between public int startingIndex; public int endingIndex; }
vs.
class SpeedAnimation { //rate to increment frames at 0 speed public float base; //additional rate to increment frames at, scaled by the speed public float multiplier; //current fractional frame index public float index; //give the upper and lower index bounds to animate between public int start; public int end; }
I've always been really elaborate with my names, because I thought that being more descriptive is more precise and lowers the chance that names might clash with each other, but then I noticed that a lot of my code becomes really lengthy and tiring to read, ie.:
I have been given a question about a object creation resulting in the constructor of the Time class being called, and to write the constructor's header new Time(21, 39, 55);
So, this would be simply "public Time" and have to give meaningful names to formal parameters, which is what i don't understand. Is it just private int hours; etc? I have also been told to attempt to write the body of the constructor and will need to estimate how the code in the body will work and to invent some fields.
I have a program that using one JFrame which opens one of two JDialog windows depending on which button is pressed.
How do I assign listeners to the buttons and fields on the JDialog window? I added listeners on the View end, but how do I process them? I tried adding the '..implements ActionListener" class in the main Controller but it does not recognize/hear anything.
A blood clinic has hired a team of software developers to build a custom application to track patients. The clinic needs to keep a record of each patient and his or her blood data. Ultimately, they want all of the information stored in a database. As a starting point, the development team leader informs the team that the application has to have a set of core classes that represent the “real-world” entities the program needs to deal with. As a developer on the team, your job is to build a Patient class along with a BloodData class so that each Patient contains a BloodData object. This principle is known as “composition.”
Building the Framework Begin by creating a public Java class named PatientBuilder that contains a main method. Then, in the same file, create a non-public class named Patient and another named BloodType. Save the file as PatientBuilder.java. Note: If this was a real development project, you would put each class into it’s own file and put the files in the same folder. By combining them all into one file, we avoid having to submit three separate files, making it easier to keep all your work in one place.The BloodData Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective:
• Create a field to hold a blood type. The four possible blood types are O, A,B, and AB. For this project, you can simply define the field as a String. • Create a field to hold the Rh factor. The two possible Rh factors are + and –.For this project, you can simply define the field as a String. • Create getter and setter methods for both fields. • Create a default constructor that sets the fields to “O” and “+” • Create an overloaded constructor that accepts two parameters – one for a proposed blood type, and another for a proposed Rh. The constructor should call the set methods and pass these parameter variables in to them.The Patient Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective: • Create a field to hold an ID number along with get and set methods. • Create a field to hold the patient’s age along with get and set methods. • Create a field to hold the BloodData for a Patient. When declaring the field, initialize it by instantiating a BloodData object. Create get and set methods. • Create a default constructor that sets the ID to “0”, age to 0, blood type of the BloodData object to “O”, and Rh value of the BloodData object to “+”. • Create an overloaded constructor that accepts the following parameters: ID,age, blood type, and Rh. The constructor should call the set methods for the field associated with each parameter.The PatientBuilder Class.This class should contain the main method from which the program runs. In that method, implement the following functionality:• Ask the user for the ID, age, blood type, and Rh factor of a Patient. • Create a Patient object, passing all of the data obtained from the user into the object. • Write the code necessary to display the ID, age, blood type, and Rh factor of the Patient by calling the appropriate get methods of the object.
MY CODE ( which does not compile since it is wrong...)
import java.util.Scanner; public class PatientBuilder { public static void main(String[] args){ String patientID; int patientAge; String patientRh; String patientBlood;
I'm writing a desktop client for simple soap service (axis), and when i create a web-service client lib using netbeans wsimport tool, I don't understand why for that entity :
I have an addressBook GUI where I have a JList that populates with the contacts names, and once I double click a contacts name I'm wanting to fill the textfields with the contacts corresponding data.
ex) ContactType: Family (enum), Name: Zoidberg, Address: 111 Space Drive, City: New York City, etc...
I've got it to where I select open from the JMenu, it populates the JList, but once I select a contacts name, all the textfields are populated, but only with the contacts name
What am i doing wrong here, and how can i fix it to where it fills out the correct data?
Here's my code so far:
public class AddressBookGUI extends JFrame { private final int WIDTH = 450; private final int HEIGHT = 300; private JLabel currentlySelected; private JTextField contactTypeTextField;
[code]...
I'm certain the logic is messed up near the end where i set all text fields to the index, because no matter what field i want to fill it's at it's going to set it to whatever index I select, but I don't know how to fix it.