Traevel 216 Light Poster

But you would only need the id of the image you want to change then? Not get all the id's and override all of them with the new picture.

That looks like bootstraps popover, it contains the input I take it and then attaches it to the image rows?

You can find the popover that is currently visible using jQuery and then read the image id on the row the popover belongs to.

By default the popover should be in a div like <div class="popover more classes here" so you could find the active ones by doing $('div.popover:visible').

What might work even better, considering you're already passing the input element to the readURL function, is only to get the img that precedes the input, rather than all the images.

So something like:

    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {

                $(input).prev("img.img-thumbnail")
                        .attr('src', e.target.result);

            }
            reader.readAsDataURL(input.files[0]);
        }
    }

Where $(input).prev("img.img-thumbnail") should find the thumbnail image that directly precedes the input field.

Traevel 216 Light Poster

What's the intended purpose? Are you trying to set multiple images to the same src given an input?

If so, the function I provided is a bit inefficient since it would read the same data over and over again for each img. The following would be better

function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $("img").each(function(){
                $(this).attr('src', e.target.result);
            });
        }
        reader.readAsDataURL(input.files[0]);
    }
}

I don't know what you mean by the image being overriden as I thought that was the intention.

Traevel 216 Light Poster

No I think your images will not exist yet when you try to collect them using var imgs = document.getElementsByTagName("img");. It depends on where you placed that script block in the code.

Try

function readURL(input) {
    $("img").each(function(){
        var img = this;
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                img.attr('src', e.target.result);
            }
            reader.readAsDataURL(input.files[0]);
        }
    });
}

$("#file-input").change(function() {
    readURL(this);
});

You might have to use $(img).attr('src', e.target.result); instead though. I'm not 100% sure whether it will recognize the attr() without it. I can't test it for you at the moment.

Traevel 216 Light Poster

You're already using jQuery, have a look at the selectors it provides.

You could use $(img) to get all img elements. If you only want specific images you could give them a class and select on that using $(.class) or $(img.class). You could even use something like $(img[src*='album']) that checks the src attribute of all images for the occurrence of the word album.

You could even go old school and do

var imgs = document.getElementsByTagName("img");

for (var i=0;i<imgs.length;i++){

    var id = imgs[i].id;

    // etc
}

But using the selectors is no doubt easier.

Traevel 216 Light Poster

It specifies which sides (both) of the element may not be adjacent to previous floats.

Those coffee/phone boxes are floats.

Traevel 216 Light Poster

2015-01-12--1421092540_1051x112_scrot.png

Add clear:both; to the footer's css.

We can make a website for you in a breeze!

Oh the irony.

Traevel 216 Light Poster

Yes he did. I just like his boldness in tractatus, claiming he had solved all philosophical problems. This is how it is, period, no need to waste more time on the subject. I'm not a big philosophy fan in my spare time, but that's one of the exceptions I didn't mind reading.

Traevel 216 Light Poster

If you know the environment you will be using has PHP 5.3 or greater you can leave out that custom implementation altogether.

Assuming $lastlogin['lastlogin'] is a correct Date format string you could suffice with doing something like:

$then = new DateTime($lastlogin['lastlogin']);
$now = new DateTime("now");
echo $then->diff($now)->format('%a days');

edit: you can follow this guide to get different outputs.

Traevel 216 Light Poster

if(! function_exists(date_diff) )

Basically, your date_diff function gets defined only if it doesn't yet exist. That way you'll ensure the presence of a date_diff function across different (older) PHP versions.

However, as you may have guessed, date_diff already exists within PHP since version 5.3 and probably does as well in your environment. As you can see, the existing date_diff requires at least two parameters. Your own implementation requires one (i.e. it's not solving the problem it's intended to solve, namely that of implementing a potentially missing date_diff function yourself).

If date_diff does not exist in a certain environment your version will be used and your call would be correct (with one parameter). However, if it does exist your implementation will not be used and your call is incorrect since the original function needs two parameters.

Traevel 216 Light Poster

The way you describe its usage would suggest that a reader seeing & expects something uncommon to happen in the right hand part. Whereas I always believed that seeing && would trigger that expectation.

It's a good reason to switch from default & to default && since I must admit I can't remember the last time I absolutely required that the second part would be tested, regardless of the first result.

The slight speed efficiency is something I found less important than readability. For tests where speed would begin to be a factor, in my former way of reasoning, I would have used && (and thus have warned the reader that a more resource intensive test was about to follow).

In summary, something about age, dogs and tricks.

Traevel 216 Light Poster

but I could not figure out how to test the value of the user input along with the isValid(String test) method

Why not use two? A number and a String would require different tests anyway. I would keep the scanner outside of it though, less confusing that way.

Something like:

String userinput;

// example with Strings

do{
    userinput = keyboard.nextLine();

    // do stuff here

}while(!isValidString(userinput));


// stuff inbetween


// example with numbers

do{
    userinput = keyboard.nextLine();

    // do stuff here

}while(!isValidNumber(userinput));

With validation methods something like:

private boolean isValidNumber(final String test){
    try{
        int number = Integer.parseInt(test);

        if(number < 2){

            // perhaps a printline here if you want to
            // inform the user, although a more proper way
            // would be to throw a custom exception holding
            // the error message. That way this method will
            // be even more "standalone" and could be used
            // by all sorts of classes to validate numbers
            // who can deal with the exceptions in their
            // own ways

            return false;
        }
    }catch(NumberFormatException e){

        // same thing about exceptions here

        return false;
    }

    // more tests here

    // all tests were passed so it must be valid
    return true;
}

private boolean isValidString(final String test){

    if(test == null | "".equals(test)){

        // again, same thing about exceptions

        return false;
    }

    // more tests here

    // all tests passed so it's valid
    return true;
}

In my opinion it's a good habit to get used to doing the (slightly unnatural …

Traevel 216 Light Poster

Regarding the JavaDoc, the @param and @return tags are not entirely filled with information. The convention is as follows:

/**
 * @param variableName Description that may contain multiple terms
 * @return A description that may contain multiple terms
 */

Also, it is common practice that the first sentence of the JavaDoc comment is a short sentence followed by a period.

/**
 * Short sentence that tells what this method does.
 * <p>
 * A longer description that can cover more than one
 * sentence and will provide extra information on the
 * method itself or usage of the method.
 */

Declaring the variables with comma's is possible but it doesn't help the reader who is interpretting your code. Also, when using this method to initialize mutable objects you can get unexpected behaviour as they would all refer to the same object instead of each receiving their own instance.

The bracket use is a choice. The only language I've ever heard it cause problems in is JavaScript where

bla bla {

}

would be preferred over

bla bla
{

}

But not in Java, so you can pick whichever one you like, just be consistent or it will be harder to read.

Not sure if it's your pasting in here or if it looks the same in your editor, but keep indentation consistent. So:

private void foo(){
    boolean bar = true;
    if(bar){
        // etc.
    }
}

instead of

private void …
Traevel 216 Light Poster

You could try following this tutorial if you don't want to do it from the HTML page. It requires a url though.

Traevel 216 Light Poster

Using this example I'm getting the entire page just fine, regardless of screen size.

The only thing I see happening is that dynamically sized elements (like the banner on their example page) get resized to fit the screen when a user resizes the screen, and are thus printed in their smaller size on the resulting image.

Edit: did you select the body element? It seems as if it's printing the contents of the element you select.

Traevel 216 Light Poster

Take a screenshot.

Or, use the new HTML5 canvas and a library like html2canvas.

Traevel 216 Light Poster

Are you running them after the elements have been loaded?

Traevel 216 Light Poster
// short version
$('.pcon').each(function(){
         $(this).css('background-image',$(this).css('background-image').replace('/styles/SkyBoot/imageset/','/styles/SkyBoot/imageset/black/'));
    }
);

// long version for clarity
$('.pcon').each(function(){
        var el = $(this);
        var oldBackground = el.css('background-image');
        var newBackground = oldBackground.replace('/styles/SkyBoot/imageset/','/styles/SkyBoot/imageset/black/');
        el.css('background-image',newBackground);
    }
);

However, find/replace is not the best way to deal with alternating themes. You could save a lot of hassle like this even by using a different stylesheet for each theme.

Traevel 216 Light Poster

I just can't find any helpful tutorials for writing that code.

Have you tried googling for "android proximity alert" and clicking the first result?

Traevel 216 Light Poster

But I am new be in seo so can suggest me which steps i wan't follow to improvement of site.

From your own website:

SEO & Web Marketing
Specializing in Business & Marketing Analysis, Search Engine Optimization tools, Google, Bing, Yahoo and Social Media outlets. Put your business or idea in front of YOUR clientele.
(...)
Internet marketing is technical, detailed work, but we offer what it takes to succeed.

Maybe you should hire yourself to solve it.

Traevel 216 Light Poster

@Traveal Sorry but i cant understand what you want to convey , Can you eloberate.

Just picked up where I left off yesterday, wasn't a response to something you said.

<M/> commented: Thanks :) +0
Traevel 216 Light Poster

@Traevel, i sent you a link to the page, idk if that will help

That is an interesting form layout, nice!

I took your updated code, after commenting out the mail and replacing with print (and self post again) it seems to work here, variables are correct although the second mail (as confirmation) has no variables in it except one that was wrong ($first_name instead of $name). When I run it I get the following result (fingers crossed for attachment to show up)

2014-12-28--1419773987_562x817_scrot.png

Here's the code, just uncomment the scripts and mail functions again.

  <?php 
    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $meeting_type = $_POST["meeting_type"];
    $time = $_POST["time"];
    $message = $_POST["message"];
    $to      = 'email@gmail.com';
    $subject = 'Contact Form Submission';

    $v1 = "
            <html> 
            <body> 
            <style>
                h1 {color:#000066;}
                table {border:1px solid black; background: #e3f0ff;}
            </style>
            <h1>Hello, this form has been submitted!</h1>
            <img src= 'logo.png' />
            <table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'>
                <tr style='background: #ffb300;'><td><strong>First Name:</strong> $name</td>
                <tr style='background: #fafafa;'><td><strong>Email:</strong> $email</td>
                <tr style='background: #fafafa;'><td><strong>Phone:</strong> $phone</td>
                <tr style='background: #fafafa;'><td><strong>Reason for Contact:</strong> $meeting_type</td>
                <tr style='background: #fafafa;'><td><strong>Best Time to Contact:</strong> $time </td>   
                <tr style='background: #fafafa;'><td><strong>Comments:</strong> $message</td>
            </table>   
            </body> 
            </html> ";
    $message = $v1; 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    //mail($to, $subject, $message, $headers); 
    echo "Message has been sent..."; //Page RE DIRECT 
    echo $v1;
//******************************************************************************************************************************//

    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $phone = $_POST["phone"];
    $meeting_type = $_POST["meeting_type"];
    $time = $_POST["time"];
    $message = $_POST["message"];
    $subject = 'Message Confirmed!';
    $v1 = "
            <html> …
<M/> commented: Thanks :) +0
Traevel 216 Light Poster

all my code, aside from my css is pasted above

I pasted what you had in a test file, had it post to itself and indeed got some errors. Where you have things like id="email" type="text" value="email" you need to either add name="email" or change value to name if you haven't yet. But even if you did, there are two unknown variables in there $telephone on line 24 instead of $phone and $from instead of $email on line 32.

Also, you are printing the variables after the TD's which causes them to be printed outside of the table, above as it happens.

So all these

<td><strong>First Name:</strong> </td>$name

would need changing to get them to print inside the table.

But after that it prints over here.

I only tested up until the redirect line though and deleted the mail() lines, so beyond that I don't know.

Traevel 216 Light Poster

I ran a quick test, but it seems that id and name can really be the same. If I run this test form (which posts to the same page):

    <?php 
        if(isset($_POST['name'])){
            $name = $_POST['name'];
        }else{
            $name = "unknown";
        }
        echo "My name is $name";
    ?>

    <form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
        Name: 
        <select id="name" name="name">
            <option value="aaa" selected>aaa</option>
            <option value="bbb">bbb</option>
            <option value="ccc">ccc</option>
        </select>
        <input type="submit">
    </form>

It will print My name is unknown if the variable is not set, if the user picks one of the names it will print My name is aaa (bbb, ccc).

The issets would go at the top, where you could still abort the script before sending mails and such.

Traevel 216 Light Poster

Not printing the variables, weird. Not really sure as to why, but I did however stumble on something about the risk of inserting a mail address like that while looking for similar issues. Does $v1 contain all the variable information if you printed it to screen instead of mailing? If not you could wrap the $_POST's with isset's to make sure they are all set properly. At least you'll figure out which ones aren't correctly set, if any.

if(isset($_POST['name'])){
    $name = $_POST['name'];
}else{
    echo "ruh roh"; 
}

Edit:
Perhaps it's somewhere in those long strings, an unescaped quote in a variable or something. You could rewrite it using the heredoc syntax to avoid all the quoting and escaping, if all else fails.

<M/> commented: hmm, interesting. +0
Traevel 216 Light Poster

They can have the same value, or be different, doesn't matter as long as you use the name for PHP's POST.

I read up a bit on it, and according to this post you can even store multiple checkboxes by giving them an array as a name. Like, if you wanted multiple timeslots they would all have the name time[] and you could collect them all in an array by using $times = $_POST['time'].

<M/> commented: Ahhhhh :P +10
Traevel 216 Light Poster

I think he means $meeting_type = $_POST["meeting_type"] as the 5th one that needs a semicolon at the end.

And I think you have to use the name attribute instead of the id for identifying the element. So if the name of the selection is meeting_type you would get 1, 2, 3 and so on in the $_POST['meeting_type'].

<M/> commented: Gracias +0
Traevel 216 Light Poster

Well from the query results you posted it seemed like you only needed the MoveIn and MoveOut date, what you are doing now is inserting the entire row including all other values (which could also work).

If you just want the dates stored you could do this:

while($row = mysqli_fetch_array($result)){
    $values = array($row['MoveIn'],$row['MoveOut']);
    array_push($result_array,$values);
}

Then to retrieve both dates you'd have to loop over all results and for instance use $result_array[0][0] to get MoveIn and $result_array[0][1] to get MoveOut. (of course in the loop you'd substitute the first 0 with an iterator variable like $i)

If you want to store all values from your query (for instance if you need tennant number later on) you could do

while($row = mysqli_fetch_array($result)){
    array_push($result_array,$row);
}

Then you'd do the loop, same as option one, but retrieve the date values like $result_array[0]['MoveIn'] and $result_array[0]['MoveOut']. (same as before, in the loop first 0 becomes an iterator variable)

The $arr in my first example is now the $result_array in this example.

On a sidenote, it's common practice to either go with mysqli or PDO instead of the old mysql API to connect to your database.

Traevel 216 Light Poster

You can use the DateTime::diff() function to get a DateInterval object which contains the time difference in properties.

For example:

$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);

would get you a difference object in $interval. In order to get the days you would call the intervals format function. Something like $interval->format('%d days'); to get 2 days as a result.

For the second part of getting the begin and end dates you could do something along the lines of

$arr[0] = array("2012-12-28","2013-04-13");
$arr[1] = array("2013-05-01","2014-09-30");
$arr[2] = array("2014-10-03",NULL);

$it = 0;
while($it<count($arr)){

    // if neither begin and end are NULL 
    if($arr[$it][1]!= null & $arr[$it+1][0]!=null){

        $datetime1 = new DateTime($arr[$it][1]);
        $datetime2 = new DateTime($arr[$it+1][0]);

        $diff = $datetime1->diff($datetime2);

        echo "Difference between ".$datetime1->format("Y-m-d")." and ".$datetime2->format("Y-m-d")." = " . $diff->format("%d days") . "<br/>";

    }
    $it++;
}

which will print

//Difference between 2013-04-13 and 2013-05-01 = 18 days
//Difference between 2014-09-30 and 2014-10-03 = 3 days

Note that for edge cases (i.e. begin or end is NULL or end lies before begin) the difference will not be calculated correctly so you'll want to alter this snippet to better reflect that. For instance if the end date is NULL you could substitute that with today's date.

Traevel 216 Light Poster

That's because Contains checks for an exact occurrence of the substring. I'm not very familiar with VB.NET so I'm sure there are better solutions out there than the ones I'm posting, especially length and time wise. But the problem itself could be solved in several ways (not a complete list nor in any particular order):

  • Sort both numerical strings, then compare
  • Count the numbers 0-9 in n1 and again for n2 and see if the amounts match

For non numbers as well:

  • Split both and iterate over all characters, check if a character from n1 occurs in n2, if it does remove from both arrays, if you have residual characters in either the strings do not match
  • Similarly you could take n1, iterate over each character and remove a single occurrence of that character from n2, if n2 has characters left it is not a match

By checking for edge cases beforehand you can shorten the running time of whichever method you decide to pick. Check for null and empty strings. If the strings are not the same length they can't match. If you do numeric operations have it return on a conversion error (i.e. String is not a number).

You can use these 30 String operations as a reference on how to do some of the above.

Similar reference for sorting in VB.NET.

ddanbe commented: Nice! +15
Traevel 216 Light Poster

It's working fine here. I can however reproduce that exact print by renaming the php file to html. PHP code can't be inserted into an html file, you'll have to make it a php file instead (in other words, rename it so the file ends on .php).

Keep in mind that php files need to be run on a server. An easily configurable one like XAMPP for instance.

Traevel 216 Light Poster

Check Antonio Conte's posts on here. #7 might be close to what you want as far as generating goes.

Traevel 216 Light Poster

Aside from the usage of pete, the compiling issue could just be the missing { after public class ICMA42.

Traevel 216 Light Poster

Apart from the Hide() it's working here. You're making a clone of clone though, and var target = $(".guests-tbody"); is technically a list of elements, so it will append to all the elements with that class. Not sure if clone.attr('id','style', ''); is doing what you think it's doing; it sets id to "style". You could use clone.attr({"id":"","style":""}); instead if you want id and style attributes empty for the clone.

Traevel 216 Light Poster

Well the whole purpose of Entity Framework is to stop writing data-access code, so I wouldn't do that. Basically the only queries you want to write are things like:

List<Products> cheapProducts = repository.Products.Where(p => p.Price < 50).ToList();

And not queries to get the entire dataset, that's what EF is for. I'm not familiar with such initializers myself, and as you yourself mentioned, what's the point of having it when you're hardcoding products. However, I don't think that your information at runtime is coming from those hardcoded products. The initializer is run once (not just on every start, but once entirely), it adds the hardcoded information to the database, and from that moment on it uses the database. There's a big warning somewhere in the third tutorial about making changes to the initializer and how they will probably not work after running the first time. The reason they are using it I imagine is because of the code first approach. In other words, Entity Framework creates the database based on the models. The other way around is DB first; EF creates the model based on the database.

In your ItemContext you have a DbSet<CartItem> ShoppingCartItems (a database set of cartitems). When you call the Add() method on that, you're basically telling EF to add that CartItem to your database. It doesn't do so right away, you have to call SaveChanges() on your context first, which you do at the bottom _db.SaveChanges();. However, it might never even get there because EF …

Traevel 216 Light Poster

EF is Entity Framework, and on top of that tutorial page it does say:

Code features in this tutorial: Entity Framework Code First

In the part where you create a new cart item, did the following give you problems?

Product = _db.Products.SingleOrDefault(
           p => p.ProductID == id),

Because that should add the product as a reference to the cartitem, you would then be able to refer to product price/name as cartItem.Product.Price or cartItem.Product.ProductPrice depending on whatever it's called in the class (and/or database).

The code in the tutorial is based on earlier tutorials according to this:

Earlier in this tutorial series, you added pages and code to view product data from a database.

So the code is written based on the assumption that you are getting your information from a database. In other words, it might be trying to find your new columns in a database that was created in an earlier tutorial, since you are using the context class _db. Even if the data is from dummy info, it is still trying to save the information into a database via the context. If the class CartItem you made does not match the CartItem in the database (where it's trying to store your cartitem in the cartitem(s) table) it will throw an error, since you're trying to store data it can't fit in anywhere. The product has a price and name, but cartitem does not, it only has a product.

Again, this is based on …

PsychicTide commented: Thank you for the insight! +4
Traevel 216 Light Poster

Are you using Entity Framework? It sounds like a database issue, not a code issue. Double check your names and objects. The variables in the objects need to have the same name as the database objects if you haven't remapped them.

It seems to me like it's looking for a column named ProductPrice in your database object Product. It could also be that EF renamed renamed/pluralized your tables, so that it's now named Products. EF will also create the object classes (they might not show up in your editor), so it could have connected different classes (with the same name perhaps) to your database then the ones you wrote yourself.

If you're not using Entity Framework it might be an idea to look at it.

Traevel 216 Light Poster

You could use System.out.format to achieve that result. It requires a format string and variables.

A format string is built up as follows.

String contentFormat = "%-15s %-8d %-15s %n";

In the %-15s for instance: a % indicates a new "column". The - means that writing starts from the left, the 15 means it will have a total of 15 characters in width which it will try to fill with your data, the s means that the input type will be a string. It's the same for %-8d with the difference being the d which stands for digit. The %n is a newline). The spaces (or any other characters) you put in will be printed normally. So in this case you have a "column" for strings that is 15 characters in width, then a whitespace, then an 8 character wide column for digits, another whitespace, then a 15 width string again, followed by a space, then a newline.

For the actual print command you would then use something like:

 System.out.format(contentFormat, "A", 1, "$9,00");

First part is the format string variable, the other parameters are your values (they must be in the same type and order as specified in the format string, also the total amount of variables must be the same as in the format string).

Since your title has different types of variables you could write two different formats, one for the title and one for the content. Something like:

String contentFormat = …
DawnofanewEra commented: Exactly +0
Traevel 216 Light Poster
echo round(((47.60 * 554.82) / 100), 2);

Gives me 264.09, you're rounding on two decimals so it will never be 264, but it shouldn't give you 263.7 either.

However, if you do (47.60 * 554) / 100) (and not 554.82) you will get 263.704. So my guess is that by using the direct database value (perhaps it's a string and not a float) the conversion PHP makes is off because of the comma that's probably in there. You'll have to replace the , with a . first, then for safety use floatvar($string) or (float) $string to cast it, then use it in your calculation. Also, be careful if your database numbers have comma's as a thousand separator in them (but I'm unsure if that is common when the comma is also the decimal separator). If you do have thousand separators it would be safer to keep the numbers without comma's in your database and then use number_fomat for instance to make them readable.

Traevel 216 Light Poster

You have a CartItem object with a ProductId, a ProductName, a ProductPrice ..and a Product? Could it be that you are mixing your CartItem and Product entities? That you are looking for a ProductName in CartItem when CartItem only has a reference to ProductId in Product?

What would be the purpose of a ProductName and ProductPrice in a CartItem if CartItem already contains the entire Product. Or do you get the name/price from the Product object inside the CartItem with those two methods GetName(id) and GetPrice(id)?

Traevel 216 Light Poster

There's not a lot of documentation on snacktime that I can find, but there are similar programs out there and a lot of helper methods like calculate heading/bearing of yourself and opponents are described, but I agree that you might not need the angle. The robot has no front or back so for all you care it shuffles sideways towards the snack. However, something that I know has tutorials for heading/bearing, speed, energy calculation, opponent tracking and so forth is Robocode so you might want to look there for inspiration as well.

For instance here is a discussion on point to point movement for Robocode.

And here would be an implementation of linear targeting, except you wouldn't be shooting at something but walking towards it.

If there is no opponent I can see why you would want to start with the farthest snack, but if new food items pop up you'll always end up travelling the furthest possible distance for the next snack. Unless you accidentaly bump into one I suppose. If you have the coordinates to the snack furthest away you could calculate a linear path towards those coords and adjust them based on the max length you can still travel (I'm guessing from your reply that the move() method won't adjust the coords to the max travel distance for you), then return them as new coords.

Perhaps this is of more help to you on that.

ps. Links seem to …

Traevel 216 Light Poster

Do you validate the input in setters themselves? Or in separate validation methods? If so you could do something along the lines of:

try{
    record.setName(name);
}catch(YourException e){
    //input not valid
}

for each input item, but that would not work if you want the user to be able to re-enter the information that was invalid without starting over. You could use a do/while loop on each item to keep asking for user input until it's valid though. Something like:

boolean firstNameValid = false;
do{
    System.out.println( "Please enter first name:" );
    String firstName = scanner.nextLine();
    try{
        record.setName(firstName); 
        firstNameValid = true; 
    }catch(YourException e){
        //inform user of error
    }
}while(!firstNameValid);

This is assuming your error is thrown by the setter. Since validation is there for a reason (i.e. users often give incorrect information) it might be debatable whether or not errors/exceptions are the right way to go. You could for instance have the setters return true/false when the setting has succeeded/failed, and work with that in your do/while loop.

Can't really help you with the writing error if there's no code about it. Your custom exception probably caught the original exception that was thrown and gave you that non-informative message (the original ones are there for a reason too, they tell you why and where it went wrong).

Traevel 216 Light Poster

You can validate the user input before creating the object. Store the inputs in variables, validate them as they come in (so you can warn the user and have him/her retry). Then when you have all the info you can create the Customer object and pass all the input as parameters in a constructor or separately through setters.

As far as the last line goes, not really sure what error you mean, the code is incomplete. It doesn't tell what type newFile is, is it an ObjectOutputStream? Did you initialize the variable newFile? And if so, is Customer implementing Serializable?

From the documentation:

 FileOutputStream fos = new FileOutputStream("t.tmp");
 ObjectOutputStream oos = new ObjectOutputStream(fos);

 oos.writeInt(12345);
 oos.writeObject("Today");
 oos.writeObject(new Date());

 oos.close();

ObjectOutputStream
Serializable

Traevel 216 Light Poster

Not familiar with the game, but it sounds fun. If you're not feeling at home with java perhaps try a simple solution first, like heading towards the one with the highest calories. Once that works you can implement better solutions.

I noticed on the video that whenever a food item gets eaten a new one pops up randomly. There are some things that come to mind after watching, maybe they'll be of help.

Keep track of your opponent, where he is and how fast he is going. Which food items can you reach before he could. Perhaps there are clusters of food items, those would be favorable over a lone (distant) single item. But what if it's a close one, or the last one in the cluster. Maybe plan ahead as well, how will an item affect my speed, will the move limit be hit before I reach it. If my opponent is lower in energy than I am perhaps I should follow a different strategy than when he is higher. If he's higher he's also slower, perhaps I can steal some food items away from a cluster he's heading to.

I guess you can make it as complex as you'd like, but I'd still start simple and build from there. From what I saw you need to implement a move() method that has a list of items/players with their coords and energy. I'd start by making some helper methods that you'll need often. One that calculates the distance to …

Traevel 216 Light Poster

document.getElementById('txtMenuInfo').innerHTML=txt; and <div id="textMenuInfo"></div>
are not the same element, change one or the other

t="<td>"</td>";
should not contain the middle "
t="<td></td>";

var text,x,xx,i; should be var txt,x,xx,i;
and
txt=text+ "</tr>"; should be txt=txt+ "</tr>";

for(i=o;i<x.length;i++) should be a 0 so for(i=0;i<x.length;i++)

x=xmlhttp.responseXML.documentElement.getElementsbyTagName("food");
should have a capital B in getElementsByTagName
x=xmlhttp.responseXML.documentElement.getElementsByTagName("food");

xmlhttp.open("GET",url,true); and xmlhttp.send(); both need to be placed outside of the function xmlhttp.onreadystatechange=function()

so

xmlhttp.onreadystatechange=function(){
    //bla
}
//xmlhttp.open("GET",url,true);
//xmlhttp.send();

If it's still not working then make sure you're running it from a server (localhost).

Traevel 216 Light Poster

Hi,

You are referring to a jquery-1.11.0 folder in your script tag but in the zip file you provided there is only a jquery-ui-1.11.0 folder. Using your code snippet, and the zip you provided (after removing the "- copy" part from the folder name) changing

<script type="text/javascript" src='js/jquery-1.11.0/external/jquery/jquery.js'></script>

to

<script type="text/javascript" src='js/jquery-ui-1.11.0/external/jquery/jquery.js'></script>

made your example work for me.

Traevel 216 Light Poster

Hi,

It's actually just an extension to your new queue length print. If the current line length is bigger than the current max it becomes the new max. Once all the customers are done you print it where you already are printing it; outside the loop.

Traevel 216 Light Poster

href="1hot.php"?pg= "2">'

try changing that to href="1hot.php?pg=2" or escape the quotation marks if you don't want to use POST

Traevel 216 Light Poster

Hi there,

You're on the right track, but you'll have to add a variable to the sky clause in order to receive a correct result.

sky(blue):-weather(Day,fair).

...should be written as

sky(Day,blue):-weather(Day,fair).

Then you can ask prolog for sky(X,blue). to receive all the days (X) for which the sky color is blue.

This works the same way for the birds.

birdsActive(sunday).
birdsActive(tuesday).
birdsActive(thursday).
birdsHappy(Day):-birdsActive(Day),weather(Day,fair).

By asking birdsHappy(X). you will receive all the days (X) for which the birders are happy.

Hope this helps,

Traevel

Traevel 216 Light Poster

Hi there,

I'm not really sure what you meant, but I think this is what you were looking for.

document.getElementById('banner').style.visibility="hidden";

This doesn't hide the image, but the entire div. If you'd like to hide the background image however, you could change its url to ' '.

document.getElementById('banner').style.backgroundImage="url(' ')";

Hope this helps,

Traevel

Traevel 216 Light Poster

Hi there,

I think the script you wrote is being executed before any of the elements are actually created. Perhaps modifying it like this will have a better effect.

window.onload = function(){
	for(var i=0;i<document.all.length;i++) {
		document.all[i].removeAttribute("title");
	}
}

I replaced the document.all with i by the way.

Hope this helps,

Traevel