Data Structure Construction

Feb 27, 2014

I'm trying to fill a List<String>, named overlappedGrid, from another List<String>, named listGrid. I'm facing an exception:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type

required: variable
found: value
at arab2004_d.ProcessingLayer.printShape(Arab2004_D.j ava:101)
at arab2004_d.Arab2004_D.main(Arab2004_D.java:30)

Java Result: 1

Here is my source code (the exception line is commented "here is the exception"):

package arab2004_d;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;

[code]....

I tried to copy listGrid in another List<String> but the exception remain the same.

View Replies


ADVERTISEMENT

Simple Data Classes - Serialize More Complex Data Structure

Oct 6, 2014

I have written several simple data classes that I serialized manually by converting to text. At this point I need to serialize a more complex data structure. which will include lists of the simpler elements. Can serialize store and reconstitute this type of structure automatically or do I need to do this one manually as well? Consider the pseudocode below for a clarification of my question;

Java Code:

Class Hops{
String Name;
float Alpha Acid;
float Beta Acid;
};

Class Malt{
String Name;
float extract;
};

Class Recipie{
String Name;
CList HopList;
CList MaltList;
};

CList RecipieList; mh_sh_highlight_all('java');

I read the article on Serialization presented at tutorial point, but the example only showed a simple class, not lists of class members. What I want to do is serialize RecipieList, which consists of a CList of Recipies, which in turn consist of CLists of various ingredients.

View Replies View Related

Defining Map Data Structure

May 27, 2014

I want to define this data structure , I show you an example

"first street",{{1,40},{43,45},{34,26}},
"second street",{{14,41},{42,5},{3,46}},
............

I wrote in this way but it doesnt work :

Map<String,ArrayList<int[]>> Street=new HashMap<String, ArrayList<int[2]>>();

View Replies View Related

Trie Data Structure In Java

Sep 27, 2014

Problem in inserting,removing and searching in trie data structure.

View Replies View Related

Checking Parentheses Using Stack Data Structure

May 4, 2015

I am trying to Implement a method matchBracket(String exp), which should take a String expression consisting of only symbols (,[,{,<,),],},> , and checks if the brackets in the expression are matching using stack data structure.

I know how the methods of stack class like push,pop,peek are for however how to do the checking for opening and closing brackets iteratively ?

public static void matchBracket(String str){
// creating a stack of character at first
Stack <Character> stack = new Stack<Character>() ;
// starting loop to scan the expression below inside main method
for(int i = 0; i<str.length(); i++){

[Code] ....

/**Expected Output:
*The parentheses are not matching
*The parentheses are matching

View Replies View Related

Java Calculator Using Stack Data Structure

May 21, 2014

My assignment is to design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. But i having error while i press the action there.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Stack;
public class JCalculator implements ActionListener {

[Code] ...

View Replies View Related

Display Data Structure With JTree In A Swing Application

Aug 28, 2014

I have a tree-based data structure that looks somewhat like this:image1.png..Every tree always has a height of no more then 3, and each of these classes has a very specific use, generalization is not possible between them.Now, I want to display my data structure with a JTree in a Swing application. A JTree needs a TreeModel and so I created a custom TreeModel for my classes, it looks like this:

public class CustomTreeModel implements TreeModel {
private Root root;
public Object getRoot() {
return root;

[code]....

But then I would introduce this interface to my Model classes just for the purpose of writing the View. So my data model has to be altered to make the View work, this sounds completely against MVC to me and also like something I dont really like.On the other hand, the CustomTreeModel would be much simpler, easier to understand, easier to maintain and just in general more pleasing to the eye.Should I change my Model to improve the View? Is instanceof okay to be used in View classes?

View Replies View Related

Peterson Lock Implemented For N Threads Using Binary Tree Data Structure

Feb 8, 2014

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
public class tree_lock_test{
int total_instances;
int thread_instances = 0;
int N;

[Code] .....

this is compiled with another Peterson class which has implemeted peterson lock for two threads ...

View Replies View Related

Design Calculator Using Stack Data Structure To Perform Additions / Subtractions / Multiplications And Divisions

Jul 18, 2014

I've beginning a new assignment and would like some feedback on my outline for the program. You are to design a simple calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. The user may enter an arithmetic expression in infix using numbers, parentheses and arithmetic operations (+, -, *, /). After an expression is entered, its postfix or prefix notation is displayed and then the result of the expression. You are required to design your own infix to postfix and infix to prefix conversions.

The professors example includes: SinglyLinkedList implementation, a Stack that implements Stack interface and extends SinglyLinkedList, a Node class, and StackApp -- in addition to the main class and the prefix/post-fix classes.

(The equation is entered/stored as a string variable)
System.out.println("Enter equation: ");
equation = input.next();
equation.trim();

(1.) Get the user input:
- evaluate the user input and use a stack to determine the correct prefix/post-fix notation.
- from the stack, pop each item:
a. account for '(' and ')' to push all operators and write all operands until ')', then pop/write
b. store new equation into a list (in prefix/postfix notation)

(2.) Display the list in both notations to the user.

(3.) Perform the calculation.Do you think it will be alright to calculate the original equation that was entered? It seems too much to then design a class that will then cycle through the polish notation and calculate according to that format.

View Replies View Related

Construction Of Child Object In Memory

Apr 19, 2015

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?

View Replies View Related

Construction Loan - No Main Class

Feb 13, 2015

I keep getting an error every time saying there is no main class ...

Loan

public class Loan implements LoanConstant{
public static int loanNumber;
public static String lastName;
public static int loanAmount;
public static int interestRate;
public static int term;
public int primRate;

[Code] ....

View Replies View Related

How To Print A Different Statement In If Else Structure

Feb 6, 2015

Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:

- If all three numbers are equal to 7, you are winning $1,000,
- If all three numbers are equal, but not equal to 7, you are winning $500,
- If two of the numbers are equal to 7 and the third one is six, you are winning $400,
- If two numbers are equal, you are winning $100,
- Otherwise you are not winning anything.

And for that I wrote:

import java.lang.Math;

public class Assn1_2150130 {
public static void main(String[] args) {
// Generate three random signle-digit integar from 0-7.
int n1 = (int)(Math.random()*7);
int n2 = (int)(Math.random()*7);
int n3 = (int)(Math.random()*7);

[code]...

But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".

View Replies View Related

Tree Structure Of Folders

Mar 21, 2014

I have been trying to make a good tree structure for my Electrical Distribution network.. How to create two "subfolder" of my Voltage level folder.

Here is the code

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;

[Code] ....

View Replies View Related

How To Modify If Else Structure To Get Output

Nov 3, 2014

I'm having trouble with this program:

//********************************************************************
// Demonstrates the existence of separate data space in multiple instantiations of a programmer-defined class.
//********************************************************************

[code]....

Basically i'm trying to add one more "coin" to flip. My problem is that my if-else structure isn't working correctly here's what it looks like:

if (count1 < GOAL)
if (count2 < GOAL)
System.out.println("Coin 3 Wins!");

[Code] .....

It only works correctly when "coin2" wins.How would I modify my if else structure to get the output I am looking for?

View Replies View Related

JSF :: Possible To Map URL With Independent View Dir Structure?

Feb 16, 2015

Is it possible to map URL's with independent view dir structure? If so how?

My goal is to simply point an url to a specific view file:

i.e.

[URL] ....

to
not/default/path/views/main/index.xhtml
and
www.myserver.com/application/admin/
to
not/default/path/views/admin/index.xhtml

A couple solutions I found so far where:

Solution 1

PrettyFaces

I just didn't wanted to use a third party solution. This is my best solution so far.

Solution 2(a JSF solution):

navigation rule entries in the faces-config.xml file.

A bean is required, not a bad thing in above example but not great in combination with static navigation like:<h:commandButton action="index"/>

Solution 3 (another JSF solution)

Resource Library Contracts
This forces me to work in the contracts file.

None of the solutions gave me a clear solution except prettyfaces.

Are there some elegant native JSF solutions ? Something flexible and reusable? Something like a mvc controller i used to use in php applications. In this controller I was able to add a template file in the constructor and an content file in specific function. Custom paths where no problem. I didn't want to use mvc nor the php language in this project.

View Replies View Related

JavaFX 2.0 :: Using CSS Sub-structure On Own Nodes

May 26, 2014

I have noticed that you can style JavaFX controls using their sub-structure.

E.g. to style the label in a table column header to be left justified I can do this :
 
.table-view .column-header-background .label {    -fx-alignment: center-left ;  } 
 
How can I style my own nodes/controls doing this? Basically it amounts to asking how the selectors like ".column-header-background" are associated with sub-structures of my Java control/node objects. So suppose I have something like
 
.fancy-node .fred .label { ... }
 
How does JavaFX associate fancy-node and fred with something in my implementation of a Node/Control?

View Replies View Related

How To Structure Simple Java Programs

May 8, 2015

how to structure simple programs (i.e. one-method algorithms for a simple purpose). There are a few different ways that I have been doing it, but I want to be consistent. Should I put both the one-method algorithm (e.g. a factorial function) and the main method that executes the algorithm into the same class and then export it to an executable .jar file for use? Or should I create one class for the algorithm and another for the main method that executes the algorithm? In addition, is there any reason that I should out these classes in a package before I export it?

As another similar question, if I have constructed two distinct classes with two separate purposes, and they are both used in the construction of a single program, then would it be best to just put the main method in a third, separate class or should I put it in one of the two classes?

View Replies View Related

JSF :: Tree Structure - Cannot Use Richfaces And Primefaces

Apr 9, 2014

I am new to jsf i have been given a task to create a tree structure in jsf but cant use richfaces and primefaces. I need a complete project for reference as i am to totally new to this.

View Replies View Related

Parsing Tree Structure In Java

Jun 26, 2015

I have an excel file with data listed as the following, i m trying to parse down using POI
 
A
     B
          C
               D1
               D2
          F
               G1
               G2
               G3
          M
               S1
     R
          T             
     U
L
  X
     Y
         Z
 
is it possible to generate an output like the following
 
A
A-->B
A-->B-->C
A-->B-->C-->D1
A-->B-->C-->D2
A-->B-->F
A-->B-->F-->G1
A-->B-->F-->G2
A-->B-->F-->G3
A-->B-->M
A-->B-->M-->S1
A-->R
A-->R-->T
A-->U
L
L-->X
L-->X-->Y
L-->X-->Y-->Z
 
I have been trying from quite some time but havent figured out the logic ...

View Replies View Related

Remember File Structure On Subsequent Openings?

Mar 12, 2014

I have a program I am working on, and have been using the following code:

Java Code:

private void checkQInstall(){
try {
qs = new File("C:MEMORYGAMEq.bin");
in = new BufferedReader(new FileReader(qs));
} catch (FileNotFoundException e) {
System.out.println("CALLED");

[Code] .....

Now my main issue is I am working on a project that could be used on a variety of systems. I understand that Java is designed for flexibility among OS's and that the way I have coded is designed for a Windows system (afaik). How to retain an installation directory so that on subsequent openings, the program knows where to open the file, without it being platform dependent.

View Replies View Related

Build Tree Structure From Array In Java

May 31, 2014

I never used tree, node etc. Consider an array of strings that come from html tags. This needs to be turned into a tree structure. Here, any Hn is the child of the most recent Hn-1

String[] Headers = {"H1", "H1", "H2", "H3", "H3", "H2", "H2", "H3",
"H4", "H2", "H2", "H2", "H1", "H2", "H2", "H3", "H4", "H4", "H2" };

Desired output -

ROOT
H1
H1
...H2
......H3
......H3
...H2
...H2
......H3
.........H4
...H2
...H2
...H2
H1
...H2
...H2
......H3
.........H4
.........H4
...H2

ANSWER -

class Example {
static class Node {
final String name;
final int indent;
Collection<Node> children = new LinkedList<> ();

[Code] .....

View Replies View Related

Nested For Loop To Capture Structure Of The Figure

Jan 26, 2014

I am having problem with some problems like this nested for-loop for instance ....

-----1-----
----333----
---55555---
--7777777--
-999999999-

Now I have to write a method called printDesign that produces the following output but i am not even entirely sure how to start it out now of course i know how to make a for-loop but and i guess if i was to do something for this i would do this .....

Java Code:

for(int*j=0;j<N-k;j++){
System.out.print("-");*
for(int*j=0;j<i;j++){
System.out.print(i);*
for(int*j=0;j<N-k;j++){
System.out.print("-");*
System.out.println();*
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Modify Internal Object Structure Using Any Design Pattern

Mar 31, 2014

I have a design scenario here which is quite interesting and complex. I have a Java class structure as follows,

class A
{
     class B;
     innerClass B
     {
          List<class C> listofC;
          innerClass C
          {
               String attribute1;
               String attribute2; // Their getter setters
          }
     }
}               

So I have this as an API. Now my challenge is that I need to add one more property to inner class C.  i.e attribute3 in innerClass C. I need to do this without disturbing the code in class A by extending these classes or writing a new wrapper, so I can use class C with new properties .

I hope this should be achievable through any design pattern either at runtime or design time.

View Replies View Related

Java Program To Implement A Single Linked List Structure

Jul 27, 2014

I'm trying to build a program that contains the ability to:

(1) insert new node at head,
(2) print out contents of the list in order,
(3) remove first node from head,
(4) remove last node from tail,
(5) find a target value,
(6) give total number of occurrences of a target value, and
(7) give total number of items in list.

The areas I'm struggling with implementing are: (

- remove from tail - I know how to find the final node but I can't quite figure out how to set it to null since its initial type is an integer.
- find a target value - how to make the parameters quite workout so the user can simply input an integer value.
- The solution is probably really simple but I can't figure out how to print out the results of these methods when I call them.

public class Node
{
private int data;
private Node link;
// Node Constructor 1
public Node()
{
data = 0;
link = null;

[code]....

View Replies View Related

I/O / Streams :: Generate File Tree Structure Of Mounted Unix File System

Apr 22, 2014

I am creating a web application that runs on server X(unix) and it has another unix system mounted on it. I want to generate the file tree structure of this mounted unix file system and show it on to a web application so that users can select a file and move it onto this current unix machine.

I know this sounds stupid and you may want to say why cant we directly copy the file, I am doing a proof of concept and using this as a basis.

View Replies View Related

Java Tree Structure - Build Tree Based On Traversal Results

Jun 17, 2014

How to do draw the original binary tree based on traversal results?

A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree structure?

View Replies View Related







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