Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.
The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.
company class:
import java.util.ArrayList; import javax.swing.JOptionPane; public class Company { private ArrayList<Employees> list ; private static int numberOfCompanies;
[Code] ....
error message when print button is clicked:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent at javax.swing.JOptionPane.createInternalFrame(Unknown Source) at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source) at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
As you can see instead of displaying the champion name it is displaying the memory location and I do not know how to fix it.
class Champions { String name; Champions [] weak = new Champions [3]; Champions [] strong = new Champions [3]; String [] items = new String [3]; public static void main (String [] args) {
For some reason my code returns the memory address of the array when its a print statement with a string, but it works fine when its in a separate print statement all by itself. Why? Do I need to create a toString method that converts a char array to a String to something? The reason why I ask that is becuase on Eclipse line 10 has a warning stating "Must explicitly convert char[] to a String".
public class Ex { private String word; public Ex(String word) { this.word = word; } public char[] Display(){ char[] wordChars = this.word.toCharArray(); return wordChars;
[Code] .....
Result:
Hello world The word is: [C@1db9742
I also tried this, knowing that it's a long shot, but that didnt do anything...
public String toString(){ Ex ex = new Ex(this.word); char[] word = ex.Display(); String updated = word.toString();//counter intuitive? return updated; }
So I have that traditional memory game homework assignment and for some reason I can't figure out how to put the codes in order. I can't figure out the arrangement to make it work. So far I have
import java.util.Random; import java.util.Scanner; public class MemoryGame {
I had a question about data structures. For the insert method of a linked list, the 'node' object is declared in the insert method. So doesn't the 'node' get destroyed as soon as the closing brace of the insert method is encountered? How do all the nodes continue to occupy memory?
Making a memory game where you click a square it turns over an image and you match the two pretty simple. My issue is my images are not displaying and I am not sure why everything looks correct to me.
when running Eclipse, roughly 250k memory is used by it?In my Task Manager, it says: javaw.exe00265,000 KJava(TM) Platform SE binary.The value of 265,000 K is of course fluctuating, but around this value. Btw, this is when Eclipse is just running in the background, without even any java programs running in it. Is this normal memory usage by Eclipse?
"A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled
1, two might be labeled 2 and two might be labeled 3. The cards are shuffled and placed face down on the table.
The player then selects two cards that are face down, turns them face up, and if they match they are left face up. If the two cards do not match they are returned to their original position face down. The game continues in this fashion until all cards are face up.Write a program that plays the memory matching game. Use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that she would like to select through a coordinate system.For example in the following layout:
All of the cards are face down except for the pair 8 which has been located at coordinates (1,1) and (2,3). To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen.Use 2D array for the arrangement of cards and another 2D array that indicates if a card is face up or face down.Or, a more elegant solution is to create a single 2D array where each element is an object that stores both the cards value and face.Write a function that shuffles the cards in the array by repeatedly selecting two cards at random and swapping them.
Note:To generate a random number x, where 0<= x <1, use x=Math.random();.For example, multiplying y six and converting to an integer results in an integer that is from 0 to 5."I have been thinking about the algorithm and design of the question for a few hours.
Started ok i guess? But when it comes to the save and get methods im totaly lost.. (See the code)
import java.util.HashMap; public class Model { HashMap<Integer,Long> m = new HashMap<Integer,Long>(); Integer value; Long result = 2 * computePower(value-1); public long computePower(int value){ if(value <= 0 )
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 understand how to write a child object. I know what can access what and the order of execution of each statement, including fields, initialization blocks, and constructors. I know what will be inherited by the child and how private fields and methods are not inherited. I also know that private fields and methods in Parent are still accessible indirectly through constructors, and non-private methods. I know how to use super() and this() with or without parameters. I know when super() will be automatically inserted by the compiler and how the Object class will always be the ultimate parent class. However, I have not been able to find an explanation of exactly (or even approximately) how all this is actually put together into an actual object in memory.
For instance, if Parent.field is private and Parent.fieldGetter() is public then Child inherits fieldGetter() and can call it directly as if it is a member of Child. In fact other classes can call Child.fieldGetter() with no clue that it is not an actual member of Child. But, if fieldGetter() is now part of Child and Parent was never actually instantiated, then how is Parent.field available for Child.fieldGetter() to read? In fact, how does Parent.field exist at all? Where is it stored? (OK, I know, "on the heap.") But I want to know what it is associated with in memory. Is it treated like part of Child? Is there really a Parent object on the heap and Child simply contains references to the parts of Parent that it inherited? What?
I am working on a game project. Whenever we are starting our game application in production, it works perfectly around 3 days after 3 days, CPU utilization is increasing upto around 95% to 99% and application stops to respond. Before 6 days, I started application again and we doubled our Perm Gen memory size. The same problem happened but it happened after 6 days.
Now, i am not able to relate CUP utilization to Perm Gen memory. Is Perm Gen memory effect CPU utilization?
I just made an application with javafx that cycles videos in a folder. I had to set the next video firing the setonendofmedia event, so they are in a cycle, but the problem is that the application loads every video at the beginning, so after a while it fills memory and crashes.Is there another way to cycle videos without pre-load them or a way to flush memory every while?
But reading this article ( JavaFX - APIDesign ) I understand that the algorithm is obsolete. It does not quite find what is the algorithm that improves the integration of javafx and swing without using separate threads.
I have two unix systems in which on one system I installed sun solaris jdk and on another system I installed IBM jdk.
Java programs which consume more heap memory are getting failed on sun solaris jdk system where as same programs are successfully getting executed on IBM jdk system .
My question is does sun solaris 64 bit jdk needs more heap than IBM 64 bit jdk ??
Suppose you are given a computer with 1GB RAM. The disk of this computer holds a 10GB file containing random numbers. Propose a technique for sorting the file without using the disk or network or virtual memory. Outline your approach, propose an algorithm, and implement the algorithm. What is the algorithmic complexity of your algorithm.
Given a string, compute a new string where identical chars that are adjacent in the original string are separated from each other by a "*". My implementation :
package com.tcs.dash; public class StringBuild { public String edit(String userIp){ StringBuilder builder = new StringBuilder(userIp); String replaceText = ""; for(int i = 0; i < builder.length() - 1; i++){ if(builder.charAt(i) == builder.charAt(i+1)){ replaceText = builder.charAt(i) + "*" + builder.charAt(i+1); builder = builder.replace(i, i+1, replaceText); } } return builder.toString(); } }
I am getting error at line 13. An exception actually.
I/P given = aaaa
Console:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Unknown Source) at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source) at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source) at java.lang.AbstractStringBuilder.replace(Unknown Source) at java.lang.StringBuilder.replace(Unknown Source) at com.tcs.dash.StringBuild.edit(StringBuild.java:13) at com.tcs.dash.StringBuildExample.main(StringBuildExample.java:14)
I'm new to programming and I would just like to know what happens inside the memory once you run a java application. How do the memory allocate space for your objects or variables? Where does it start?does it start in memory location 1 first when I create my first variable or object? What is the use of variables and how is it used by the memory?Also if I create a variable named String s1 then I created another variable again named s1= "myString" Did I create a new object or I just edited the value of the s1 variable??
And if I create a variable int num1 = 10 then I created another variable int num1 = 12 did I create another one or I just edited the num1 variable?? Also how much memory would an object have? Does it depend on how many primitives objects like arrays or strings it have?Also I want to develop 3D games also, in the future is Java going to be great as I know machines in the future will have massive amounts of RAM and the JVM will be better...