How To Keep Track Of Percent Full

May 20, 2014

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.

View Replies


ADVERTISEMENT

Calculate Percent In Java

Jan 3, 2014

I would like to change the precent from *1.17 (17%) to calc of precent like this :

3% + 5% + 5$

For example :

The resault is 10$ - i want to get :

10$ +3%(0.3$) + 0.5% (0.51$) + 5$ = 15.81$

How i change this line to this calc

if(results[i].getSite()=='Xxx'&&XPrice==0)
{
XPrice =(results[i].getPrice() *1.17);
}
}

View Replies View Related

Program Should Copy Person With Highest Percent From File

Mar 23, 2014

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:

[code]....

View Replies View Related

Swing/AWT/SWT :: JScrollPane Getting Full But Not Scrolling?

Mar 1, 2014

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?

private static void addScrollPane() {
jScrollPane = new JScrollPane(new JPanel());
((JPanel)jScrollPane.getViewport().getView()).add(new JButton("First Button"));

[Code]....

View Replies View Related

Insert Sort - Doubling Array If It Gets Full

Feb 28, 2015

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

[Code] ....

View Replies View Related

Create A Borderless Window With A Background Transparency Set At Full

Feb 15, 2014

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.

View Replies View Related

Unable To Full Screen Swing Form On Fedora

Jul 16, 2014

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;

[Code] ....

View Replies View Related

JPanel Rectangle Drawing Relative To The Full Window

Jun 16, 2014

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

MOUSE.x = event.getXOnScreen() - gameFrame.getLocationOnScreen().x;
MOUSE.y = event.getYOnScreen() - gameFrame.getLocationOnScreen().y;

but that resulted in some errors (null pointers) and the mouse was just printing out a position of 0,0

View Replies View Related

Dijkstra's Algorithm - Array Full Of Null Data

May 6, 2014

I'm trying write a Dijkstra's implementation in java. First off, here is the algorithm:

package lab3;
import java.util.HashMap;
import java.util.Stack;
 
/**
* 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.

View Replies View Related

Size Of Frame In Gaming Code - Full Screen Mode

Feb 17, 2014

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

[Code] .....

View Replies View Related

Variable Updated To Point To The New Array Last Full Cell Index Value

Jul 10, 2014

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?

View Replies View Related

JavaFX 2.0 :: HTMLEditor - Default Size / Cannot Fill Full Screen

May 10, 2015

The code:
 
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;

[Code] ....
 
run (when window height > 700px ) :
 
HTMLEditor  default height is 670px, the other area (green color) is not filled,why?
 
HTMLEditor   高度总是670px, 怎么把HTMLEditor 填充满窗口?
 
这是一个bug吗?

is it bug?

View Replies View Related

User Inputs His Full Name In A String From Keyboard / Program Will Give His Initials As Output

Jan 5, 2014

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

[Code] ....

View Replies View Related

How To Track Player Positioning

Nov 25, 2014

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.

View Replies View Related

Who Keeps Track Of Which JComponent Has Focus

Aug 31, 2014

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?

View Replies View Related

Best Way To Keep Track Of Number Of Objects Created

Mar 13, 2014

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?

Class circle{
private double x,y,radius;
private static count;
Circle(double x1, double y1, double radius1){
x=x1;y=y1;radius=radius1;
count++;
}

View Replies View Related

Keep Track Of Result Of Each Roll Using Array

Mar 8, 2014

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;

[code]....

View Replies View Related

Memory Calculator - How To Keep Track Of Current Value

Nov 10, 2014

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;

[Code] ......

View Replies View Related

Java Program That Keeps Track Of People Names

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

Keep Track Of Output - How Many Times Each Total Occurs

Jan 23, 2015

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());

[code]....

"how many time each possible total occurs"

View Replies View Related

Keeping Track Of Team Standings In A League

Apr 18, 2014

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;
}
}

View Replies View Related

Priority Queue In Java Which Keeps Track Of Each Node Position

May 4, 2014

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.

View Replies View Related

Swing/AWT/SWT :: Track Down Why SetViewPortView On A JScrollPane Is Taking So Long

Apr 27, 2014

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.

View Replies View Related

Create A Program That Keeps Track Of Information Input By User

Sep 17, 2014

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.

View Replies View Related

Servlets :: How To Track Source Of Request Coming To Controller

Sep 29, 2014

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.

View Replies View Related

Keeping Track Of Inventory For A Company - How To Update Variables

Feb 11, 2015

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:

balance = 4000.00;
lampQuantity = 400;
lampPrice = 10;
chairQuantity = 250;
chairPrice = 20.00;
deskQuantity = 300;
deskPrice = 100.00;
  
System.out.println("Current Balance: $" + balance);
System.out.print("1. Lamps " + lampQuantity);
System.out.println(" at $" + lampPrice);
System.out.print("2. Chairs " + chairQuantity);
System.out.println(" at $" + chairPrice);

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved