Violet_82 89 Posting Whiz in Training

Hi I would be really interested to understand how exactly the toString() method works. I have read quite a bit about it, that it returns the string representation of
an object, that the default one can be overridden with @Override etc etc.
Let's have a look at some examples:

   @Override // indicates that this method overrides a superclass method
   public String toString()
   {
      return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f", 
         "commission employee", firstName, lastName, 
         "social security number", socialSecurityNumber, 
         "gross sales", grossSales, 
         "commission rate", commissionRate );
   } // end method toString

and it is called in this way

System.out.printf( "\n%s:\n\n%s\n", 
         "Updated employee information obtained by toString", 
         employee.toString() );

where employee is an object. firstName, lastName etc are all private instance variables of the class

Or anothe similar one:

@Override // indicates that this method overrides a superclass method
   public String toString()
   {
      return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f", 
         "commission employee", firstName, lastName, 
         "social security number", socialSecurityNumber, 
         "gross sales", grossSales, 
         "commission rate", commissionRate );
   } // end method toString

which is called by

 System.out.printf( "\n%s:\n\n%s\n", 
         "Updated employee information obtained by toString", employee );

again, employee is the object.

Now what I don't understand is what is the difference between printing an object this way and printing an object with a normal call to System.out.printf and list the instance
variables? I mean why do I need a toString method for? Maybe in the examples above, since they …

Violet_82 89 Posting Whiz in Training

Hi all it's that time again, java exercise! Mindful of what happened last time http://www.daniweb.com/software-development/java/threads/449525/building-a-simple-airline-reservation-system-exercise/ , this time I have decided that I want to have all the pseudocode done before I even start thinking about how to code the whole thing.
This is what the exercise requires:

Create a TicTacToe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 2 dimensional arrays. Use an enumeration to represent the values in each square of the array. The enumeration's constants should be named X, 0 and EMPTY (for a position that doesn't contain an X or 0).
The constructor should initialize the board elements to EMPTY. Allow 2 human players. Wherever the first player moves place an X in the specified square amd place an 0 wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won and whether it's a draw.

If anybody is interested this exercise is taken from the Deitel and deitel book "Java How to program" p393.
Ok, this is my pseudocode:
There are plenty of comments so it should be clear what's going on:

/*PSEUDOCODE*/
create TicTacToe class
    private 3-by-3 two_dimensional_arrays;//holds the board
    private boolean isFull = false//if true all the squares have been assigned.     
    private boolean isDraw;//to check if the game is draw
    private boolean squareStatus;//returns the status of a square, if false the square is …
Violet_82 89 Posting Whiz in Training

uhm, sounds a bit suspicious...I can only assume (sorry oalee and CimmerianX) that you don't have a genuine copy of windows. You should buy a genuine copy of windows and the serial number will come with it. If you're trying to install the same genuine copy of windows onto another machine you should be able to transfer the licence to it.

Violet_82 89 Posting Whiz in Training

ok chaps, I appreciate you have diverging opinions and I can't really butt in because I know only very little. SO why don' we start just from scratch again? I think I have made a very big mistake at the beginning, which is not producing any pseudo code but start the development straight away.
So here's some pseudocode, maybe that will help me. Once I get that right I suppose it shouldn't be too bad to build the program. Needless to say my pseudocode has some issues, as in I am doing a few things twice. I know bguild doestn' like that so perhaps you guys can help me with the pseudocode first and then I can move on to build the application?

Please type 1 or 2 to choose the class, 0 to quit
    if 1
        generate seat at random from values smaller than the last index of the last seat of the section (10-5 = 5 so index 4)
    else if 2
        generate seat at random from values bigger than index4 of the array and smaller than the last index of the last seat of the section array.length - 1 

    check whether seat has been already assigned
    if so generate seat again till you find a seat that hasn't been assigned to
    if not assign the seat and display boarding pass

    if first class has no seats and second has
        ask user if he/she wants to have a seat in the second class
        if no, display …
Violet_82 89 Posting Whiz in Training

HI all, I am a bit confused about right justifying and formatting strings and numbers in general, and I was wondering if somebody can clarify this for me please. Ok, so let's take an example:

// Fig. 7.2: InitArray.java
// Initializing the elements of an array to default values of zero.

public class InitArray 
{
   public static void main( String[] args )
   {
      int[] array; // declare array named array

      array = new int[ 10 ]; // create the array object

      System.out.printf( "%s%8s\n", "Index", "Value" ); // column headings

      // output each array element's value 
      for ( int counter = 0; counter < array.length; counter++ )
         System.out.printf( "%5d%8d\n", counter, array[ counter ] );
   } // end main
} // end class InitArray

Ok, so the first printf System.out.printf( "%s%8s\n", "Index", "Value" ); // column headings prints off the string Index and the string Value with a field width of 8, meaning the the first character will be in 8th position (if you're ought to count the position), so the string index has 5 characters so the "V" of value will be positioned 3 characters after "Index":
Index Value
The second System.out.printf( "%5d%8d\n", counter, array[ counter ] );, on a separate line will start printing on the 5th character so the indexes are just below the 5th character which is the "x":

Index
    0    

The int instead has a field width of 8 charachters and will start printing at the 5+8th position, so 8 positions after …

Violet_82 89 Posting Whiz in Training

Allowing threads on pirated software could potentially put Daniweb in a sticky legal position, so the appropriate response is to strongly suggest acquiring a legitimate copy of the software regardless of the problem

I can't disagree with that, in that being Daniweb a public forum of course we should encourage people to do the right thing nad not intalling pirated software, then everybody is free to do what they want, as long as they don't come here and openly say they support piracy. That said, I still believe that there are people there who could install a pirated copy of an os without knowing (an example: somebody has a problem and asks a friend to fix his computer and the 'friend' format his HD and install a fake copy of windows: now, who's fault is that?). So personally, although as said I can't disagree with deceptikon, I think we might be firm and helpful at the same time.

Violet_82 89 Posting Whiz in Training

We dont know if the user installed it knowingly

True, we don't, but I guess we could give him the benefit of doubt, many people don't know what they're doing with their machines, and I think they shouldn't be penalised becasue of their ignorance.We've done what we should have which is, telling him to get rid of the pirated software and install a genuine copy and he doesn't seem one of those that goes on about supporting piracy, getting a pirate copy of this and that. I think it is safe to assume that the issue he's reporting doesn't have anything to do with his xp being pirated or not. That's just my opinion thought : - )

Violet_82 89 Posting Whiz in Training

Chaps, I wonder if you can give me a hand with this. Here's the brief:
"Create a program that draws 10 random filled shapes in random colors, position and sizes. Method paintcomponent should contain a loop that iterates 10 times. In each iteration, the loop should determine whether to draw a filled rectangle or an oval, create a random color and choose coordinates and dimension at random. The coordinates should be chosen based on the panel's width and height. Lenghts of sides should be limited to half the width or height of the window. "
Right, so I managed to do that, code's here:

//ShapesTest.java
import javax.swing.JFrame;
public class ShapesTest{    
    public static void main( String[] args){

            Shapes panel = new Shapes();
            JFrame application = new JFrame();

            application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            application.add( panel );
            application.setSize( 600, 600 );
            application.setVisible( true );
        }
    }

AND:

/*
p263 draw 10 random filled shapes in random colours, positions and sides
*/
//Shapes.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
public class Shapes extends JPanel{

    private static final Random randomShape = new Random(); 

    public void paintComponent( Graphics g ){
        super.paintComponent( g );
        int width = getWidth();
        int height = getHeight();
        int shape;//holding the shape
        int colour;//holding the colour
        int x;//holding x coordinate
        int y;//holding y coordinate
        int shapeWidth;
        int shapeHeight;

        for( int i = 0; i < 10; i++ ){
            //determine the coordinates and size of shapes to draw
            shape = decideShape();          
            colour = decideColour();

            x = decideCoordinates( width ); …
Violet_82 89 Posting Whiz in Training

I agree, the user is not asking for advice about pirated software, he's just got an issue with his screen - as already mentioned he must have used the key combination to turn the screen upside down. He clearly doesn't know what he's talking about, it's irrelevant whether his version of xp is pirated or not (but I think everybody in this forum appreciate the advice given to unistall a pirated copy and install a genuine one).

Violet_82 89 Posting Whiz in Training

thanks all for the replies. bguild, I tried what you suggested and yes problem solved. SO basically by using 10%% rise are we somehow escaping the %? Shouldn't have it been something like /%? Just so I understand exactly what's going on
thanks

Violet_82 89 Posting Whiz in Training

I have now pritaeas, I have just tried a .gif and as I suspected it made no difference. The problem is in the css, IE7 and 8 do't seem to like the fallback, so there must be, I am sure, another way to make ie7 and 8 to behave, ie, to get the background image to display.
thanks

Violet_82 89 Posting Whiz in Training

no I was hoping to keep it in the css to be honest, that's why I didn't use jquery : - )

Violet_82 89 Posting Whiz in Training

Hi there, I need to buy a new netbook for my sister. She isn't IT so I don't need a super expensive and powerful machine, she will just use it for word processing and browse the internet.
Does anybody have any suggestion at all? I myself have a samsung nc10 netbook with win xp and to be honest I found it quite good, so size-wise I guess it will have to be the same as the nc10.
I wanted to get her a Dell but I seem to understand that Dell doesn't produce netbooks anymore (I really wanted to get her the dell duo).
Any advice's much appreciated
thanks

Violet_82 89 Posting Whiz in Training

ahhh! I have found the mistake. I have been through the code many times but I couldn't see where the problem was.

this line var next_image = ($("#main_picture").next().length > 0) ? $("#main_picture .active").next() : $("#main_picture img:first"); should have been var next_image = ($("#main_picture .active").next().length > 0) ? $("#main_picture .active").next() : $("#main_picture img:first"); I somehow skipped the .active class.

Violet_82 89 Posting Whiz in Training

thanks guys :)