Violet_82 89 Posting Whiz in Training

Hi all, I was wondering if anybody can enlighten me on when it is best to separate javascript code in different script. Let me give you a practical example.
I have a script that I would like to run everytime the page is resized, so I am thinking to use the onresize event. But I also have some code that I will need to run when the DOM is ready, so I will wrap it inside a $(document).ready(function(){...});
I believe the script that is run onresize doesn't need to be inside a document ready, so is it worth splitting the 2 scripts into 2 separate files?
From here, in general, is it fair to say that the portion of a script that doesn't need to be inside a document ready should be in its own file and the same for the portion that needs to be inside a document ready (even if the one script could potentially call a function in the other file)?
thanks

Violet_82 89 Posting Whiz in Training

Hi Troy III, thanks for that, but I need to find a way to apply each of those classes at a specific time, that's why I was using the height of the element. If I use the code above, how would I determine when to add one class or the other at the right time?

After thinking a little bit about it, I made some progress: I have scrapped the height idea and used instead the toggleClass() method, like so:

function ROundCorners(){
    var keyElementHeight;
    var $key = $(".key");
    var chevronClass = $(".key .headerArea > a").attr('class');
    console.log("class name is " + chevronClass);
    keyElementHeight = $key.find("#keyElement").height();
    $key.find(".headerArea").toggleClass("NoRoundC RoundC");

Now, that works in that when the page loads the content is collapsed and the corners are round as they should be; when the content slides down the corners become square, which is great; but when I slid the content up again the corners turn round again a little too early, but I am getting there, so perhaps a way to delay the toggle class a little? There doesn't seem to be anything on the jquery API about delaying a toggleClass().

Violet_82 89 Posting Whiz in Training

Chaps, I wonder if you can help me with this problem please. In a nutshell I am trying to remove/add round corners around a container on the fly. The reason is that I have a div with some content that slides down and when the content is visible I want the header to have square corners, when it slides back up it should have
round corners. So that you understand, here's a link that demonstrate the issue: http://antobbo.webspace.virginmedia.com/bootstrap/bootstrapTemplate.html
Resize the window till you get to a size smaller than 768px (like the screenshot attached)
b491d73ef20eec0f0a9bfcb9a6792266
and you will see the "Key div" to be at the top of the page (you need to refresh the page with ctrl f5 when you have resized enough).
Now, click on the chevron and you will see some more content sliding down. You will noticed that the corners of the green container are still round, and they shoud instead be square.
Slide the content back up again and the corners will go square instead (they should now be round)
Ok, if it is clear let's move on to the code.
I am using bootstrap for the functionality but I have created a script that handles the corners, well it's supposed to do it at least, function ROundCorners() that gets called by
other code. Here's the complete script:

var displayKey = function(passedObject){
         $(passedObject).toggleClass('icon-chevron-up icon-chevron-down');      
        ROundCorners();
    }   

function ROundCorners(){
    var keyElementHeight; …
Violet_82 89 Posting Whiz in Training

Ok I see, well that's clear now, at least in theory, will see if I can apply that in practice : -)!
Thanks for your help, and yes now I can clearly see the distinction between the throws clause and the throw clause, sorry for the confusion.
thanks

Violet_82 89 Posting Whiz in Training

That's right JorgeM, mainly validation. Thanks

Violet_82 89 Posting Whiz in Training

Chaps, I have a question about nesting elements. I am using bootstrap for a project I am working on, and for whoever didn't know that - I am one of those - in bootstrap buttons are display:inline-block;
Now, I have this situation at the moment:
<p><button>My button</button> This button means X</p>
Is it acceptable to have the button before the text of the paragraph? Personally I think so, because p is a block element and button regardless of the value of its display property can be inside p, but I thought I'd double check.
Any objection?

Violet_82 89 Posting Whiz in Training

thanks, yes sorry I meant "unchecked exception" and not "method". When I say the "throw clause" I mean something like

public int intDivide(int a, int b) throws ArithmeticException {
  return a / b;
}

but I appreciate that there might be some confusion with the terminology from my part, sorry for that.
When I wondered whether nextInt() could have a throw (clause?) I did so only so that I could have the whole exception thing clear in my head, and be able to say something like "Oh ok, so nextInt() can't have a throw clause the same way as the intDivide() method can". But I seem to understand that this is in the method signature (providing it is not a custom defined one).

Violet_82 89 Posting Whiz in Training

ah ok, sorry crunkie, I didn't mean to patronise or anything. I suppose this shows the very low level of experience I have with html emails!

Violet_82 89 Posting Whiz in Training

Hi all, thanks for your explanations. @~s.o.s~: yes I knew already about the differentce between checked and unchecked (I read about yesterday funnily enough in my book and in the link provided by iamthwee : - )).

The only difference is that the second method explicitly mentions/states/informs the method consumer/user that intDivide can throw an exception.Because ArithmeticException is an uncheked exception.

Yes this is really good to know and clears things up quite a bit already.
Back to nextInt(): I had a look at the link you have provided.
So I appreciate the nextInt() can throw 3 different exceptions and I infer that because of that (and also bearing in mind that it is an unchecked method) we don't need to use an explicit throw clause?. I wonder though, what would happen if we add a throw clause to the nextInt() even if it already throws an exception? Would it work the same way as for the intDivide() method in your code or will it produce an error?

Violet_82 89 Posting Whiz in Training

thanks iamthwee, I have read that with interest. So if I understand correctly the throw clause is used when it is a method that throws an exception (in the code posted only the quotient method has a throw clause), but then again, nextInt() is a method too and it doesn't have a throw clause: is that because it is inside a try block? Also my understanding was that to catch an exception, it had to be thrown by something, hence the throw clause, but again, as said before not everything seems to be having this throw clause...so although your link provided some interesting insights I am still a bit confused...

Violet_82 89 Posting Whiz in Training

Hi,
the gap is there because both the td and the image have a height:

<td width="600" height="11" border="0" style="padding:0px;" colspan="2">
<img width="600" height="11" style="vertical-align:top;" src="xxxxx">
</td>

Now, this tr

<tr>
<td width="600" height="11" border="0" style="padding:0px;" colspan="2">
<img width="600" height="11" style="vertical-align:top;" src="xxxxx">
</td>
</tr>

to me doesn't look like is doing anything in there, and if that is the case I would remove it completely from your html, resulting in the gap to disappear. Alternativey you could reduce both the height to 0.

Now, let's get to the most important part. Is there a reason why you are using tables? Tables should be used only for tabular data and the info on the page I am afraid it isn't tabular data, so it shouldn't be in the table. Clearly the table is used for layout in this instance. I suggest you review your code and use a different approach (using divs is much better and clearer) unless of course there is a specific reason why you have to use tables (for example it is somebody else's code and you can't change it). Also, I hope your inline styles are used just for demonstration purposes because really they belong to a css file.
Hope this helps.

Violet_82 89 Posting Whiz in Training

the default value for display is block. So you just do display:block;.

Violet_82 89 Posting Whiz in Training

Chaps, today I was reading about exception handling and although the book explains them in sufficient details there is something that I really struggle to understand. Ok, here's the example they analyze:

// Fig. 11.2: DivideByZeroWithExceptionHandling.java
// Handling ArithmeticExceptions and InputMismatchExceptions.
import java.util.InputMismatchException;
import java.util.Scanner;

public class DivideByZeroWithExceptionHandling
{
   // demonstrates throwing an exception when a divide-by-zero occurs
   public static int quotient( int numerator, int denominator )
      throws ArithmeticException
   {
      return numerator / denominator; // possible division by zero
   } // end method quotient

   public static void main( String[] args )
   {
      Scanner scanner = new Scanner( System.in ); // scanner for input
      boolean continueLoop = true; // determines if more input is needed

      do
      {
         try // read two numbers and calculate quotient
         {
            System.out.print( "Please enter an integer numerator: " );
            int numerator = scanner.nextInt();
            System.out.print( "Please enter an integer denominator: " );
            int denominator = scanner.nextInt();

            int result = quotient( numerator, denominator );
            System.out.printf( "\nResult: %d / %d = %d\n", numerator,
               denominator, result );
            continueLoop = false; // input successful; end looping
         } // end try
         catch ( InputMismatchException inputMismatchException )
         {
            System.err.printf( "\nException: %s\n",
               inputMismatchException );
            scanner.nextLine(); // discard input so user can try again
            System.out.println(
               "You must enter integers. Please try again.\n" );
         } // end catch
         catch ( ArithmeticException arithmeticException )
         {
            System.err.printf( "\nException: %s\n", arithmeticException );
            System.out.println(
               "Zero is an invalid denominator. Please try again.\n" );
         } // end catch
      } while ( continueLoop ); // end do...while
   } // end main …
Violet_82 89 Posting Whiz in Training

ahhh, yes, sorry I have been thick as usual! It makes sense now, I have created a currentObject variable and I wasn't even using!
Ok works now, I have changed the for loop as follow (I am also getting the class name to identify which object I am talking about):

for( CarbonFootprint currentObject : categories ){
            System.out.printf("\n%s: %s \n%s %s: %.2f\n",
                "Details for ", currentObject.getClass().getName(),
                currentObject.toString(),
                "Carbon footprint is ", currentObject.getCarbonFootprint());
        }//end for loop

thanks for your help

Violet_82 89 Posting Whiz in Training

Oh i see, I think this is the first time I came across this sort of problem (can't quite understand why I haven't come across this before in any other program!). On reflection thought, it makes sense. So effectively, in my code only objects of type CarbonFootprint have the getCarbonFootprint() method because it has been declare inside the interface CarbonFootprint. That said I don't understand what difference it makes if I get an object from the list and use it to call the method (the object still doesn't have that particular method assigned to it unless the get() does some magic! ).
If I amend my code to be the below (haven't compiled yet)

        categories.add( new Bike( 200.00 ));
        categories.add( new Building( 4000.52 ));
        categories.add( new Car( 5845.25, 20.5 ));
        categories.get( 0 ).getCarbonFootprint();
        categories.get( 1 ).getCarbonFootprint();
        categories.get( 2 ).getCarbonFootprint();
        System.out.println(" Data of each object:\n ");

        for( CarbonFootprint currentObject : categories ){
            System.out.printf("%s \n%s: %.2f\n",
                categories.toString(),
                "Carbon footprint is ", categories.getCarbonFootprint());
        }//end for loop     
    }//end of main

is it necessary to call categories.getCarbonFootprint() so many times prior to the call inside the for loop?
thanks

Violet_82 89 Posting Whiz in Training

oh I see, thanks for that JamesCherrill. I sort of knew that those methods existed but I thought I could also use the normal array notation, sorry. It crossed my mind to check the API but I must admit that I am a bit reluctant to do so because I always get confused when I do it, there is so much information there and I never know what I look for.
So in the above suggestion you are using this method:

add(E e)
Appends the specified element to the end of this list.

I have made the changes as you suggested to have this

ArrayList< CarbonFootprint > categories = new ArrayList< CarbonFootprint >();//creates array of objects of type CarbonFootprint
        /* categories[0] = new Bike( 200.00 );
        categories[1] = new Building( 4000.52 );
        categories[2] = new Car( 5845.25, 20.5 ); */
        categories.add( new Bike( 200.00 ));
        categories.add( new Building( 4000.52 ));
        categories.add( new Car( 5845.25, 20.5 ));
        System.out.println(" Data of each object:\n ");

I now have another error, a "cannot find symbol". Obviously I googled it, trying to understand what this is about but I am still not sure sorry:

antobbo@antobbo-xps17-ubuntu:~/Documents/dell xps/My documents/java/tests/carboFootprint$ javac *.java
CarbonFootprintInterfaceTest.java:19: error: cannot find symbol
                "Carbon footprint is ", categories.getCarbonFootprint());
                                                  ^
  symbol:   method getCarbonFootprint()
  location: variable categories of type ArrayList<CarbonFootprint>
1 error

Completely blank, I have no idea. The variable categories is of type arrayList, but it calls a double function, so it should return a double value...

Violet_82 89 Posting Whiz in Training

good job I have left it open...I am having some issues with the ArrayList<t>. This is all my code broken down in classes:

INterface:

/*CarbonFootprint interface. File CarbonFootprint.java*/
public interface CarbonFootprint{
    double getCarbonFootprint();//calculates the carbon footprint
}//end of interface

BIke:

/*Bike.java: Bike class*/
public class Bike implements CarbonFootprint{
    private double yearlyMiles;
    private final int caloriesPerMile = 34;

    //constructor
    public Bike( double miles ){
        yearlyMiles = miles;
    }//end of constructor

    public double getYearlyMiles(){
        return yearlyMiles;
    }

    public void setYearlyMiles( double miles ){
        yearlyMiles = miles;
    }

    @Override
    public String toString(){
        return String.format("%s: %.2f",
            "Yearly miles are ", getYearlyMiles() );
    }

    @Override
    public double getCarbonFootprint(){
        return yearlyMiles * caloriesPerMile;
    }

}//endnof Bike class

Building:

/*Building.java: Building class*/
public class Building implements CarbonFootprint{

    private double averageMonthlyKwh;
    private final int months = 12;
    //private double carbonFootprint;

    //constructor
    public Building( double monthlyConsumption ){
        averageMonthlyKwh = monthlyConsumption;
    }//end of constructor

    public void setAverageMonthlyKwh( double monthlyConsumption ){
        averageMonthlyKwh = monthlyConsumption;
    }

    public double getAverageMonthlyKwh(){
        return averageMonthlyKwh;
    }

    @Override 
    public String toString(){
        return String.format("%s: %.2f\n", 
        "the monthly consumption is ", getAverageMonthlyKwh() );
    }

    @Override
    public double getCarbonFootprint(){
        return getAverageMonthlyKwh() * months;
    }

}//end of Building class

Car:

/*Car.java: Car class*/
public class Car implements CarbonFootprint{
    private double averageYearlyMiles;
    private double averageMPG;
    private final int kgCO2PerMile = 9;

    //constructor
    public Car( double miles, double MPG ){
        averageYearlyMiles = miles;
        averageMPG = MPG;
    }//end of constructor

    public void setAverageYearlyMiles( double miles ){
        averageYearlyMiles = miles;
    }

    public void setAverageMPG( double MPG ){
        averageMPG …
Violet_82 89 Posting Whiz in Training

JamesCherrill, it would be a really really good idea but unfortunately I only have the tic tac toe and judging from a quick look at my computer I don't think I have developed any other game in java unfortunately. Also if it wasn't for the fact that I have to crack on with the theory I would almost be tempted to attempt one or two more games, but I am quite behind, so I tink I will pass on this, but I do appreciate the great idea!
Also you're quite right in saying that the above exercise is a bit too simple, but - believe it or not - it is the most difficult for the section I am reading : - )! I will give it a go, I suppose no programming exercise is a waste of time.
I suppose that, since the 3 classes are that simple I won't bother thinking about any possible method other than the one specified in the exercise like Lucaci Andrew suggested, and develop with what I have. I will leave the thread open in case I get stuck

Violet_82 89 Posting Whiz in Training

Chaps, I have just read about java interfaces and there is a nice exercise in my book that I would like to attempt, so I was wondering if you could help me to identify the best way to go about it. Here's the exercise:
"Create 3 small classes unrelated by inheritance - classes Building, Car and Bicycle. Give each class some unique appropriate attributes and behaviours that it doesn't have in common with other classes. Write an interface CarbonFootprint with a getCarbonFootprint method. Have each of your classes implement that interface so that its getCarbonFootprint method calculates an appropriate carbon foorptint for that class (check out a few sites that explains how to calculate carbon footprint).
Write an application that creates objects oh each of the 3 classes, places references to those objects in ArrayLists<CarbonFootprint>, then iterates through the ArrayLists, polymorphycally invoking each object's getCarbonFootprint method. For each object print some identifying information and the object's carbon footprint".

Now, first of all, let me say that I don't really care about the accuracy of the carbon footprint calculation, because I am not going to build an application that somebody will actually use (there are plenty of online calculators for that), this is just an exercise aimed at helping me to understand interfaces a bit more and the usage of ArrayLists<T> which I have never used.

I had a look at how the footprint is calculated and these are the formulas I was thinking to use:
For a …

Violet_82 89 Posting Whiz in Training

ok I see, how about more than one submit button with a different name attribute? would that be enough to somehow "differentiate" them?

Violet_82 89 Posting Whiz in Training

pritaeas, I think I might have made a mistake in the way I have formulated the question. It didn't occur to me (yes I must have forgotten!) that buttons tag can have a type="button" which in a way it solves the problem. So really my question should have been: can I have more than 1 submit button inside a form tag? From what I can see, yes I can as long as they have a different name attribute. SOrry for the confusion.

Violet_82 89 Posting Whiz in Training

Hi guys, I was wondering whether it is alwasy true that a button needs to be inside a form tag? Is that necessary all the time?

The W3C say that The FORM element acts as a container for controls

so kind of yes really, but I 'd like to see if anybody has a different opinion. The thing is, I am working on a simple page at th moment which has 3 buttons, each of them doing a different thing: the first button validates something online; the second validates something offlice; the third cancels the action. So ideally each of them should be inside a separate form tag don't you think? To save me the hassle of having 3 form tags I was thinking not to have it at all, so just buttons inside a container, no form tag involved, but I am not sure that is a good idea

Violet_82 89 Posting Whiz in Training

Hi Dani, I seem to be experiencing problems just with .java files

Violet_82 89 Posting Whiz in Training

No worries, glad it worked.

Violet_82 89 Posting Whiz in Training

To start with, I'd say that rather than relying on the width of the label to position the input, you should remove that width:8em and give the input a margin-left. The input is a block element so you can safely have a margin applied to it. I am using linux at the moment so I can't test in IE, but try that
I should have said: add a class to the input so you can target it easily or do input[type=checkbox]{margin-left:20px;}

Violet_82 89 Posting Whiz in Training

no worries, I didn't mean to sound annoying or anything, at the end of the day as stultuske pointed out there are other ways to do it, my point was just that it has been broken for a while and it might be good to fix since we offer the option.
Good luck with your company and job then

Violet_82 89 Posting Whiz in Training

well, not sure I can be more specific than that mate. You said you are using the grid system to create the table - at least this is my understanding - and like I said, forget about the grid system (it looks like the below)

<div class="row">
    <div class="span4"></div>
    <div class="span8"></div>
</div>

That is used to place content in the page, but it shouldn't be used to position tables on the page. Look at the table markup they have on the link I sent you:

<table>
  <caption>...</caption>
  <thead>
    <tr>
      <th>...</th>
      <th>...</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>...</td>
      <td>...</td>
    </tr>
  </tbody>
</table>

DO you see? There are no div with class of row or span, just a table. If you do that the table shouldn't break. DOes it make sense?

iamthwee commented: yup +14
Violet_82 89 Posting Whiz in Training

just wanted to add that I eventually bought the OEM battery. It was sold to me as new, so I was wondering how long should I leave it in charge for? The old usual 15-16 hrs? ALso, since I am on the subject, I have noticed something with the old battery...i notice it is swollen, not like a balloon, but I can see that the shape has slightly changed. The thing is the battery came with the phone when it was bought about 2 years ago, so it can't be due to a dodgy battery bought somewhere. What should I do, can I keep use it or is it a very bad sign?
cheers

Violet_82 89 Posting Whiz in Training

yeah sure, I mean I know about the alternatives (I ended up zipping everything), but that's not exactly the point. The problem is that - at least for me - the upload doesn't work, and if the functionality is there I think that it should be working, does it make sense? If it doesn't we might as well not have it. It seems to me to be a problem with .java files because I have managed to upload an image
thanks

Violet_82 89 Posting Whiz in Training

eh eh, ok thanks for clearing that up, hopefully I will get that in my head then! I think it was also the fomat method that I haven't come across before to confuse things. Should be ok now, thanks : - )

Violet_82 89 Posting Whiz in Training

It seems just a bit of ordinary javascript, the best way to find out how a function is called or implemented is to have a look at the code, have you done that? You cna download the html and even the script and figure it out from there. However, I would discourage you from doing what it has been done in the first link: having a cursor that looks like an angle bracket pretty much all the way through the picture seems really silly, the controllers (the angle brackets ) shoul be implemented properly and there are dozens of plug-ins available on the net that just do that, and do it in a nice way. Also, I have noticed that the cursor changes in the middle of the picture from an angle bracket to something that reminds me the windows 8 logo. How is a user supposed to know that that particular icon means "thumbnail?" I find it absurd and not accessible, so my advice is, even if it is nice, don't use it.

The second link seems more reasonable, if you click on any thumbnail you will notice that the picture opens up in a new page, so all you need there is just a bit of html. Hope this helps

Violet_82 89 Posting Whiz in Training

Ok, I can obviously see that the idea is sound - and hey I didn't mean to criticise that, surely if everybody does that there is a good reason for it - it's just that being still at the beginning of my java trip I perhaps still don't appreciate the big picture : -)!
But that toString method, I really find it bemusing at times, it's like magic in a way!
Anyway, thanks for your help as usual much appreciated!

Violet_82 89 Posting Whiz in Training

thanks JamesCherril. I appreciate that my example isn't probably the best ever, but even in general terms, having a superclass that sets some values and some methods (I have read your example) seems in a way a waste because surely all the methods and variables declared in the superclass can easily be declared in the subclasses, more so if they are declared as abstract (now, bear in mind that I am really new to this concept of declaring an abstract class/method) because the abstract methods and classes practically don't seem to be that useful.

About the toString method I have just followed an example found on my book. You say I only need to return the string not to print it, so does it mean that I don't need to use a String.format() at all? If so how do I print the values, I mean where do I put all this code:

        "%s: %f\n %s: %f\n %s: %f\n %s: %f\n %s: %f\n %s: %f\n",
        "Base of triangle is ", getBase(),
        "Height of triangle is ", getHeight(),
        "SideB of triangle is ", getSideB(),
        "SideC of triangle is", getSideC(),
        "The area is ", getArea(),
        "The perimeter is ", getPerimeter() 

Sorry I don't find the the toString() overload method the friendliest one is causing

Violet_82 89 Posting Whiz in Training

Hi pritaeas, no I am not sure it is necessary, but I was just going with what I have read in one of those links, so I thought maybe that will help. The thing is, I have posted this in the web design because personally I am fairly sure it is a CSS problem rather than a script, although this problem with the graph being displayed smaller inside a hidden element seems to be documented somewhere in one of the links. The only way around at present is not to hide the element containing the graphs, but it seems a bit lame. ANy other idea?

Violet_82 89 Posting Whiz in Training

Right, I have done the small application that calculates the area and perimeter of a triangle and a rectangle. The files with the code are attached.

Here's the output, which is what I have expected:

Rectangle information:

 Base of rectangle is : 10.000000
 Height of rectangle is : 5.000000
 The area is  50.000000
 The perimeter is : 30.000000

Triangle information:

 Base of triangle is : 10.000000
 Height of triangle is : 6.000000
 SideB of triangle is : 7.000000
 SideC of triangle is: 8.000000
 The area is : 30.000000
 The perimeter is : 25.000000
antobbo@antobbo-xps17-ubuntu:~/Documents/dell xps/My documents/java/tests/superAndSubClasses$ 

Needless to say I have a few questions:

1) the superclass, as said previously is pretty small:

/*TwoDimensionShape.java, Superclass*/
public abstract class TwoDimensionShape{

    public abstract void calculateArea();

    public abstract void calculatePerimeter();

}//end of class TwoDimensionShape

I wonder, what is the point of have those 2 methods in the TwoDimensionShape class? I appreciate that perhaps the choice of figures (rectangle and
triangle) wasn't the best ever because they don't have much in common so I suppose I could have done without the TwoDimensionShape class at all?

2)the infamous toString method. For the triangle (and the rectangle) I have used this:

@Override
    public String toString(){
        return String.format(
            "%s: %f\n %s: %f\n %s: %f\n %s: %f\n %s: %f\n %s: %f\n",
            "Base of triangle is ", getBase(),
            "Height of triangle is ", getHeight(),
            "SideB of triangle is ", getSideB(),
            "SideC of triangle is", getSideC(),
            "The area is ", getArea(),
            "The perimeter is …
Violet_82 89 Posting Whiz in Training

Chps still having big problems uploading java files onto the forum, I keep getting the below error a7770cd5e7699bf618ad96734e519ad8

Violet_82 89 Posting Whiz in Training

Oh I see tha will leave me with pretty much an empty superclass..

/*TwoDimensionShape.java, Superclass*/
public abstract class TwoDimensionShape{
    public abstract double  getArea();

    public abstract double  getPerimeter();
}//end of class TwoDimensionShape

Now, when you say that the subclasses will calculate the area and perimeter themselves in their own getArea()/getPerimeter() do I have to use the @override notation to achieve that correct?
One more thing, I take it is ok to declare all the variable in the subclasses as private?

Violet_82 89 Posting Whiz in Training

Ok so essentially my TwoDimensionShape abstract class will look like this:

/*TwoDimensionShape.java, Superclass*/
public abstract class TwoDimensionShape{

    private double area;
    private double perimeter;
    //constructor uses the empty default one because there is nothing to set    
    //getters   
    public double getArea(){
        return area;
    }

    public double getPerimeter(){
        return perimeter;
    }

    //calculates area of shape
    public abstract double calculateArea();
    public abstract double calculatePerimeter();
}//end of class TwoDimensionShape
Violet_82 89 Posting Whiz in Training

ah ok, so I should use abstract classes....ok I just read about them in my java book. Ok I will give it a go, not sure if I will implement it correctly. I will post the finished code later
thanks

Violet_82 89 Posting Whiz in Training

thanks, I will build an application that does that then.

put everything you can that is used in >1 subclass in the superclass, so you only have to do it once

I was thinking about that too: I was thinking to have the methods int he superclass - calculate the area and perimeter of the 2 shapes - but the way they are calculated is different for each shape, so how do I account for that? Also the superclass will have only 2 variables representing the 2 sides of a shape, but the triangle needs 3, so should I declare a third side in the superclass or subclass?
thanks

Violet_82 89 Posting Whiz in Training

I have started to use Bootstrap quite recently, personally I think it's just a waste of time, but anyway, I think the reason why it is breaking is because you are using the table inside the grid - if I understand correctly what you're saying. My suggestion is to get rid of the grid and follow the example here http://twitter.github.io/bootstrap/base-css.html#tables where no grid is used.

Violet_82 89 Posting Whiz in Training

Hi chaps, I am looking for a not too difficult exercise which involves superclasses and subclasses (the java book I am reading doesn't really have any good one). So I was thinking about something like this:
Create a superclass 2DimensionalShapes and 2 subclasses Rectangles and Triangles. I will then need to calculate the area and perimeter of a Rectangles object and a Triangles object.
I am thinking to have the sides declared in the superclass and perhaps the methods in the subclasses, not sure what's best. Do you guys have any suggestion at all as to whether this could be a good exercise and the best way to implement it?
thanks

Violet_82 89 Posting Whiz in Training

To be honest with you @yaragalla_mural I don't like the way you have positioned the elements in your code, there is no need to position elements relatively if you can achieve pretty much the same effect with padding for the sake of argument.
Check this code out and adjust the padding to your liking (needless to say all those styles need to go in a proper external CSS, I assume you used inline styles just for demonstration purposes):

 <!DOCTYPE html>
    <html>
        <head>   </head>
        <body>
        <div style="height:50px;background:#F75D59;border:1px solid yellow">
            <div style="font:bold 20px arial;color:white;float:left;padding-left:50px">GOOGLE 
            </div>
                <div style="float:left;padding-left:40px">
                    <input type="text";text size="50px">
                    <input type="button" title="search">
                </div>
            <div style="float:left;color:white; padding-left:150px"> mythili mydhili
            </div>
            <div style="float:right">
                <input type="button" color="#ff0000"value="1">
                <input type="button" button size="10px" value="+share"> 
                <img src="a.png"height="20px";width="20px">

            </div>

        </div>



    </body>
</html>

Forgot to mention: If you're trying to achieve some sort of responsive website, you need to rethink your strategy completely and give a percentage based width to your divs

Violet_82 89 Posting Whiz in Training

If it helps, I try not to use hr anymore, anytime I need to achieve the same effect I will just use the css border property, it is much more reliable and works pretty much all the time in every browser.
So say you have a <div class="myDiv">...</div> then just add this rule to the css .myDiv{border-bottom:1px solid black} (obviously tweak it as needed) and here's your pseudo-hr

Violet_82 89 Posting Whiz in Training

Chaps I have an interesting and odd problem. Today I had the brilliant(??) idea of using google
chart https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart#Loading
for a site I am building. It is all nice and dandy till I placed the graph inside a hidden container,
planning to add some jquery and slide the graph down when somebody clicks a link. The functionality works,
in that the graph does actually slide down but the size of it shrunk to almost half of it. Feeling completely lost after having tried to increase the width of a few of the container created by the google script, I had a
look online and found something that perhaps explains what the problem is:
http://stackoverflow.com/questions/8577366/using-hide-and-show-with-google-visualization/8600892#8600892
In essence, when the graph is places in a hidden container, it doesn't work(!!). Now they do provide some
sort of fix, but I have failed to implement it (they say to use the call the function that draws the graph as
a callback function to the one that unhides the element, if I have understood correctly.)

Here is some html code and css to describe the issue (but you can see the problem online here http://antobbo.webspace.virginmedia.com/medical/home.html if you click on 'pulse' and compare the size of that graph to the one under exercise which at the moment for demonstration purposes resides in a block container - no hiding occurs).
This is the html exerpt where you have the empty …

Violet_82 89 Posting Whiz in Training

Thanks. @rubberman, I had a look at the site you mentioned but do they deliver also abroad? I am based in Europe and the site seems to be dealing only with US.

@billy.jones.545: how do I know if my device has NFC?
thanks

Violet_82 89 Posting Whiz in Training

Hi guys, I need to buy a new battery for my Samsung galaxy GT-I9000, because the one I currently have doesn't hold charge for that long. I wonder, do you think it is safe to get one off ebay/amazon, or is it better to get a samsung's?
thanks

Violet_82 89 Posting Whiz in Training

ah ok it makes sense, thanks

Violet_82 89 Posting Whiz in Training

hi AHarrisGsy,
yes thanks all seemed to have gone well! ok if you say it's safe then I will do what you said, I don't think I will use a 2.5" for quite a while anyway. I assume I can leave the switch wherever it is even if I use a usb and/or a sd card? Unfortunately I don't know much about voltage etc etc so it is completely new stuff for me!

Violet_82 89 Posting Whiz in Training

Chaps, just bought a Hard drive docking station for my 3.5" Hard Drive.
This can be used for all sort of things, 3.5, 2.5, SD, USB etc etc, you can see it in the first picture 6d7dc6ccb7cbf1014d447a842a474237

At the bottom there is a button that has allegedly something to do with what sort of HD you use: one position if for 3.5' and one is for 2.5'. I had a look on the instruction, on youtube and some guides I have managed to download from the net but none of them mentions this at all. I left the switch as it is in the picture
6c03461a3a9c6c32b5862b04faa6dfad

and I plugged my 3.5'HD. It worked and the data seem to be opening ok, so hopefully I haven't fried anything but I wonder how true this thing with the switch it. If you wonder where I icked that up, it was from the picture that is on ebay, you can see it here if you scroll down http://www.ebay.co.uk/itm/200859352737?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
Has it got anything to do with the power supply or something? Any idea as to what I should do?
thanks