|
yea, figured that out, but still hoping there is a way.
|
|
|
|
|
And this still has nothing to do with Java. Please use the correct forum.
|
|
|
|
|
|
|
No, because JavaScript cannot access the hard drive so it won't be able to determine if the file exists or not.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hello! I'm having a bit of trouble with 2-dimensional arrays. Currently, I am using netBeans 8.0.
I don't believe I need a loop to do what I'm trying to achieve, but nonetheless I'm stuck. Here is the code for reference:
<pre>
package nb.test.gamepackagev1;
import edu.sjcny.gpv1.*;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Homework4 extends DrawableAdapter
{ static Homework4 ge = new Homework4();
static Character[][] parade = new Character[4][2];
static int[][] aNum = new int[4][2];
static GameBoard gb = new GameBoard(ge, "Homework 4 by Sam Tahiri");
public static void main(String[] args) throws IOException
{
showGameBoard(gb);
int newX, newY;
for (int i = 0; i < parade.length; i++) {
parade[i][0] = new Character[4][2];
newX = aNum[i][0];
newY = aNum[i][1];
parade[i][0].setX(newX);
parade[i][1].setY(newY);
}
readArray();
}
public static void readArray() throws IOException {
File fileObj = new File("Array.txt");
if (!fileObj.exists()) {
System.out.println("File does not exist");
}
else {
Scanner fileIn = new Scanner(fileObj);
for (int i = 0; i < aNum.length; i++) {
int x = fileIn.nextInt();
int y = fileIn.nextInt();
System.out.println(x + " " + y);
aNum[i][0] = x;
aNum[i][1] = y;
for (int j = 0; j < parade.length; j++) {
parade[i][0].setX(x);
parade[i][1].setY(y);
}
}
}
System.exit(0);
}
public void draw(Graphics g) {
for (int i = 0; i < parade.length; i++) {
parade[i][0].show(g);
parade[i][1].show(g);
}
}
}
Ultimately, what I would look to do is to place the values of the array aNum[4][2] into each of the 4 objects of parade. The file, Array.txt, has 4 rows of 2 columns, therefore, 4 sets of [x][y] coordinates for the 4 objects I would like to create.
How can I place these values into said objects?
For example, if the first line of the array aNum is 120, 150, then the first object, parade, would be located at (120, 150) on the GameBoard. Thank you so much for helping me out!!
|
|
|
|
|
just give me an ideas or else if u know please send a sorce code.
please
|
|
|
|
|
Generically for all possible cases it is not possible because html need not be rigorously defined.
And there are other general problems such as what one is supposed to do with links and images during the conversion.
Further just converting it to XML generically isn't generally useful. One normally expects a certain format of some sort.
So if one wants to proceed one should define the following
1. What is allowed. Both as 'legal' html, and what data will be converted.
2. Use an html parser (HTML library)
3. Provide a source log both errors found and content for further analysis but otherwise skip it
4. Determine how to convert valid attributes to XML. The XML that was previously decided on
5. Get a XML library and use it to create the XML
|
|
|
|
|
Can we convert HTML to XML like this,First Can we convert HTML into XHTML and then to XML.
Is it possible?
|
|
|
|
|
Yes, it is possible, but it will require you to write the code.
|
|
|
|
|
|
Member 13501540 wrote: How? By reading the HTML, deciding which tags you want to keep, and using them to create the XML. There are libraries to read HTML and write XML, so all you need is to work out what needs to be transformed.
|
|
|
|
|
Well,thanks.
|
|
|
|
|
Create a function :
1. Int fact (int y) - to return the factorial of y .
2. Void printspecial() - by ivoking the function fact () , print all special numbers between s (start limit) and l ( last limit). The function reads starts (s) and last (l) limits. ( If sum of factorial of each digits of a numbers is equal to the number itself , the number is special ) .
Exp : input n = 145 = 1! +4! +5!= 1+24+120= 145, so 145 is special number .
Write a function Print () to I put start and end limits and by ivoking suitable function and print special numbers between start and end limits .
|
|
|
|
|
Sorry, we don't do your homework for you. Your homework is for you to learn stuff, not for us.
Try it yourself. If you get stuck somewhere in the middle feel free to ask a more specific question.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Jbdomnic123 wrote: Hi all can anyone solve this for me plz in java
Yes I can solve it. I would expect others can as well especially if they already know what a factorial is.
|
|
|
|
|
Not sure what's going wrong with my code-any suggestions? This is a basic calculator in Android Studio. It needs to be able to do multi-number operations(using order of operations). Currently, if you enter 2+2*6, it'll only do 2*6. Also, when you hit the Clear button, the 0 from the display stays tacked on, and I'm not sure how to get rid of it.Thanks!
package com.example.10012698.calculatorproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonadd, buttonsubtract, buttonmultiply,
buttondivide, buttonequals, buttonclear;
TextView display;
String displaytext="";
double result;
double x, y;
ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
buttonadd = (Button) findViewById(R.id.buttonadd);
buttonsubtract = (Button) findViewById(R.id.buttonsubtract);
buttonmultiply = (Button) findViewById(R.id.buttonmultiply);
buttondivide = (Button) findViewById(R.id.buttondivide);
buttonclear = (Button) findViewById(R.id.buttonclear);
buttonequals = (Button) findViewById(R.id.buttonequals);
display = (TextView) findViewById(R.id.display);
display.setOnClickListener(this);
list = new ArrayList<>();
}
public void onClick(View view)
{
if(!(view.equals(buttonclear)&&!(view.equals(buttonequals))))
{
display.setText(display.getText()+""+((Button)view).getText());
if(displaytext.equals("0"))
{
display.setText(" ");
}
if(view.equals(buttonclear))
{
display.setText(" ");
}
if(view.equals(buttonequals))
{
displaytext= displaytext.substring(0,displaytext.length()-1);
StringTokenizer operators= new StringTokenizer(displaytext, "+-*/",true);
while(operators.hasMoreTokens())
{
list.add(operators.nextToken());
}
for(int j=0; j<list.size()-1; j++)
{
if (list.get(j).equals("*") || list.get(j).equals("/"))
{
x = Double.parseDouble(list.get(j - 1));
y = Double.parseDouble(list.get(j + 1));
if (list.get(j).equals("*"))
{
result+=(x*y);
}
if (list.get(j).equals("/"))
{
result+=(x/y);
}
}
}
for(int k=0;k<list.size()-1;k++)
{
if (list.get(k).equals("+") || list.get(k).equals("-"))
{
x = Double.parseDouble(list.get(k - 1));
y = Double.parseDouble(list.get(k + 1));
if (list.get(k).equals("+"))
{
result+=(x+y);
}
if (list.get(k).equals("-"))
{
result+=(x-y);
}
}
}
}
display.setText(""+result);
}
}
|
|
|
|
|
Your code is not clear to understand, you need to try a bit more diagnosis to narrow down where the problem is. Also, this question (and the one below) really belong in the Android forum[^].
|
|
|
|
|
Member 13476776 wrote: Currently, if you enter 2+2*6, it'll only do 2*6
I don't believe that the code you posted does that.
Member 13476776 wrote: displaytext= displaytext.substring(0,displaytext.length()-1);
The code you posted never sets displaytext. So it will always be empty. You should have been getting the value from 'display' (presumably.)
Member 13476776 wrote: list.add(operators.nextToken());
You never clear 'list'. That is going to be a problem. I doubt that 'list' should even exist anywhere except the method that parses the result.
You never clear 'result'
Your algorithm is incorrect. It does the following
1. Start = 2+2*6
2. Parse multiplication/division: result += '2*6'
3. Parse addition/subtraction: result += '2+2'
That would leave result=16 (should be 14).
|
|
|
|
|
I am not sure of the logic. Please help.
My xml is as below:
<?xml version="1.0" encoding="UTF-8"?>
-<LinearLayout tools:context="com.example.sisir.calculatorproject.MainActivity" android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat.Display2" android:text="0" android:gravity="right" android:layout_marginTop="50dp" android:layout_marginRight="20dp" android:layout_marginLeft="20dp" android:id="@+id/display"/>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="30dp" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:id="@+id/button1" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:id="@+id/button2" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="3" android:id="@+id/button3" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" + " android:id="@+id/buttonadd" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="4" android:id="@+id/button4" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="5" android:id="@+id/button5" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="6" android:id="@+id/button6" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" - " android:id="@+id/buttonsubtract" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="7" android:id="@+id/button7" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="8" android:id="@+id/button8" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="9" android:id="@+id/button9" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" * " android:id="@+id/buttonmultiply" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="C" android:id="@+id/buttonclear" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="0" android:id="@+id/button0" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="=" android:id="@+id/buttonequals" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" / " android:id="@+id/buttondivide" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Calculator App" android:gravity="center_horizontal" android:layout_marginTop="15dp" android:id="@+id/title" android:layout_marginBottom="5dp"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Sisira Mandapaka" android:gravity="center_horizontal" android:id="@+id/name" android:layout_marginBottom="5dp"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Block 2A" android:gravity="center_horizontal" android:id="@+id/block" android:layout_marginBottom="5dp"/>
</LinearLayout>
</LinearLayout>
and my java file is as below
package com.example.sisir.calculatorproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonadd, buttonsubtract, buttonmultiply,
buttondivide, buttonequals, buttonclear;
TextView display;
String displaytext="";
double result;
double x, y;
ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
buttonadd = (Button) findViewById(R.id.buttonadd);
buttonsubtract = (Button) findViewById(R.id.buttonsubtract);
buttonmultiply = (Button) findViewById(R.id.buttonmultiply);
buttondivide = (Button) findViewById(R.id.buttondivide);
buttonclear = (Button) findViewById(R.id.buttonclear);
buttonequals = (Button) findViewById(R.id.buttonequals);
display = (TextView) findViewById(R.id.display);
display.setOnClickListener(this);
list = new ArrayList<>();
}
public void onClick(View view)
{
if(!(view.equals(buttonclear)&&!(view.equals(buttonequals))))
{
display.setText(display.getText()+""+((Button)view).getText());
if(displaytext.equals("0"))
{
display.setText(" ");
}
if(view.equals(buttonclear))
{
display.setText(" ");
}
if(view.equals(buttonequals))
{
displaytext= displaytext.substring(0,displaytext.length()-1);
StringTokenizer operators= new StringTokenizer(displaytext, "+-*/",true);
while(operators.hasMoreTokens())
{
list.add(operators.nextToken());
}
for(int j=0; j<list.size()-1; j++)
{
if (list.get(j).equals("*") || list.get(j).equals("/"))
{
x = Double.parseDouble(list.get(j - 1));
y = Double.parseDouble(list.get(j + 1));
if (list.get(j).equals("*"))
{
result+=(x*y);
}
if (list.get(j).equals("/"))
{
result+=(x/y);
}
}
}
for(int k=0;k<list.size()-1;k++)
{
if (list.get(k).equals("+") || list.get(k).equals("-"))
{
x = Double.parseDouble(list.get(k - 1));
y = Double.parseDouble(list.get(k + 1));
if (list.get(k).equals("+"))
{
result+=(x+y);
}
if (list.get(k).equals("-"))
{
result+=(x-y);
}
}
}
}
display.setText(""+result);
}
}
|
|
|
|
|
|
Hi, I'm searching for an application (or plugin at Eclipse / Netbeans) where I can analyze the structure of a class. It is important that I can see the package dependencies. Plugins I tried just give me an overview 1:1 or 1:n beetween the classes, but no information about the package dependence at a class.
A sample:
Class A
{
JButton btn;
void test()
{
btn = new JButton(myicon, „hello world");
String text = btn.getText();
btn.setText();
ArrayList<String> obj = new ArrayList<String>();
obj.add(„first");
obj.add(text);
}
void myfunc()
{
System.out.println(„test");
}
}
What I need here:
All foreign classes, functions, or constants (means all that are not defined at A) which are used through class A, are shown in a list.
myfunc() is not necessaray to show because it is definied at A - but it is doesn't matter if it is shown - that's okay.
It is not necessary that this tool (or plugin) shows it over a GUI.
Class ; Function ;
javax.swing.JButton ; init<icon, string=""> // Constructor
javax.swing.JButton ; getText() ;
javax.swing.JButton ; setText(String) ;
java.util.ArrayList ; init<>
java.util.ArrayList ; add(Object) ;
System.out ; println(String);
NOTE: I need no reverse engineering of a JAR file - I like to analyze my own java source files.
Thank you in advance!
|
|
|
|
|
|
Hager.Harald wrote: NOTE: I need no reverse engineering of a JAR file - I like to analyze my own java source files.
That is conceptually impossible.
Things like IDEs use an incremental compiler to validate the edit window as you type, so to that it can resolve, if possible, dependencies. The process might not create the final binary but it does involve a substantial amount of the same processing to get to the point where it can resolve such things.
Keeping in mind of course that the incremental compiler must also have a context to resolve dependencies, so java API libraries and other libraries that might be used.
Also keep in mind your example is simplistic and more significant applications will often use dependencies that cannot be resolved until the application runs.
|
|
|
|
|
Thank you for your answer (especially for your description how it works). This will help me to find an appropiate tool for my aims.
2017-10-18 Update: JArchitect has complied what I needed (but it is commercial)
modified 18-Oct-17 5:53am.
|
|
|
|
|