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.
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.
Some web site offers feature of "remember user id/pwd" so next time when you access the same web site, it automatically pre fill out the user id field and or password field for you. How is this kind feature implemented ? I am not talking about the auto-complete function here.
I know when including remember me token in request header, it will contain expiry date. does this mean the token generated must be able to be reversed back to it's original string?
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".
//******************************************************************** // 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?
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.
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"):
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?
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?
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.
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
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 {
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
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 .....
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?
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.
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;
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 ...
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.