darkagn 315 Veteran Poster Featured Poster

In C# there is the concept of namespaces, which (roughly) correlates to a package in Java, although in Java the naming convention matches the folder structure of the compiled .jar file whereas the C# namespace does not have to. Similarly, there is no hard and fast naming rule in C# class-file relationships, but most conventions follow this trend for ease of use. One big difference is the way get__ and set__ methods are written in C# - often properties are used instead. Another difference in syntax (but not really behaviour) is the way in which interfaces are implemented or base classes extended.

Your Java example might look something like this in C#:

using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Common;

namespace Example
{
  // the : indicates extends and/or implements
  public class MyFrame: Form
  {
    private string name = "C# the son of Java";

    // the : here indicates that the constructor "inherits" the base class constructor
    public MyFrame() : base()
    {
      // ...
    }

    // C# convention - methods and properties start with capital letter
    // instead of Java's camel case of lowercase first letter but capitalises second word, third word etc
    public void PrintMe(string name)
    {
      //...
    }

    private string GetName()
    {
      // although this is legal, in C# you would probably use a property (see below)
      return this.name;
    }

    // Property - outside this class use MyFrame.Name to access the name variable.
    public string Name
    {
      get
      {
        return this.name;
      } …
darkagn 315 Veteran Poster Featured Poster

I'm afraid I'm no C++ guru, but I can probably compare C# and Java:

Some similarities:
- both have system garbage collection (C++ does not - you have to allocate and deallocate memory for objects).
- both have strict compiler conditions which are checked such as array indexes, initialisation of variables before use etc (I believe that C++ only checks syntax, resulting in many run-time errors).
- both have large API's and documentation (Java - http://download.oracle.com/javase/6/docs/api/ , C# - http://msdn.microsoft.com/en-us/library/hfa3fa08.aspx).
- both can perform reflection.
- both have excellent exception handling.

Some differences:
- C# (and C++ for that matter) allows operator overloading, Java does not.
- Java has primitive types such as int, char, double etc. Although C# has a similar syntax, the "primitive types" are actually objects and behave in the same manner in terms of memory usage and referencing.
- In Java, all method parameters are called by value, that is that the values of the parameter variables are copied into method local variables. C# allows call by value by default, but can also pass a parameter by reference, allowing the properties or values of parameters to be mutated. C# also allows an "out" variable, which is a means of returning more than one value from a method.

There are more similarities and differences between the languages. C# and Java are very similar in their syntax, C++ is more like C in …

ddanbe commented: Good answer! +7
Stefano Mtangoo commented: Well explained! +6
darkagn 315 Veteran Poster Featured Poster

Instead of creating a whole new table, I would add a zone_id field (numeric FK) to your ads_months table. Adding your new table is less efficient because you need to link back through the ads_months table for a select anyway, and each insert into the ads_months table would need a second insert into the ads_months_zone table (same for updates).

darkagn 315 Veteran Poster Featured Poster

I would do one query with two joins rather than the three queries you currently have. This allows you to sort on any column from any of the three tables as needed. Something like this would work:

-- select all appropriate columns from the three tables
select p.id, p.product_id, p.colour_id, p.size_id, p.quantity, c.colour_name, s.size_name
-- from the main table
from product_size_colour_lookup p
-- joined to another table on its id
inner join colours c on p.colour_id = c.id
-- and joined to another table on its id
inner join sizes s on p.size_id = s.id
-- now set the sorting however you want
order by c.colour_name asc, s.size_name asc

You may need to modify the query to suit your needs, but my comments should explain what I have done. Please re-post if I have confused you.

Benjip commented: Fantastic, thanks for the help! +1
darkagn 315 Veteran Poster Featured Poster

stardustmeri,

Read through your lecture notes, check out that tutorial i posted a link to, have a try at writing some code, if you get stuck post some questions in the Java forum and there will be people there who can help you out. Try not to beat yourself up about it, learning is a step by step process, and JDBC is (semi)-advanced Java. I would have thought that this would definatley not be a first assignment in a beginner's Java course.

darkagn 315 Veteran Poster Featured Poster

Ok, well JDBC stands for Java DataBase Connectivity, so I'm guessing you need to write your program in java. Check out this tutorial, if you get stuck on the concepts please post your attempt and where you are struggling. Sorry but we aren't allowed to just do your assignment for you.

darkagn 315 Veteran Poster Featured Poster

The LIKE statement might prove useful.

SELECT * FROM Discriptions
WHERE Description LIKE '%paint%' or Description LIKE '%red%'

The above statement will find any description where one or both of the words paint or red appear anywhere in the string. The % is a wildcard character that represents any set of characters, another is the _ (underscore) character that is used to indicate any single character.

Example:

SELECT * FROM Discriptions
WHERE Description LIKE 'r_d'

will return any three character string it finds with r as the first character and d as the third character.

These are just suggestions, not sure if it will help but was the first thing I thought of when I read your post. Good luck :)

darkagn 315 Veteran Poster Featured Poster

Make sure that line 7 (and all lines for that matter) in your csv don't have more than 19 commas. That will give you 20 values in a csv file. This line in a csv file:

1,,2,,3

actually has 5 values, it's just that 2 of the values are null/blank.

darkagn 315 Veteran Poster Featured Poster

Hi jpavao and welcome to DaniWeb :)

It won't actually contain itself, it will contain another instance of the same class. For example, if it were a JPanel, your code would look something like this:

JPanel parentPanel = new JPanel();
JPanel childPanel = new JPanel();
parentPanel.add(childPanel); // --> NOT parentPanel.add(parentPanel);
BestJewSinceJC commented: good helpful attitude :) +4
darkagn 315 Veteran Poster Featured Poster

Here is a good tutorial on what SQL injection is, how it can be used maliciously and measures that can be taken to prevent such attacks.

darkagn 315 Veteran Poster Featured Poster

The question is what is the best way to trach the ads. Should there be a seperate months table?

One approach might be to have an ads_months table that links each advertisement to the month(s) it was run. This would require three columns, ads_months_id (numeric PK), ad_id (numeric FK), month_run (date). Then when you want to know what ads were run during january 2010, use something like the following query:

select ad_id, month(month_run), year(month_run) from ads_months
group by ad_id
having month(month_run) = 1 and year(month_run) = 2010
darkagn 315 Veteran Poster Featured Poster

SQLYog is pretty easy to use.

darkagn 315 Veteran Poster Featured Poster

The best text book I used in my Mathematics and CS degree was "Linear Algebra and its Applications" by David C Lay, Published by Addison-Wesley. We used it in three of the five mathematics courses I did (including Discrete Math), and can thoroughly recommend it. I hadn't studied anything for 10 years before I decided to go back to university, so that is probably a pretty good advertisement for this text!

darkagn 315 Veteran Poster Featured Poster

Sorry, you should use:

$airdate = strtotime($r['airdate']);
$now = strtotime("NOW");

and

$airdateFormatted = date($dateFormat, $airdate);

Which line gives the error that you mentioned?

darkagn 315 Veteran Poster Featured Poster

Ok, instead of:

$airdate = $r["airdate"];
// ...
echo "$airdate...";

I would do something like this:

$airdate = $r["airdate"];
$now = strtotime("NOW"); // timestamp of current date/time
$currentYear = date("Y", $now); // format of "Y" gives four digit year ie 2009 not 09
$yearOfDateFromDatabase = date("Y", $airdate); // the year of the record
if($yearOfDateFromDatabase == $currentYear)
  $dateFormat = "d F"; // dateFormat = 12 December
else
  $dateFormat = "d F Y"; // dateFormat = 01 January 2010
// now use $dateFormat when displaying the date!
$airdateFormatted = date($dateFormat, strtotime($airdate));
// ...
echo "$airdateFormatted...";

EDIT: Personally I would put the bulk of the above code into a function but that's up to you.

darkagn 315 Veteran Poster Featured Poster

Hi saher_omer,

In future, please start a new thread if your question is not directly related to the original poster's problems.

But to answer your question, there are many examples on the net of an SQL select statement. Google will provide millions of them. Here is a good one.

darkagn 315 Veteran Poster Featured Poster

The main method in a java application has the following signature:

public static void main(String[] args)

If you are a beginner I would suggest starting with something a bit simpler than a JButton's click method. But the theory behind it is to add an ActionListener to your button. This listener has an actionPerformed method that is called when the action is taken on the component, in this case pressing the button. Inside that method you can call another method or do whatever you like, such as JTextField.setText...

darkagn 315 Veteran Poster Featured Poster

You type java Hi , there is no need to specify the ".class" to run your program. Also, you will need a main method in that class to run the program.

darkagn 315 Veteran Poster Featured Poster

I need to make ten selections. One of all the datetimes in the last 24 hours, the next one from 24 hours to 48 hours, and on back in 24 hour blocks for the last ten days. I've tried various approaches to this, but this is what I currently have:

select title, app_id, count(*) as cnt from app_instances where time between now() -1 day and now()-2 day group by title order by cnt desc

The best way I can think of is to run these queries inside a for loop, substituting out the numbers for incremental variables in PHP to result in 10 seperate selections. Does anyone know the correct syntax for this or maybe have a better way?

In PHP the strtotime and date functions might be useful to you. You can go:

for($i=0; $i<10; $i++)
{
  $startDateTime = date("Y-m-d H:i:s", strtotime("-$i days"));
  $endDateTime = date("Y-m-d H:i:s", strtotime("-{$i+1} days"));
  $query = "select title, app_id, count(*) as cnt from app_instances where time between $startDateTime and $endDateTime group by title order by cnt desc";
}

That may require some tweaking to get it spot on, it's just what I came up with on the spot.

darkagn 315 Veteran Poster Featured Poster

Hi alreem,

We can only help you if you show that you have made some sort of an attempt. Do you have an algorithm or some code that you have tried? We may be able to point you in the right direction if we can see what you are thinking...

darkagn 315 Veteran Poster Featured Poster

Try adding the following line to your script, anywhere after the line $dir = $documentroot . '/' . $username; but not inside the function:

rmdir_r($dir);

Basically, the code inside the function doesn't execute until the function is called.

aeinstein commented: nice catch and good solve Darkagn +8
darkagn 315 Veteran Poster Featured Poster

Hi erlene and welcome to DaniWeb :)

You have posted in the Game Development forum which is a forum for discussing game programming. I think you will have a better response from one of the tech forums on this site.

I will say though that there are a number of things that could be happening. I think most likely there is a problem with your video card (just a guess). Try running the game on lower quality graphics and see if this helps you.

Good luck :)

darkagn 315 Veteran Poster Featured Poster

Hi easyb and welcome to DaniWeb :)

You don't need to use Math.pow at all. Math.pow is used to find the power of a number. I wish that banks would pay interest exponentially but unfortunately... ;)

I suggest you revise your notes on iteration and for-loops. I think what you want would look something like this:

for(n=1; n<=10; n++) {
  P = P * (1+r); // a better solution would be to have r = 1.05
  System.out.println("The amount at the end of the year " + n + " is:" + P);
}
darkagn 315 Veteran Poster Featured Poster

Not sure what DaniWeb's policy is, but for other forum-type sites that I have contributed to we kept all PM's, emails, forum posts in database tables. If the owner of the message deleted it (by pressing a button for example) then we archived the message to another database table that was not accessible to the general public. This way we had a record of abusive posts, bullying etc even if the sender tried to delete it.

From a legal standpoint there are only certain things that are illegal to store. Off the top of my head I know that signatures (that is hand-written credit card authorisations) have legal implications for example. But things like emails, forum posts, blogs etc should be ok to store indefinately.

darkagn 315 Veteran Poster Featured Poster
String number = Float.toString(number);

I think what you are trying to do is convert the number n to a string yes?

What I would do is this:

String number = new Float(n).toString();

Here I create a Float object from my float primitive, then convert it to a String. You have tried to call the toString method statically and then pass the variable number instead of n.

darkagn 315 Veteran Poster Featured Poster

Hi ankiwalia and welcome to Daniweb :)

Your SQL syntax is incorrect. Instead of this:

String query="select username and password from Registeredusers";

Try this:

String query="select username, password from Registeredusers";
darkagn 315 Veteran Poster Featured Poster

So is $title the title of a single RSS feed item? If so, you can do something like:

$count = 0;
foreach($rssFeedItems as $title)
{
   if(empty($title))
      echo ++$count; // a prepend increment will add one to $count before it is used
   else
      echo $title;
}
lonestar23 commented: Great Coder! +2
darkagn 315 Veteran Poster Featured Poster

There are a few different types of SQL, but http://www.w3schools.com/sql/default.asp is a good site for general SQL knowledge. http://www.sql.org/sql-database/sql-tutorial/ is a good beginner's tutorial but it is a little slow-paced for my liking - if you have programming experience you may feel the same. SQL is not too difficult when you get started, I have mostly learned just from trial and error.

Not sure what you mean by data controls? If you are talking Silverlight am I correct in thinking you mean C# user controls to access a database?

darkagn 315 Veteran Poster Featured Poster
$send="INSERT INTO mailbox SET
   member_id='$memid',
   user_name='$$_SESSION[user_name]',
   user_id='$_SESSION[user_id]',
   message='$message',
   inbox='NEW',
   subject='$subject',
   date='$dsub' " ;
$save_result=mysql_query($save);

What is $save? I think you are trying to run the query $send?

darkagn 315 Veteran Poster Featured Poster

When you say you suck at math, how bad is it? Are we taliking about not knowing advanced calculus and algebra, or not knowing your times tables? Who are you comparing yourself to?

This site has lots of tutorials, demonstrations and explanations that might help you. I have used it often for some advanced concepts, but it starts at beginner and works through to the advanced levels of mathematics. There are many other sites out there aimed at online math learning, that's just the one I've used.

Good luck :) And remember, mathematics is actually fun when you get the hang of it (spoken like a true geek I know...)

darkagn 315 Veteran Poster Featured Poster

The easiest way to do this is to extend JPanel and override the paintComponent method. When you override the paintComponent method, you should do the following:

public void paintComponent( Graphics g )
{
  super.paintComponent( g );
  Graphics2D g2d = (Graphics2D) g;
  // use g2d.drawImage methods to paint your background image here...
}
darkagn 315 Veteran Poster Featured Poster

imagedestroy() is used to free memory assigned to an image resource stream. I haven't tried it out, but I assume it can be used to free any image resource stream created by the GD package.

By tmp folder, are you referring to file upload tmp folder? If so, open the php.ini file and search for upload_tmp_dir. This is the setting that needs to be adjusted.

EDIT: Actually I just followed my own advice and found that the tmp directory for the upload_tmp_dir in my php.ini file is set to more than one setting, so it may need to be changed in more than one place in the ini file.

OmniX commented: Thanks for the advice. +2
darkagn 315 Veteran Poster Featured Poster

I assume you want $nowdate to be a string. String concatenation in PHP uses a period character to join strings. This **should** work:

$nowdate = date('Y') . "-" . (date('Y') + 1);
PinoyDev commented: useful +1
darkagn 315 Veteran Poster Featured Poster

In order to tell what parameters you need to pass to the method, you can look at the method signature. In your Pizza class, let's look at how the setSize method is described:

public void setSize (int diameter)

Let's break this signature up into each part so that we can describe what the signature does:

  • public: This is the access identifier of the method. In this case, public, indicates that the method can be called by an instance of Pizza from anywhere.
  • void: This is the return type of the method. In this case, the method returns void, meaning that nothing is returned.
  • setSize: The name of the method. This is how we call the method.
  • int diameter: The type and name of the first parameter of the method. Other parameters could be added to a method if needed, separated by a comma, and when the method is called the parameters MUST match. In this case when calling the setSize method we must pass a single variable of type int. Inside the method it is known by the name it is given, diameter, even though we may pass it by another name, such as inches.
jasimp commented: very helpful +9
darkagn 315 Veteran Poster Featured Poster

I think in this situation you are better off explicitly joining the tables by account id. Like so:

SELECT COUNT(J.account) from JanTable J
INNER JOIN FebTable F 
ON J.account = F.account
WHERE J.AmountPaid=0 AND F.AmountPaid=0

Otherwise you will get many duplicate records.

Ezzaral commented: agreed +19
darkagn 315 Veteran Poster Featured Poster

About 50% of my job is in documentation and technical support. There are many help authoring tools out there and in general you get what you pay for. http://hat-matrix.com/ might be able to help you find one that suits your needs.

Personally I would recommend Adobe's RoboHelp (this is the tool that I use). It does all of the things you have listed and a whole lot more, but is kinda pricey. One of the best things about Adobe is their user community forums which I use frequently to help me with the use of RoboHelp. This link will give you an overview of RoboHelp and its features but it is written by Adobe and is more of a marketing brochure than a critique.

Anyways, hope this gives you a starting point.

Regards,
d

darkagn 315 Veteran Poster Featured Poster

Hi vimotaro,

Are you asking if you receive a record you want to update an existing one with the data in that received record? If so, you can do this quite easily by running a SELECT COUNT(*) statement and seeing if this returns 1. If it does, run your UPDATE statement.

If this wasn't what you were asking, please clarify your question for me and I will try to help further :)

vimotaru commented: good answer. Not solved but was my fault with the explanation. +1
darkagn 315 Veteran Poster Featured Poster

The COUNT function will return the number of rows returned by the query which is what I think you are trying to do. The COUNT function requires a column to count as a parameter, so your query will look something like this:

select COUNT(name) as number_sold
from beats
where availability = 'Sold'
and p_staffid = 1;
CodeBoy101 commented: Exactly what I needed. +0
darkagn 315 Veteran Poster Featured Poster

Yes, except that you don't have to define the code for Reptile::eat() because it is in the Animal class. If you wanted to change the way that the Reptile eats from the way that the Animal eats then you would need to redefine it. And of course you can use a call to parent::eat() like you can with any extending class if you want to extend the eat() method rather than simply overriding it.

All of this adds up to the fact that you can minimise the amount of code and simplify the code maintenance by using an abstract base class in a package of similar classes.

Venom Rush commented: Thanks, you really helped ;) +2
darkagn 315 Veteran Poster Featured Poster

Should zipCode belong to the Individual class or the IndividualArray class? I think it is a value relating to the Individual, not the list of Individuals.

darkagn 315 Veteran Poster Featured Poster

First, make sure that the SQL file has statements that read like this:

CREATE TABLE IF NOT EXISTS Example
-- table definition goes here

Then you actually need to run the mysql query by typing the following into a terminal:

mysql DB_Name < script.sql
buddylee17 commented: You solved this post. +2
darkagn 315 Veteran Poster Featured Poster

I think it may possibly be out of beta now - that post is almost 2 years old... :P

Salem commented: There is only betaware or abandonware ;) +20
Ezzaral commented: One would hope so anyway :) +11
buddylee17 commented: funny +2
darkagn 315 Veteran Poster Featured Poster

Your DB structure looks ok, except that I would probably just sort by name and remove the sort_name field. Your SQL query will look something like:

SELECT * FROM table_ads
INNER JOIN table_categories
ON table_ads.category_id = table_categories.id
WHERE table_ads.active = true
ORDER BY name

Might need a bit of tweaking to get exactly the result you're after, but should point you in the right direction.

buddylee17 commented: good example Aussie +1
darkagn 315 Veteran Poster Featured Poster

www.php.net is probably a good place to start. This site has some really good documentation and sample code. Of course, if you get stuck there is also DaniWeb :)

darkagn 315 Veteran Poster Featured Poster

You need to call Graphics2D.setStroke(Stroke) method before drawing a line. You will need to create a Stroke first - use the BasicStroke class for now. Also, don't forget to reset the stroke after you have drawn your line.

Ezzaral commented: Concise and correct. +9
darkagn 315 Veteran Poster Featured Poster

Your problem is in the first if-statement:

if ($_FILES["userfile"]["size"] = 0)

You are using an assignment here rather than the comparator == as I think you mean. In PHP though, your statement is legal, just that it will always be evaluated to false (and thus will never cause the code block following it to execute).

As for not getting the error when you upload a 2MB file, I'm not sure what is happening there, especially since 2000000 bytes < 2MB (which is 2 * 2 ^20 = 2 * 1024 * 1024). I would suggest doing the following to see exactly what is happening when you upload a file:

print_r($_FILES);
exit;

Executing this code will print the FILES array and might give you a clue as to why your code is not behaving as you would like.

Hope this has helped,
darkagn :)

antwan1986 commented: Helpful +1
darkagn 315 Veteran Poster Featured Poster

Hi Akeem Amure and welcome to Daniweb :)

A couple of things before we start - please don't shout (by using all capitals) and there is no need to ask for help as soon as possible as we always try to get back to you when we can. Also, please use code tags when posting chunks of source code as it makes it easier to read.

Ok, looking at your code there is a few things. The statement

import jav.awt.*;

automatically imports the class Graphics, so there is no need to import it explicitly. Also, you don't need to import anything starting with java.lang as this is the default package that gets imported automatically.

In answer to your question, the Graphics class has a series of methods beginning with fill, for example fillOval, which can be used to paint a shape with a filled colour. In order to outline the shape in a different colour, call the draw method after the fill method with a different colour.

Hope this helps :)
darkagn

darkagn 315 Veteran Poster Featured Poster

Rather than implementing the ActionListener in your class, it is probably better to add an ActionListener to your menu item. You can do this by

// Exit menu item
exitItem = new JMenuItem("Exit");
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,   ActionEvent.CTRL_MASK));
exitItem.addActionListener(new ActionListener() {
   public void actionEvent(Event e) {
      System.exit(0);
   }
});
fileMenu.add(exitItem);

However, if you need action listeners for every item in your GUI this code will create many classes, which may or may not be desired.

Another way of doing this would be to create your own actionListener class as an inner class and put the implentation in there, similar to your code which reads

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == exitItem)
{
System.exit(0);
}
}

but in another class. Then add that ActionListener to each of your items.

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi there santhi1986 and welcome to Daniweb :)

We have a few rules here at Daniweb that you might want to read. Probably the most important one is that we can't do your homework for you, we need to see some effort before we try to guide you. What do you think is the answer to your problem?

An unwritten rule in this forum is that we don't revive old threads to ask our questions. We prefer it if you start your own thread to ask your question even if it is related.

Anyway let us know what you've done to solve the problem and we will try to help you out :)

Cheers
darkagn

darkagn 315 Veteran Poster Featured Poster

dReg1 in the above code is an Accumulator, a register that is used to keep track of the result of the calculations. If you think about how a calculator works, you enter a number, press the operator, enter a second number (dReg2) then press equals to find the result. Then you can (if you want) press another operator and yet another number and find another result. And so on. This result is stored in a special register (called the Accumulator). The line

dReg1 = Calculation(sOperator, dReg1, dReg2);

is exactly how an accumulator works. It is possible to create a third register to store the result, but not only would this use more memory but it is not how an Accumulator works, accumulating the result in a single register.

As for your second question, those three lines of code simply print the result to the screen. If you mean what do each line do, then the first converts the result dReg1 to a Double object (as opposed to a double variable type), the second line converts it to a String, and the third sets the text of the display to that String.

Hope this has helped,
darkagn

Jishnu commented: Nice +2