|
I am new to Java and need to know how to correct this function call parameter passing compiling error. Any ideas?
List.java compiles and here is the code.
class List
{
private class Node
{ int col;
double val;
Node next, prev;
Node (int c, double v) { col = c; val = v; next = prev = null; }
public String toString() {
return String.format (" (%2d, %5.2f)", col, val);
}
public boolean equals(Node E) { return (this.val == E.val); }
}
private Node front, back, current;
private int row, length;
List(int r) { front = back = current = null; row = r; length = 0; }
void insertAfterLast(Node N)
{ Node node = new Node(N.col, N.val);
if ( this.length == 0 )
{ this.front = this.back = node;
}else {
node.prev = this.back;
this.back.next = node;
this.back = node;
this.current = node;
}
this.length++;
}
public String toString()
{ String str = "";
for(Node N = front; N != null; N = N.next)
{ if ( N == front ) { str = String.format ("%3d:", row); }
str += N.toString() + (N.next==null?"\n":"");
}
return str;
}
}
ListTest.Java does not compile. Here are the error and code.
-bash-3.00$ javac ListTest.java
ListTest.java:20: non-static variable this cannot be referenced from a static context
Entry Ea = new Entry(0, 0.0);
^
ListTest.java:24: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
A.insertAfterLast(Ea);
^
ListTest.java:26: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
B.insertAfterLast(Ea);
^
ListTest.java:28: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
B.insertAfterLast(Ea);
^
4 errors
class ListTest
{
private class Entry
{ int col;
double val;
Entry next, prev;
Entry (int c, double v) { col = c; val = v; next = prev = null; }
}
public static void main(String[] args)
{ int i;
List A = new List(1);
List B = new List(2);
Entry Ea = new Entry(0, 0.0);
for(i=1; i<=4; i++){
Ea.col = i;
Ea.val = Double.parseDouble(Integer.toString(i));
A.insertAfterLast(Ea);
Ea.val = Double.parseDouble(Integer.toString(10-2*i));
B.insertAfterLast(Ea);
Ea.val = Double.parseDouble(Integer.toString(9-2*i));
B.insertAfterLast(Ea);
}
System.out.println(" ");
System.out.println("Print Lists A and B which have been initialized");
System.out.println("A = " + A);
System.out.println("B = " + B);
}
}
|
|
|
|
|
You need to move your Entry class outside your ListTest class.
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
srbruno wrote: ListTest.java:24: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
A.insertAfterLast(Ea);
insertAfterLast is defined as void insertAfterLast(Node N) but you are passing an Entry object.
|
|
|
|
|
Please can someone explains for me what the following code does:
import java.awt.*;
import javax.swing.*;
public class Circleline extends JApplet
{
public void paint(Graphics g)
{
Dimension d = getSize();
int x = (int) d.getWidth();
int y = (int) d.getHeight();
g.drawLine(5, 5, x / 10, y / 10);
g.drawRect(5, 5, x / 10, y / 10);
g.fillRect(5 + x / 10 + 5 + 3, 5 + 3, x / 10 - 6, y / 10 - 10);
g.drawRect(5 + x / 10 + 5, 5, x / 10, y / 10);
g.drawOval(5 + x / 10 + 5 + x / 10 + 5 + 1, 5 + 1, x / 10 - 6,y / 10 - 10);
g.drawRect(5 + x / 10 + 5 + x / 10 + 5, 5, x / 10, y / 10);
}
public void init()
{
setSize(400, 400);
}
}
Thank you so much
|
|
|
|
|
sturabumukiza wrote: Please can someone explains for me what the following code does:
On my system it draws a Line in a rectangle, a filled rectangle in a rectangle, and a circle in a rectangle. Did you try it on your system?
|
|
|
|
|
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /Message.jsp(26,4) File "/header.html" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:334)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:367)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:468)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
org.apache.jasper.compiler.Parser.parse(Parser.java:133)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14
my file structure is like:
in ecclipse inetsolve is project name
Inetsolve
src
j2eelib
webroot
meta-inf
web-inf
lib
web.xml
.htmls
.jsps
could u plwase let me know the correct path for html and jsps
|
|
|
|
|
I need to know if my data structure classes have been properly created to accomplish the following:
I am trying to represent a matrix as a 1-dimensional array of Lists. Each List will represent one row of the Matrix, but only the non-zero entries will be stored. List elements must store the matrix entries and its column location. For example, the matrix below would have the following representation as an array of Lists.
| 0.0 4.0 5.0 |
M = | 3.0 0.0 0.0 |
| 1.0 0.0 2.0 |
1: (1, 1.0) (3, 2.0)
Array of Lists = 2: (1, 3.0)
3: (2, 4.0) (3, 5.0)
I have created two classes in different ADT files: The Matrix class and the List class. The goal is to create a two dimensional matrix as an array of Lists of Entry Objects. More specifically, the Matrix will be an array of deque linked list of Entry Objects. Only non-zero entries will be stored in the Matrix class. Therefore, the linked list (representing the rows of the matrix) is dynamically created since the entries of the matrix can be entered in any order. Entries are identified by their row, column, and value attributes.
Matrix.java code:
class Matrix
{
private class Entry
{ int col;
double val;
// Entry Constructor
Entry (int c, double v) {
this.col = c; this.val = v;
}
}
}
List.java code:
class List
{
private class Node
{ Object obj;
Node next, prev;
// Node Constructor
Node (Object o) { this.obj = o; next = prev = null; }
}
// List Fields
private Node front, back, current;
private int row, length;
// List Constructor
List(int r)
{ front = back = current = null;
this.row = r; this.length = 0;
}
}
|
|
|
|
|
Is there a reason for not using the generic types provided by java?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
package coverage;
import java.io.*;
import java.lang.String;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
/**
*
* @author IenZCrueL
*/
public class TryFileDialog {
public static void main( String args[] )
{
int arrlen = 10000;
byte[] infile = new byte[arrlen];
Frame parent = new Frame();
FileDialog fd = new FileDialog(parent, "Please choose a file:",
FileDialog.LOAD);
fd.show();
String selectedItem = fd.getFile();
if (selectedItem == null) {
// no file selected
} else {
File ffile = new File( fd.getDirectory() + File.separator +
fd.getFile());
// read the file
System.out.println("reading file " + fd.getDirectory() +
File.separator + fd.getFile() );
try {
FileInputStream fis = new FileInputStream(ffile);
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
String a;
int count=0,counta=0;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
a=strLine.toString();
if(a.contains("if") || a.contains("if else") || a.contains("if else") || a.contains("else"))
count++;
}
System.out.println("if statement = "+count);
//System.out.println("while statement = "+counta);
//Close the input stream
dis.close();
} catch(IOException iox) {
System.out.println("File read error...");
iox.printStackTrace();
}
}
} }
i write this code to count if statement
here is the statement where i count the "if"
if(a.contains("if") || a.contains("if else") || a.contains("if else") || a.contains("else"))
count++;
but this code will count ALL WORD contain "if".
do u have any suggestion?
|
|
|
|
|
Shakirin Mohd Amin wrote: if(a.contains("if") || a.contains("if else") || a.contains("if else") || a.contains("else"))
count++;
but this code will count ALL WORD contain "if".
do u have any suggestion?
Why test for "if else" twice when you have already tested for "if", and why are you counting "else" statements when you are trying to get the count of "if"s?
To do this properly you need to break each line into tokens of whole words and then look for "if" statements. You will also need to ignore comments in such lines as that will possibly give incorrect results.
|
|
|
|
|
then i should use token?
ok i'll try that
thanx ya
|
|
|
|
|
How to draw a Gantt Chart that the task bar could remove or zoom by user.What kind of control to implement the task bar.please help me.
|
|
|
|
|
|
I Googled.I just want to ask that kind of dynamic task bar(remove and zoom)is maked by what kind of control.For example:rectangle or lable.Our Project id based Swing.Please help me.
|
|
|
|
|
please tell me the code to calculate the practical numbers in a given range..
|
|
|
|
|
rics 2 wrote: please tell me the code to calculate the practical numbers in a given range..
You need to learn to do your own work, not expect others to do it for you. If you then encounter a problem in your code you can post a specific question here.
If you have absolutely no idea of the algorithm for practical numbers then you can use any of the internet search engines; Google yields some interesting hits.
|
|
|
|
|
If you understand this then you can code it:
In mathematics, and in particular number theory, a practical number or panarithmic number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n. For example, 12 is a practical number because all the numbers from 1 to 11 can be expressed as sums of its divisors 1, 2, 3, 4, and 6: as well as these divisors themselves, we have 5=3+2, 7=6+1, 8=6+2, 9=6+3, 10=6+3+1, and 11=6+3+2.
Source: Wiki[^]
|
|
|
|
|
|
I need to know if I have successfully created a Square Matrix List of Entry Objects. The detail desciption and my java code solution follows:
A) Description
1) The List ADT will export its services to the Matrix ADT.
2) The List ADT will defines a List of Objects. The Objects referred to by these List elements will be defined in the Matrix ADT
3) The Matrix ADT, in file Matrix.java, defines the Matrix class. This class will contain a private inner class that encapsulates the column and value information corresponding to a matrix entry.
B) Code
List.java
class List
{
private class Node
{ Object obj;
Node next, prev;
// Node Constructor
Node (Object o) { this.obj = o; next = prev = null; }
// toString: Overrides object's toString method.
public String toString() { return String.valueOf(obj); }
}
// List Fields
private Node front, back, current;
private int row, length;
// List Constructor
List(int r)
{ front = back = current = null;
this.row = r; this.length = 0;
}
}
Matrix.java
class Matrix
{
private class Entry
{ int col;
double val;
// Entry Constructor
Entry (int col, double val) { this.col = col; this.val = val; }
// toString: Overrides Object's toString() method.
public String toString() { return " (" + col + ", " + val + ")"; }
}
// Matrix Fields
private List[] Entry;
private int size, nnz;
// Matrix Constructor
Matrix(int n) { Entry = new List[n]; this.size = n; nnz = 0; }
}
|
|
|
|
|
|
I am beginner to java.so please bring me any small applet programs to do.
Just give me the concept.I will try coding myself...
|
|
|
|
|
Here[^] is a good java applet tutorial for beginners. You will find 4 chapters with examples. The code is well commented, but only the basics of applet programming are covered. Anyway, I think that this is a good "learn by examples" tutorial for Java applets.
I hope this helps you.
Nuri Ismail
|
|
|
|
|
Thank you its realy helpful
|
|
|
|
|
can someone help! I am working with graphics primitives and I am having a problem in creating 5 drawings in 5 rectangular regions within one window.The following is what i have managed to come up with.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class Circleline extends JApplet{
int x=300,y=100,r=50;
int xPoints[] = {50,80,80,50,50}; //Sets x coordinates to draw to/from
int yPoints[] = {50,50,80,80,50}; //Sets y coordinates to draw to/from
public void paint(Graphics Obj,Graphics g) //paint function (essential for graphics)
{
Obj.setColor(Color.black); //Sets the color to green
Obj.fillPolygon(xPoints,yPoints,xPoints.length); //Uses the x,y coordinates declared earlier to draw a filled square
for(int i = 0; i < xPoints.length;i++) //for loop to add to x values to move it across screen
xPoints[i] += 200;
Obj.drawPolyline(xPoints,yPoints,xPoints.length); //draws an empty square at the new x values and same y values
}
public void paint(Graphics g){
g.drawLine(3,300,200,10);
g.drawString("Line",100,100);
g.drawOval(x-r,y-r,100,100);
g.setColor(Color.blue);
g.fillOval(x-r,y-r,100,100);
g.setColor(Color.magenta);
g.drawString("Circle",275,100);
g.fillRect(400,50,200,100);
g.setColor(Color.pink);
g.drawRect(400,50,200,100);
g.drawString("Rectangle",450,100);
g.setColor(Color.yellow);
g.drawRect(250,250,250,250);
g.fillRect(250,250,250,250);
g.setColor(Color.gray);
g.drawString("Square",350,350);
}
public void init() //Initialize
{
setBackground(Color.cyan); //Make window background cyan
setSize(400,400); //Set window size
}
}
Please help me so that the code can output 5 drawings in 5 rectangular regions within one window. Thank you
|
|
|
|
|
First you need to specify the regions for example region one is from (0,0), (0,100), (100,0), and (100,100) then when your drawing you should assign the drawings within the range of those region. Do note that you also need to use the frame size coordinates for a better view i.e. all the drawings will be viewed when you launch the application plus when you resize the frame the drawings will also resize.
|
|
|
|
|