somjit{} 60 Junior Poster in Training Featured Poster

It's funny to see ASAP coming from someone apart from one's stingy boss :D

somjit{} 60 Junior Poster in Training Featured Poster

Getting a private auto-message for an sponsored post, and coming here to find homework.. just screwed my mood.

Dani commented: Just came across this post. Sorry DaniWeb failed you :( We'll do better +32
somjit{} 60 Junior Poster in Training Featured Poster

Update : turns out to be simple enough , just need an interface. something like this.

public class Summation {

    public Double calc(int lower, int upper, Function f) {
        double acc = 0;
        while (lower <= upper) {
            acc += f.definition(lower++);
        }
        return acc;
    }

    public static void main(String[] args) {
        Summation sigma = new Summation();

        // implement definition(double) according to your mathematical function
        // this one does a sum of integers
        System.out.println(sigma.calc(1, 19, new Function() {

            @Override
            public double definition(double x) {
                return x; // this can be more complex
            }
        }));
    }
}

Where Function is a basic interface

public interface Function {
    public double definition(double x);
}
somjit{} 60 Junior Poster in Training Featured Poster

i have about 18 years of expirience banging tables :P only reason i dont have a drumkit at home is because of how quiet my neighborhood is , and how much the neighbors would like to keep it that way. I played guitar , until the neck bent and now tunes drop even with half-hours strumming. :(

somjit{} 60 Junior Poster in Training Featured Poster

your text file looks pretty ordered to me. The only place where you might need scanner for input parsing purposes is when there may be unexpected lines in-between two valid lines , or a valid line has garbage in between two valid key words. split() works there too , but then you have to put in more checks. So unless you have a dirty , unordered file , go with the split-switch method.

Also , If you do decide on using scanner , (though its a bad idea if your file is always like this) , check more into the condition for hasNext() to return false. you can say that it knows there is a wall in front of it only after it has hit it ;)

somjit{} 60 Junior Poster in Training Featured Poster

are you sure that the code you posted is exactly the one your working with ? If thats the case , then i see a lot of spelling mistakes in your code , Starting from the 1st line. Maybe taking care of them will bring you better luck.

Your code is painful to read. Why not break things up in your class in segments like

fetchDOB(/* arguments */);
fetchName(/* arguments */);
.
.

each will have their own code inside them , and makes things easy to follow. It will also be easier for you to debug aswell. It would help out both you and us if you do that first.

somjit{} 60 Junior Poster in Training Featured Poster

are you trying to add/remove something to/from your arraylist while your program is running ? like read something from the console , parse it as a string and add it to your string type arraylist ? if so , then yes. that is quite a normal usage.

somjit{} 60 Junior Poster in Training Featured Poster

I see fresh college grads all around running for a (/an almost) saturated software development field. Myself not being any exception to this either. But I'm kind of in a dilemma.

  1. I have invested around 12 months learning stuff like Java, databases and other cs stuff.
  2. but I got a job offer from a company that works in the networking domain.

many have told me that the professional environment varies with location , and I do believe enough logic to be in that statement , however I'm still making this post to ask a few questions, answer for which I would love to have from the professionals out there.

  1. Does the networking domain for freshers start from the support level? I've read a few blogs and threads which indicate that to be the norm.
  2. What opportunities for growth does this domain provide for freshers? How fast does it grow?
  3. Does the networking domain, in general pay as well as the software one? Like as in incentives, bonus, hikes and salary in general?

Some answers would help out a lot.

somjit{} 60 Junior Poster in Training Featured Poster

welcome to daniweb :)

apart from scanner , you can also try out a BufferedReader .
i dont really see console being used for this kind of stuff. any particular reason you're using it ?

also , whatever you choose to use , its a good practice to close the io stream after your done with it. traditionally its done inside a finally() block , but with java 7 , a fancy try with resources block can be used.
you can check it out here .

somjit{} 60 Junior Poster in Training Featured Poster

thanks a lot for your help :)
marking thread solved :)

somjit{} 60 Junior Poster in Training Featured Poster

going by deceptikon's advice regarding using a console application , and adak's advice regarding compiling/executing from within the ide , the original problems are no longer coming up.
marking this thread solved.

somjit{} 60 Junior Poster in Training Featured Poster

1st of all , let me mention my hardware :

HP G6 laptop with win8 :
amd a4 4300M, radeon graphics : 512 MB 7420G + 1GB 7670M , 4 gb 1600 Mhz ram.

4 yr old Desktop running xp sp2 :
amd athlon x2 250 , inbuilt graphics : 256MB NVIDIA GeForce 7025 / NVIDIA nForce 630a, ram : 2gb DDR2 800Mhz ,

Long Story short : i think speccy doesnt give accurate results on win8 + HP hardware , or , is bugged somehow , and causes CPU temp to shoot to astronomical levels.
if you care about how i come to say this , read below :

I wanted to note the CPU temerature of my laptop , and i have always been a speccy user , so installed the latest speccy in the lappy , and ran it. i was surprised to see an idle temperature over 86 degrees Centigrade. i ran a kasperky scan , and it went upto 120 degrees !! i thought it must be a mistake , so i installed coreTemp , and a bunch of other monitors. All showed the same readings !

whereas , in my desktop , they all show an idle temp of around 33 deg (recently changed the thermal paste) and under load ( Photoshop rendering ) it went upto a max of around 44 deg.

it has been around a week since this event , iv contacted hp , and an engineer had …

somjit{} 60 Junior Poster in Training Featured Poster

what i felt from the instructions :

  1. create a student class
  2. write the private instance variables
  3. overload the default constructor with social security number and GPA arguments
  4. write the public getters/setters etc , and also , override toString() and equals()
  5. then write a main method ( this is your test client )
  6. create new instances of students inside main, passing in social security number , GPA etc feilds in the constructor itself
  7. print them out in any manner you like.
somjit{} 60 Junior Poster in Training Featured Poster

add() can always work without main method.. this is a simple code showing that happening.

import java.util.ArrayList;


public class tester {

    ArrayList<String> arr = new ArrayList<String>();

    public tester(){
        arr.add("sure ");
        arr.add("it ");
        arr.add("does");
        arr.add("... see :) ");
        for(String s : arr)
            System.out.print(s);
    }

    public static void main(String[] args){
        tester t = new tester();
    }

}
somjit{} 60 Junior Poster in Training Featured Poster

instead of

        while(current_node != null)
        {
            System.out.println(current_node.name+"\t"+current_node.age);
            current_node = current_node.next;

        }

do this :

        while(current_node.next != null) // as the head (which the current node has been assinged ) is a sentinel , and actual data starts from the next node
        {
            System.out.println(current_node.name+"\t"+current_node.age);
            current_node = current_node.next;

        }

also , in your constructor :

    public aaa()
    {
        head_node = new node();
        current_node = new node(); // shouldnt this be current_node = head_node ?
    }

im not sure of the advantage that creating a separate node for the "current_node" gives... especially since your assinging the head to the current node in your display method later on.

somjit{} 60 Junior Poster in Training Featured Poster

individual question with a class to run both of them

sorry, i didnt get you there...

regarding your code , your creating isPerfect as a separate class , so when you want to use it inside your allPerfect class , you have to create a reference to it. since your calling it directly , it says it cannot find the class, as java doesnt know where to look for the isPerfect method.

also in this line System.out.println(ap.allPerfect(num)); this wont work as allPerfect()'s return type is void. you cannot print something when its not there!

somjit{} 60 Junior Poster in Training Featured Poster

welcome to daniweb. :)

how can i make my 10 different program as one program

would be good if you could explain a bit more about these "programs" . if you have written some code , post them here , that would speed up the problem solving procedure. :)

somjit{} 60 Junior Poster in Training Featured Poster

@ mostlydangerous

use the edit post button , consecutive posts look a bit cluttered... and odd.

@pvn29 : use indentation on your code , else will look cluttered.

i edited your code a little bit.
this one is indentated , and as soon as size equals initialCapacity , it exits the program.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class UserList {
    public static void main(String[] args) throws Exception {
        String str1, str2 = "username";
        int index;
        int initialCapacity = 3;

        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<String> users = new ArrayList<String>();
        System.out.print("Enter a user name: ");
        str1 = dataIn.readLine();

        while (str1.length() > 0) {
            boolean containsString = users.contains(str1);
            if (str1.equals(str2))
                System.out.println("That user name is NOT allowed!");
            else if (!containsString) {
                users.add(str1);
                System.out.println("User \"" + str1 + "\" added to user list.");
            }
            else if(containsString){
                System.out.println("User \"" + str1 + "\" already in user list.");
            }
            if (users.size() == initialCapacity) {
                    System.out.println("List is full!");
                    System.out.println("Last entry is " + users.get(initialCapacity - 1));
                    break;
            }
            System.out.print("\nEnter a user name: ");
            str1 = dataIn.readLine();
        }

        System.out.println("Program complete.");
    }
}
somjit{} 60 Junior Poster in Training Featured Poster

@stultuske : yes , i should have elaborated that part more.

@bobit : although ur using getters and setters , all the instance variables of your code are open and exposed. you should change them to private. like , instead of double radius , it should be private double radius

reason? well , When you write your code , if all the variables are exposed , they can get accessed and changed from anywhere in the code during run time, and you might find that ur output is quite different from one you hoped for.. the very reason we use public getters and setters is such that the instance variables can stay private, protected from any outside influence , and can only be modified by calling the respective getters and setters for that particular variable. this whole "protect your instance variable " thingy is the famous java concept of encapsulation.

apart from making your code safer through encapsulation, getters and setters also lets you put in checks , like

public void setRadius(int r){
    if( radius < 0 ) System.out.println("negative values not allowed");
    else if(r > 10) radius = r; 
    else radius = 5; // provide a default value of 5 to radius
}

so here, not only is radius not allowed to be zero , and is changed to default value of 5 if a value less than 10 is passed , you also get a warning if negative values are passed to it. you might not need …

stultuske commented: there you go :) +14
somjit{} 60 Junior Poster in Training Featured Poster

@michael : you see , apparantly , the results will look like they are giving random numbers , but lets go through a simple case:

suppose you have 3 cards from a deck , so number of diff permutations will be 3! = 6 , lets see this in a bit detail :

'__________' '_________' '_________'

the above are 3 slots, where you can put the cards.

for the 1st slot , you have 3 options.
for the 2st slot , you have 2 options left.
for the 3st slot , you have 1 option left.

thus 3*2*1 = 6 total number of ways you can arrange the cards.

if you want to do this in code , you will have to reduce the population from where your taking the cards by 1 in every turn , thus resulting in 2 options down from 3 , and then 1 option down from 2 in the 2nd and 3rd runs.

if you dont do this , and take a random number from the whole population , ie 3 on each turn, you would get 3*3*3 = 27 combinations , which isnt correct, and will give you biased results. You can check that with the naked eye as well as the result obtained here(27) isnt divisible by 6 ( the correct result ) . So some arrangements will turn up a greater number of times than others.

i had posted a link on one of my earlier replies... there you …

somjit{} 60 Junior Poster in Training Featured Poster

is there a standard best/worst case for sorting algorithms?

there are hundreds of sorting algorithms out there... some of them have different variations of themselves as well. they all have their own standard best/worst case complexity.

example : considering two classic algorithms : quicksort and mergesort, quicksort has time complexity higher than mergesort (both in the region of NlogN ), but generally a standard quicksort algorithm works faster than mergesort .. why? because mergesort requires more space in the form of an auxillary array in its algorithm, so for huge data structures , moving values from one array to another eats up the time complexity advantage it had over quicksort.

notice i say generally , because the original quicksort can go and run in quadratic time in presence of duplicate keys, but this error was eventually solved by implementing random shuffle at the begining , and then using a 3 way partioning method to keep the duplicates grouped in order.

so I was thinking a vector where all elements are the same would be the worst case scenario, and that a vector filled with randomly generated numbers would be the average scenario, and the best case scenario would be on an already sorted vector,

mergesort is an optimal sorting algorithm , meaning that its upper and lower bounds are both in the region of NlogN.. so it doesnt matter how the data is arranged to mergesort , it will take more or less equal time anyways.

somjit{} 60 Junior Poster in Training Featured Poster

this will not return unique random number.

Yes. i read recently that choosing a random number from an entire array wont give you correct results. which is what you said above as well.. knuth shuffle works around this problem by choosing randomly between 0 and i , or in some cases (n-1) to i , but not from 0 to (n-1).

edit : found this to be an interesting read.

somjit{} 60 Junior Poster in Training Featured Poster

In other words, in each iteration, the odds of choosing the current value are:
(number of values still needed) / (number of values left to choose from)

i took it from there....
if:

randomNum = random.nextInt()
odds = (number of values still needed) / (number of values left to choose from)
range being the range from which the samples have to be taken

then what i meant was that will

( odds x randomNum x range ) + min

this formula above , iterated over K times , give K sample units , such that no two sample units are the same?

im saying about this, because i feel that if this is possible, then the OP can put the range as 78 , and then keep a count , and when the count matches any of the numbers generated through this sampling process , he keeps that particular value , else disregards n and iterates again...

somjit{} 60 Junior Poster in Training Featured Poster

and store value in Set.If added successfully(means unique as set doesnot support duplicacy) means it is unique.

that sounds good... but what about the expense of storing the data in the set... ? if that isnt too expensive, then i guess its going to be a pretty good solution.
i talk about expense here coz i have a feeling that the Original poster wanted to use that particular method to reduce memory requirement from O(N) to O(K) , where N = total population, ie 78 , and K = sample size , ie 5 .

somjit{} 60 Junior Poster in Training Featured Poster

In other words, in each iteration, the odds of choosing the current value are:
(number of values still needed) / (number of values left to choose from)

so if i have to find 'k' non reapeating numbers from a certain 'range' , and if i do this:

((obtained random num).(odds).(range)) + min

will this be good?

also, if it does give good results, then that would mean the results are in uniform distribution, so calculating standard deviation over each sample should give a high value right ? my apologies if im being vauge, i havent touched statistics in over four years.. gone quite rusty..