I'm trying to make a canteen class that holds water. It holds two quarts of water and two quarts is 100%.
public double maxVolume;
public int percentFull;
Right now the Canteen is empty.
public void Canteen()
{
percentFull=0;
maxVolume=0;
}
And right now I'm trying to make a constructor that specifies the amount of liquid the canteen can hold and specifies the percent full.
public Canteen(double maxVolume, int percentFull)
{
}
Should I make this second Canteen an integer, a double, or something else? Also, how do I make sure the Canteen never reaches higher than 100%. I'm also curious how I can keep maxVolume and percentFull connected so the % of water is consistent with the number of quarts(2) the Canteen can hold.
The program should copy person with the highest percent from the file 'plik1', and then put it to the file 'plik2'.The problem occurs while compiling.
Java Code: string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type mh_sh_highlight_all('java'); Code:
I am trying to create a JScrollPane with buttons in it, but I noticed that when I try to scroll, the items all move into ONE row at the top of the JScrollPane. How do I have them vertical? Is there something wrong with the way I am setting up the JScrollPane?
I have read through some of the posts on insert sort /arrays and see close but not exactly what I'm looking for. I don't want to use a library to do work for me, I want to do it myself and understand it.
OrderedArrayList.java // import static org.junit.Assert.assertEquals; public class OrderedArrayList<T extends Comparable<T>> { // T is a variable that contains a class type, array of T things private T[] arrayA; // changed to private per example private T[] arrayB; int numElements = 0;// number of elements full (not null), used in multiple methods. numElement -1 = back
I want to create a borderless window with a background; I want this background's transparency set at full, so that the corners show the image of whatever's underneath, just as in the picture. Then, I want to add an image (or button) to a specific x, y location in the window (which is NOT resizeable, which is my desire) and then have the user able to click the button; button1 does function1, button 2 does function2, etc. But the images (or buttons) must ALSO have transparency, so that you can see the background image.
I wrote this program in VB.NET already; I'm trying to rewrite it in Java, as I can no longer work in VB... the program is simply taking up too much memory and is far too slow. Java should handle the whole process better.
I want to make swing form full screen even on taskbar on linux machine. But after trying so hard unable to achieve it. I am using fedora as operationg system.
Below i am giving you my swing code. but whenever i run this file form comes up on the screen and waits for a second and it goes in background.
I am using linux OS Fedora 64 bit.
public class ThankYou { JFrame f; JTextArea nameField; JLabel lable; String str;
I'm currently making a Breakout clone to learn about different ways of organizing my code and whatnot but I've run into a problem with the positioning of some pieces versus the position of the mouse.
I've created a blue rectangle on the screen that turns white when the mouse hovers over it, BUT it actually only ends up turning white about halfway down and then continues on off the block. I moved the rectangle to 0,0 to see where it draws and it looks like it is drawing to the very top left corner of the window itself but for the mouse coordinates, the top left is just where the black area is and excludes the borders of the window.
Here is the class rendering the rectangle, it extends from a class that in turn extends from the JPanel class:
public class MainMenuState extends MenuState { JFrame gameFrame; Graphics2D g; // PlayButton variables int playPosX = 0; int playPosY = 0; int playWidth = 100; int playHeight = 50;
[Code] ....
A few other things I tried that I can think off the top of my head: Play around with different layouts (at times this caused the screen to shrink to a small size as well as using pack()), using setSize() setLocation() or setBorder() in the MainMenuState class which had no effect.
Someone on another forum also suggested trying to utilize component.getLocationOnScreen(): I tried two things with the getXOnScreen method, first subtracting with the location of the JPanel which of course gave me the same problem. After that I tried
/** * Compute shortest paths in a graph. * * Your constructor should compute the actual shortest paths and maintain all the information needed to reconstruct them. The returnPath() function should use this information to return the appropriate path of edge ID's from the start to the given end. * * Note that the start and end ID's should be mapped to vertices using the graph's get() function. */ class ShortestPaths { Multigraph graph; final int INF = Integer.MAX_VALUE; PriorityQueue<Integer> Q;
[Code] ....
I followed someone else psuedocode very closely but for whatever reason, my edge[] array is just full of null data, which means I can't actually return the shortest path. Why that's happening/how to fix it? Maybe I'm not understanding dijstra's correctly.
Basically the code is for a game which is displayed in a window. The statement if(false) //full screen mode is confusing me a little. How does this if work? it doesn't seem to be testing for anything so how does it ever get set to full screen mode? Is the if even needed? why not just code windowed mode?
public class Window extends JFrame{ private Window() { // Sets the title for this frame. this.setTitle("My test"); // Sets size of the frame. if(false) // Full screen mode
I'm trying to set a variable to point to the last full cell of an array and then create a new larger array and then have the variable be updated to point to the new array's last full cell index value.
a) Should the variable be declared static? b) What would be the best initial value to set this variable to? Shouldn't it correspond to a <for> loop index rather than a solid integer?
private lastfullcell = a[i]; private int [] a;
c) How would you update <lastfullcell> because if you passed the index through a method's loop index isn't the array index value garbage collected after the method completes?
Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.
############################
For example: User inputs-> Ram Kumar Das
Program Returns-> R.K.D.
I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.
Java Code:
import java.io.*; public class Assignment { static int i=0; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main (String args[]) throws IOException
So I have a player an enemy and enemy bounds the enemy can go. I need to have the enemy track my position and when I go into the position (I am using a collision method for this) the enemy comes over at a speed of 1. My problem is the enemy jumps to me and then follows at speed of 2 (2 is the player speed). The code is wrong this is why it is jumping and I have my other problems. so my question is what is a good solution for this? I am trying to make a method to track playerposition() so what I am thinking I could do is find x, y of player then store those into an array and return the array to Enemy so he tracks.
player.java public class Player{ int x = 100; // Location of player int y = 200; // location of player int xa = 0; // Representation of where the player goes int ya = 0; // Representation of where the player goes private int speed = 2;
[Code] .....
Please note this is not the entire code I have cut some things out that did not need to be there. Also, the code is just to get an idea of what I was thinking of doing. The ideas that are came up with are not meant to be a reflection of what I already have but, what I could add or replace.
I have two JFrames: frame1 and frame2. frame2 currently has focus, and I want to determine which component of frame1 would have focus if I were to switch focus to frame1, hopefully without actually temporarily changing focus.
Is it the KeyboardFocusManager who keeps track of which element in each frame has focus? Or does each container itself keep track? How does Java figure out which element in a frame gets focus when I switch to that window?
Which is the best way to keep track of the number of the objects I've created?Is is a good practice to have a static variable, which will be incremented everytime I call a contructor?
The code I have below asks the user how many times you want to roll the dice. It rolls dice 1 and dice 2 randomly and gives the total. Now, I'm trying to keep track of the result of each roll using an array that is indexed by the sum of the roll of the two dice. Then I want to output my result in a table that shows each value (from 2 - 12)) and the number of times that value was rolled. I would like to do this preferably with the JTextArea class, but it doesn't have to be. I keep getting errors.The code below works for the dice rolling in the 1st paragraph. I took out all the bad code I was trying to use for the 2nd paragraph.
package Part2pack; import java.util.Random; import javax.swing.JOptionPane; class Dice{ public static void main (String args[]) { String input = " "; int count = 0,dice1,dice2;
Basically we have to create a calculator that it will have to keep track of the current value, and do the functions that the calculator uses.
But I have it working for the most part, but the current value does not keep...
The double " currentValue " Must stay private.
import java.util.*; public class MemoryCaluclator { private double currentValue; public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int answer = 0;
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).
I am currently truing to make this class instantiate 100,000 dice rolls of 2 dice. And I also need to keep track of how many times each possible total occurs and I am having trouble outputting the result. Right now when I run my code it is just showing the results of each of the 100,000 roles.
public class ltefera_DiceRollTest { public static void main(String[] args) { ltefera_DiceRoll diceRoll = new ltefera_DiceRoll(10); System.out.println("Total # of pips" + " "); diceRoll.printArray(); System.out.println(diceRoll.countDice(2)); System.out.println(diceRoll.isArrayDataValid()); System.out.println(diceRoll.getTotal()); System.out.println(diceRoll.allDifferent());
Here are my conditions: You are developing a program to keep track of team standings in a league. When a game is played, the winning team (the team with the higher score) gets 2 points and the losing team gets no points. If there is a tie, both teams get 1 point. The order of the standings must be adjusted whenever the results of a game between two teams are reported. The following class records the results of one game.
public class GameResult { public String homeTeam() // name of home team { /* code not shown */ }
public String awayTeam() // name of away team
[Code] ....
The class TeamStandings stores information on the team standings. A partial declaration is shown below.
public class TeamStandings { TeamInfo[] standings; // maintained in decreasing order by points, // teams with equal points can be in any order public void recordGameResult(GameResult result)
[Code] ....
And here is the actual question:
Write the method adjust. The method adjust should increment the team points for the team found at the index position in standings by the amount given by the parameter points. In addition, the position of the team found at index in standings should be changed to maintain standings in decreasing order by points; teams for which points are equal can appear in any order.
And here is what I have so far:
private void adjust(int index, int points) { int Score[] = new int[standings.length] for ( int i=0; i <= standings.length; i++) { Score[i] = index, points; } }
I'm working on a lab for my class. I need to create a Priority Queue in Java using an array list. The kicker is that each node has to have a "handle" which is just an object which contains the index of of the node that it's associated with. I know that sounds weird but we have to implement it this way. Anyway, my priority queue seem to work fine except the handle values apparently aren't updating correctly because I fail the handle test. Also, I run into problems with handles only after extractMin() is called, so I figured the problem would be somewhere in that method but I've been through it a million times and it looks good to me.
Here is my Priority Queue Class:
package lab3; import java.util.ArrayList; /** * A priority queue class supporting operations needed for * Dijkstra's algorithm. */ class PriorityQueue<T> { final static int INF = 1000000000; ArrayList<PQNode<T>> queue;
[Code] ....
I can post the tests too but I don't know if that would do much good. Just know that the queue works as is should, but the handles don't point to the right nodes after extractMin() is utilized.
I've built up an unreasonably large and unreasonably complicated JPanel. Unfortunately, when I use setViewportView to add it to a JScrollPane, a get an extended UI freeze—that operation takes several seconds. I'm trying to figure out what's taking so long. I've tried some fairly extreme things, like overriding the paintComponent, PaintComponents, paintChildren, paint, repaint, validate, revalidate, and validateTree methods in the panel with no-ops to try to figure out what's taking so long, but to no avail. I've tried validating the JPanel before adding it, but that has no effect. If I override the addImpl method of the scroll pane, that makes things quick, but it doesn't really narrow things down much.
I am new to Java an have to Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, and Age. Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns.You should be able to add and remove contacts in the array.
I have a controller that on the basis of commands (formaction and subaction) dispatch requests to different jsp pages. But somehow when I am debugging my application, I can find duplicate request coming to the controller, so one jsp page does load twice. I am not sure from where the duplicate request is generating.
My program is supposed to be used to keep track of inventory for a company. The user is prompted with a menu that asks them which item they want to update and then gives them another menu that allows them to buy, sell, or change the price of the items. For this, I need to have the variable values to change (based on the input of the user), because they are initially set to specific numbers. How would I do this?
Here's the part of my code that is relevant to this question: