darkagn 315 Veteran Poster Featured Poster

Hi rheyang16 and welcome to daniweb,

There are a couple of things to consider when posting - first this thread is 18 months old and your statement has nothing to do with the topic. Second, you have to be more specific - what do you mean by "i don't sometimes get it"? If you have a specific question we can help you, otherwise it's a bit difficult sorry!

darkagn 315 Veteran Poster Featured Poster

anihC fo cilbupeR s'elpoeP ehT

darkagn 315 Veteran Poster Featured Poster

Hi alexasmith,

The problem you were having has to do with scope. Basically you declare your variable myInts1 in your main method and pass it as a parameter to your readArray method (this is all correct). However, inside your readArray method, the name myInts1 is not defined - it is outside the scope of this method. Inside your readArray method it is called array (which is the name it is given as the parameter). In order to perform calculations on myInts2, you need a second call to your readArray method passing myInts2 to it. This is also called array inside the readArray method - basically the readArray method can perform calculations on one array at a time (the array that gets passed in when the method is called).

I hope this has explained your problem further.

Enjoy!

darkagn

darkagn 315 Veteran Poster Featured Poster

I think what you probably need to do is sum all of the students' scores and then divide by the number of students. The average should be either a float or a double. Since all the scores are presumably int's and the number of students is an int. In Java an int/int calculation equals an int, so you will need to perform a cast.

double average = (double) sum / numStudents;

darkagn 315 Veteran Poster Featured Poster

Also, can I suggest putting a few extra println statements in while you are trying to debug your program. Try something like

num = scan.nextInt();
System.out.println("### num = "+num+(" ###");

This will confirm whether you are reading the correct value. Put this sort of statement after every input and don't forget to display your output so you can see the result. This will help to decifer what is happening in your program. Just don't forget to comment them all out before handing in your final assignment!

Cheers,

darkagn

darkagn 315 Veteran Poster Featured Poster

What error are you getting? Or is it just a logic error somewhere? Nothing really stands out, but if you can describe how it isn't working I might be able to find something...

darkagn 315 Veteran Poster Featured Poster

The first parameter tells you how long the first row (I guess this is the base of your pascal triangle perhaps?) is. The second parameter tells you how many rows there are (the height of your pascal triangle?)

darkagn 315 Veteran Poster Featured Poster
int create_pascals(int a, int b)
{
/*
This section of the code is checking to make sure that the two parameters passed into the function are non-negative and that a is larger than b. Otherwise we exit straight away.
*/
	int cons = 1, row;
	if (a< 0|| b<0|| b>a)
	{
		cout << " error!!! the program will now terminate." << endl;
		exit(1);
	}

	else
	{
/*
This section of code is doing the calculation for what the method is calculating. By the looks of it, the second parameter passed into the function tells the method how many rows are in the pascal and the first parameter passed in tells it how long each row is.
*/
	for (row=1; row<=b;row++, a--)
	{
		cons = cons*a/row;
	}
	return cons;
	}

}

Hope this has helped,

darkagn

ithelp commented: good explanation. ithelp +2
darkagn 315 Veteran Poster Featured Poster

I'm sure there's a more elegant solution but you could create an array where each element is the result of an OR result of the other two arrays.

for (int i=0; i<10; i++) {
array[i] = a[i] || b[i];
}
darkagn 315 Veteran Poster Featured Poster

luna

darkagn 315 Veteran Poster Featured Poster

I received the following email the other day and thought it was worth sharing. I chuckled but maybe it's just my stupid sense of humour... :twisted:

-----------------------------------------------------------------------------------------------


Are you male or female?


Look down...

I said look down not scroll down!!!

Ancient Dragon commented: Very true! +20
darkagn 315 Veteran Poster Featured Poster

A couple of comments for you to consider:

  • You will need a variable of type float or double to store and print the average
  • You can use modulo arithmetic to get the digits of a number (%)

These two hints should point you in the right direction. Let me know if I am being too vague but I am trying to give you a hint without telling you exactly what to do... ;)

darkagn 315 Veteran Poster Featured Poster

Try something like:

int total = 0;
for (int i=0;i<10;i++) {
total = a[i]+b[i]+c[i]+d[i]+e[i];
// print result
printf("total = "+total+"\n");
// print i to see which iteration of the loop
printf("i = "+i+"\n");
}
/* there is no need to reset total as it will be recalculated on the next iteration of the loop */

This should at least give you a clearer understanding of what is going on with your code, if not answer your question?

darkagn 315 Veteran Poster Featured Poster

Hi all,

I have done some development in OpenGL in the C++ platform and was thinking about trying my hand at DirectX which I have heard is a bit more challenging than OpenGL. From what I have read, DirectX seems to be the more popular format so I was wanting to learn how to use it. Or should I spend my time developing the skills I have gained in OpenGL further? What are the major differences/advantages/disadvantages of each? What are your thoughts/suggestions?

Cheers,
darkagn

PS - This is not a homework question - I was just interested in other people's thoughts on the debate. :)

darkagn 315 Veteran Poster Featured Poster

Sorry, I don't understand your question. Do you mean How do you select the same element from a series of arrays and add them together?

darkagn 315 Veteran Poster Featured Poster

What language(s) are your programs written in?

In order to get your source code you can copy your files to your home computer by SSH'ing to the college server and using an scp comand.

scp [source] [destination]

darkagn 315 Veteran Poster Featured Poster

Hi tomthehun,

Welcome to daniweb. I don't mean to be rude, but this thread was last used over 4 years ago, so I am not sure that you will get an answer to your question. Please check the date of forums before posting in them.

Cheers
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi siri_lito,

The rules of this forum are that you need to show an attempt before we can point you in the right direction. What have you done so far?

darkagn 315 Veteran Poster Featured Poster

Hi danieldear and welcome to daniweb!

The main rule here at daniweb is that people won't answer questions without a little effort being demonstrated. Perhaps you could post what you think a delegate is and the differences between java and c++ are and we can correct you or give some advice from there.

Cheers,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi Libran,

To help debug your code, try adding some println statements to gain a better understanding of what is going on. Please see my comments below.

import java.util.*;
import java.io.*;
public class FranchiseManagementSystem
{
    private BufferedReader br;
    private String[] str;

    public FranchiseManagementSystem() throws Exception
    {
        br = new BufferedReader(new FileReader("applicants.txt"));
        str = new String[50];
        readApplicantDetails();
    }

    private void readApplicantDetails() throws Exception
    {
        String thisLine = "";
        int i = 0;
        while ((thisLine = br.readLine()) != null)
        {
            [COLOR="Red"]System.out.println(thisLine);
            System.out.println(i);[/COLOR]
            str[i] = thisLine;
            [COLOR="Red"]System.out.println(str[i]);[/COLOR]
            i++;
        }

        if (str.length < 5)
        {
            [COLOR="Red"]System.out.println("str.length < 5");
            // str.length must be at least 5 since the following println statement fails to execute[/COLOR]
            System.out.println("Applicant entries are less than the minimum required number.");
        }
        else
        {
            for (i=0; i<str.length; i++)
                System.out.println(str[i]);
        }
    }  

}

Hopefully these println statements will help you debug your program. Don't forget to comment them all out for your final program! ;)

iamthwee commented: Good simple advice! +11
darkagn 315 Veteran Poster Featured Poster

Hi dynarial,

I'm just curious as to your line of thought here. Why is it that you are

not interested in undergraduate degrees from universities.

?

darkagn 315 Veteran Poster Featured Poster

Take a look at the Java API, in particular the javax.xml packages. There are some handy tutorials on the sun website too. You will probably need to use a DOM model to parse the xml.

darkagn 315 Veteran Poster Featured Poster

In your command line prompt type java myProgram to run a compiled version of a java program called myProgram. You may need to set an environment variable for the path where your java vm is installed. Let us know if you need to know how to do this... :)

darkagn 315 Veteran Poster Featured Poster

You have assigned the variable a as an object of type A. A's process() method throws an exception. You need to wrap the line

a.process();

in a try/catch block. Let me know if this hasn't helped.
Also,

new ExtendTest().process();

doesn't make sense. I think what you want is

ExtendTest et = new ExtendTest();
et.process();
darkagn 315 Veteran Poster Featured Poster

What will happen if devices = 70?

darkagn 315 Veteran Poster Featured Poster

Hi Ginwah,

Sorry but you have to do a little better than that. Do you know what CPI is?

darkagn 315 Veteran Poster Featured Poster

What is tak and tz?

Also, can you post the code for your add and delete tokens?

darkagn 315 Veteran Poster Featured Poster

Hi ceyesuma,

The super method is used to call a parent class's constructor method in the child class's constructor method. As an example...

public class Shape {
int height;
int width;
public Shape() {
height = 1;
width = 2;
}
}

public class Triangle extends Shape {
double area;
public Triangle() {
super(); // this means height = 1 and width = 2
area = height * width / 2.0;
}
}

In this example, Circle is the child class of Shape and it's constructor calls super as its first instruction and then extends it by doing something after.

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster
public static int firstMethod() {
int foo = x;
// do something with foo
return foo;
}

/* second method takes parameter of same type
as first method returns */
public static int secondMethod(int bar) {
int out = bar;
// do something with out
return out;
}

public static void main(String[] args) {
int boo = 3;
int i = secondMethod( firstMethod ( boo ) );
System.out.println( i );
}

I think this is what you were after but let me know if this hasn't explained it too well... :)

darkagn 315 Veteran Poster Featured Poster

Can ya'll take a look at this?

string names[3] = {"John","Anne","Mary"};   
     int score[i];

It's saying the "i" in scores is undeclared?
What do I do?

You have not declared your i before this line. An array needs its size set - you have done this correctly in your string array. You need to declare your i...

darkagn 315 Veteran Poster Featured Poster

In this thread I explain a similar question by example. It sounds like you need to describe the time complexity of this code in terms of k but I'll leave you to figure that out.

darkagn 315 Veteran Poster Featured Poster

Before you start thinking in terms of code, maybe try understanding the steps involved in english. Write out some dot points on a piece of paper to get a better idea of what is going on. I'll give you step one:

Display text: "Please enter employee's name." Get input and store it somewhere.

Don't worry about how you are going to do this at this stage, just work out what needs to be done. This is an important stage of the problem solving process called design and it is a stage that requires practice, but I can't stress how important design is in the real world with complex problems to solve.

So give that a go, repost what you think the steps are and let us know what you can / can't code.

darkagn 315 Veteran Poster Featured Poster

So help me to change goto with while or do while,,because I'm not really know about using while or do while,,and please give some information about the different between while and do-while..

The main difference between the while and do-while loops is that the condition in a while loop is checked before the inner code is executed, whereas the do-while loop's condition is checked after the inner code is executed. This means that the do-while loop will execute at least once whereas the while loop will only execute for the first time if its condition is met.

darkagn 315 Veteran Poster Featured Poster

When debugging I often find it helpful to add some println statements to see exactly what is happening. In your case I would insert a println statement immediately after

transval=Console.in.readDouble();

Something like

System.out.println("### transaval = "+transval+"###");

will help find out what is happening to your variable. Obviously this is the only thing that can exit your while loop both in your condition and your break statement. I personally have never used Console.in but prefer to use an InputStreamReader class (often in conjunction with a BufferedReader) and then parse the input received. But I hope I have given you a pointer in finding your error.

darkagn 315 Veteran Poster Featured Poster

What is the exact error that you are getting? Do you get it when you try to compile or when you run it?

darkagn 315 Veteran Poster Featured Poster

Hi anshads,

Just a word of warning - it is very dangerous to post your personal phone number, address, passport number, credit card number or PIN number on a forum. You can send a private message to a forum-ite by clicking on their name and following the link marked "Send a private message to..."

darkagn

darkagn 315 Veteran Poster Featured Poster

Hi xraaz,

What are your thoughts on how to proceed? Please show that you have at least thought about the solution and maybe we can see where you are headed and help you along the way...

darkagn 315 Veteran Poster Featured Poster

I think you want hours as an int and minutes as a float.

darkagn 315 Veteran Poster Featured Poster

This link is the java API. You will need it many times in your programming studies / career. For what you are talking about take a look at the classes starting with File, in particular FileReader and FileWriter.
Hope this has given you a starting point,
darkagn

EDIT: peter_budo gives a good example of this in this thread.

darkagn 315 Veteran Poster Featured Poster

a -> 1 step
For i = 1 to n -> takes n steps -> n+1 steps so far -> the 1 is negligible as n gets big so approx n steps so far
For j = 1 to i -> takes i steps for each n -> i*n so far -> approx n*n so far
For k = 1 to j -> takes j steps for each n*n -> j*n*n so far -> approx n*n*n so far
a = a+1 -> 1 step for each n*n*n -> 1*n*n*n

= n^3

darkagn 315 Veteran Poster Featured Poster

The PrintWriter(String s) constructor does not contain automatic flushing to the writer. You need to use println statements to do this rather than print statements. Or immediately after your while loop call out.flush().
Also, I think maybe you need or statements in your while loop as opposed to and statements, but that may depend on what you are actually trying to achieve.

darkagn 315 Veteran Poster Featured Poster

What is actually meant by the term "web-based development/solutions/applications"? In particular in relation to java? I hear this terminology all the time but I don't really understand what it means... :$

darkagn 315 Veteran Poster Featured Poster

First, you need to loop until the input = "E". The prompts would work like this:

int lineNumber = 1;
cout << lineNumber << "> ";
cin >> temp;

This will prompt with the current line number. You will need if statements to keep track of the line number according to what the user has entered.

darkagn 315 Veteran Poster Featured Poster

Sorry Ghost, I was at work but now I'm at home and can look more closely at your code.

I'm thinking that your problem lies in the reading of the second (and subsequent possibly) characters to your code string. Instead of

char letter = code.toCharArray()[i];

try

char letter = code.charAt(i);

I'm not sure if this will make any difference but I can't see anything wrong with the rest of your code. Does

cont.validate();

repaint the buttons? Do they return to dark after the first round?

EDIT: I just compiled your code on my PC, it looks like the code follows what I press rather than the other way around. On the very first pass, code.length() = 0, so there is no code to guess. I pressed yellow, and the second pass had a code of 'y'.

darkagn 315 Veteran Poster Featured Poster

I think you should call newColor() at the start of the play() method as opposed to the end?

darkagn 315 Veteran Poster Featured Poster

The odd thing is that it works on the first round... but not any of the others.

Do you mean that a full sequence of colours runs correctly the first time and then the next time the sequence is the same?

darkagn 315 Veteran Poster Featured Poster

Ah, sorry. I misunderstood what you meant. I think maybe you may need to call the repaint() method on the JFrame in the newColor() and reset() methods?

darkagn 315 Veteran Poster Featured Poster

Try using Util.Random class for your random generator. Something like:

java.util.Random randomGen = new java.util.Random(System.currentTimeMillis());
int rand = randomGen.nextInt(4);

will create a new seeded random generator every time. I think this should be more stable than using Math.random() but let us know if that's not the problem.

darkagn 315 Veteran Poster Featured Poster

Does your program compile and the buttons don't do what they're supposed to or does the program not compile at all?

darkagn 315 Veteran Poster Featured Poster

Not sure what the problem is, but you could try sending the output to a text file to view it in Notepad. Normally to run a java class file you would type something like

java myProgram

Try

java myProgram > output.txt

That will create a file, output.txt, that you can open and view the console output of your program.