somjit{} 60 Junior Poster in Training Featured Poster

i hope you have taken a look at the links i asked you too , however , sometimes an example explains best. i modified your code a lot , and instead of all the classes , you have just one class now , the char_array{} class renamed to hangman ( just felt that to be more in place with things ) and the other classes you used to have , iv converted them into methods under the hangman class.

here is the code: (this is a basic stuff that will get you started with ideas)
i kept the chosen word as "pizza" as u'll see in the code , go ahead run it , put the words of pizza , and see what happens.

import java.util.*;

public class hangman {

    private static String[] words = {"insert","moron","fool","bored","crazy","hello","nice","word","brother","senior","junior",
                "glasses","tiny","floor","code","internet","lake","sport","prince","aunt","seven","cartoon","trump","zebra","chalk",
                "random","person","movie","place","thing","rabbi","chest","hairy","clothes","close","open","closed","filled",
                "waste","find","easy","hard","pitch","base","come","twins","cracka","whatever","keyboard","actually","alabama","sixteen","computer","telephone","habitat","hangman","java" };
    public String chosenWord;
    public String x;
    public int counter = 0;//variable to increase in case of double letter. Added to counter in main function.

    public hangman(){
        double r = 1 + Math.random()*words.length;
//      chosenWord = words[(int)r]; // eventually this should be used
        chosenWord="pizza"; // but its good to use what you know while building n testing your code.
//        x = b;

    }

    public void checkInput(Scanner is){
        boolean[] pos = new boolean[chosenWord.length()];
        int counter = 0;
        while(counter!=chosenWord.length()){
            System.out.println("\n enter letter: ");
            String ip = is.nextLine();
            for(int i = 0 ; i < pos.length ; i++){
                if(ip.charAt(0)==chosenWord.charAt(i)){
                    pos[i] = true;
                    counter++;
                } 
        }
            int i = 0;
            while(i<pos.length){
                if(pos[i]) …
somjit{} 60 Junior Poster in Training Featured Poster

main main = new main();
you dont have a Main() class , and main() , rather

public static void main(String[] args){}

in java serves a different purpose.. its the 1st method looked at by the jvm , without it , you cant compile your code.. so seems like a two - way error...
what did you intend on making this do? im sure we can fix that :)

edit : i just looked again , and you do have a main class! sorry about that... i overlooked the main class in the 1st post , but do you need all the different classes for this? it can be all done with one class. also , the graphics class you posted , just keep it as another method inside the char_array() class , and look up at the switch - case statements and how they work , they can really simplify your existing code.

another improvement , something that can make your code much simpler , is using ArrayLists . using that , you can check if the word contains the user input by simply using the contains() method of an arraylist. check these two out. its gonna be fun :)

somjit{} 60 Junior Poster in Training Featured Poster
        System.out.println("How many positions do you want?");
        int userInput = play.nextInt(); // this will lead to problems
        Clown[] circusClowns = new Clown[userInput];
        for (int i = 0; i < circusClowns.length; i++) {
            System.out.print("Enter the name of the clown: ");
            name = play.nextLine();

this part of the posted code will lead to new errors , as the nextInt() method will leave behind a newline character which will be picked up by the nextLine() method , and the program will crash. put an extra play.nextLine(); right below the for() and before the System.out.print("Enter the name of the clown: "); part to catch the stray newline character left in the stream.

As far as I can see, your driver is asking for doubles and your main class is sending ints. So thats never going to work.

seems to work for me.. promotion into a higher byte variable is done automatically , however , if it was a double to int conversion , that would result in an error.
that said, just because java takes care of int to double conversion , we shouldn't knowingly pass int to somthing that asks for a double either, especially when we can do something about it.

somjit{} 60 Junior Poster in Training Featured Poster

welcome to daniweb :)

maybe you could post for the other classes as well , that way members could run it and check out the nuances themselves.. not only that , but it would be more fun too .. :) good to play hangman :)

however , at a first glance , i dont see the role of the counter variable inside the char_array() class , i dont see it being used for anything...
also ,

    public void init(String a, String b){
        word = a;
        x = b;

    }

this is supposed to (re)initialize it... with a new word. and it would have a cascading effect on some_function() as it works with the word initialized by init.
also , i have a feeling that char what_user_sees[] = new char[word.length()]; has a role to play in the re initialization , as what user sees shouldnt get a new char array everytime , rather it should be appended to what is there already...

somjit{} 60 Junior Poster in Training Featured Poster

by "client" what iv come to understand is the main method that runs classes and its methods in a particular fashion , to get a particular job done.

u might hear terms like "test client" as such as well... they are basically a tester class with just the main method , and uses many other classes for doing some work.

somjit{} 60 Junior Poster in Training Featured Poster

Instance variables can be initialized in constructors, where error handling or other logic can be used. To provide the same capability for class variables, the Java programming language includes static initialization blocks.

umm.. whats the difference between class variables and instance variables? i thought they were the same ? i read that we work with instances of the class , instead of the class itself.. so i suppose then the exceptions to this would mean a static class ? like math?

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

u had "del" and "delNode" , that was a bit confusing... basically , what you have to do is :

temp = curr.next.next; // stores address of node pointed to by the node you want to delete
curr.next.next = null; // node_to_delete now points to null
curr.next = temp; // node prior to the one to delete now points to the node originally pointed to by the deleted node.
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

both are good , and usually it depends on the particular code your working in. but if the 1st method can be done , ie if the values to set are known at the time the new instance is created , i cant see why not to use it... makes the code shorter and more compact.
However , when the values to set are not known atthe time you call the new on any object , then you have your default no arg constructor , and set the values at a later time using the setter methods.

somjit{} 60 Junior Poster in Training Featured Poster

is there any particular reason ur keeping your readlines method static?

edit : didnt see that james already posted there....

somjit{} 60 Junior Poster in Training Featured Poster

james and radhakrishna already pointed out the things you should be doing.. i just saw that in ur isSolvable() method , ur doing this :

            if(((a*d) - (b*c)) == 0)
                return 0;
            else
                return 1;

you dont need to have a if else structure for return.. once return is called , the method exits. so the above code can be compressed down to

 if(((a*d) - (b*c)) == 0) return 0;
 return 1;

makes code look more compact , especially when your doing more complicated stuff. learnt about this recently , so id thought id share :)

somjit{} 60 Junior Poster in Training Featured Poster

thank you :)

somjit{} 60 Junior Poster in Training Featured Poster

perhaps this isnt a good place to post this query , but im doing so as my doubt relates to the if-else structure that has been talked about here...

in this code

    // compare by y-coordinate, breaking ties by x-coordinate
    public int compareTo(Point2D that) {
        if (this.y < that.y) return -1;
        if (this.y > that.y) return +1;
        if (this.x < that.x) return -1;
        if (this.x > that.x) return +1;
        return 0;
    }

Point2D is a class that deals with x,y co ordinates in a 2D plane , and it implements comparable() . my question is , that if one condition gets satisfied , lets suppose the 1st one, then will the next ones be checked?
i dont know if doing executing a return exits that method , hence this post. by the way, is return a method? i tried to google for it , but in every case, the return google thought im asking for wasnt what i was asking for.. i got stuff like returning arrays etc , but not what return means in java... so no luck there...

my apologies if im being vague , and making a post in the wrong place...

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..

somjit{} 60 Junior Poster in Training Featured Poster

@ G_S:

This is used for referring to this class' variable whose name is similar to the method's parameter?

a methods parameter, also called a local/static variable can be same or different to a class' variable, also called a instance variable. WHY? because they have different scopes... atleast in the above example it does. also, u should know, that a local variable lives in the stack , and an instance variable lives in the heap. so that further adds to why having the same name really doesnt matter too much.

Children inherit their parent's methods and attributes BUT using the paren't setter doesn't set the children's variables? If so, then using the childrens setter will only set the age and, id and name of ONE child and not the parent's or the other child's?

you can always download eclipse or netbeans, install it, and put this code there, and check ur ideas. thats one of the benefits of coding... that way, u can see 1st hand what effects these tweaks result in. whatever doubts you have then, you can always post here. :)

also, i agree that since we dont know what your teacher did, it would be a bad idea to compare with it. maybe you can post the code here. :)

somjit{} 60 Junior Poster in Training Featured Poster

inheritance is really handy in eliminating duplicate code, and making the overall code more compact, since doctor and patient have things in common, its handy to put the common stuff in a superclass.

as regards

Can't we use only the children, since they will also have the setter method created in the parent along with the parents three attributes?

class people {

    private String name;
    private int age,id;

    public void setName(String name){
        this.name = name;
    }

    public void setAge(int age){
        this.age = age;
    }
    public void setId(int id){
        this.id = id;
    }

    public void display(){
        System.out.println("name: " + name + " age: " + age + " id: " + id);
    }

}

class patient extends people{

    String disease;

    public void setDisease(String d){
        this.disease = d;
    }
    public String getDisease(){
        return disease;
    }
}

class doctor extends people{

    int salary;

    public void setSalary(int s){
        this.salary = s;
    }
    public int getsalary(){
        return salary;
    }
}


public class peopleTester {

    public static void main(String[] args){
        doctor d = new doctor();
        patient p = new patient();

        d.setName("kurt");
        d.setAge(40);
        d.setSalary(3000);
        d.setId(10);

        p.setName("jhonny");
        p.setId(4505);
        p.setAge(23);
        p.setDisease("fever");

        d.display();
        p.display();
    }

}

here, i did just use the children, and all the inheritance worked quite alright :)

the teacher used the set method OF THE PARENT CLASS to take care of the 3 common variables and then used the children's methods to set the remaining variables that were still not set.

when you use the setters of the superclass (ie, …