At a quick glance, your switch
statement should look like this:
switch(HighLow)
{
case 1:
...
break;
case 2:
...
break;
default:
...
break;
}
At a quick glance, your switch
statement should look like this:
switch(HighLow)
{
case 1:
...
break;
case 2:
...
break;
default:
...
break;
}
Few questions: Are you using WinForms or WPF? What panel control are you using? Is the panel doing the layout or are you (i.e. do you specifically set the position of each textbox)? What's your code for rearranging the order/layout of the textboxes?
Show the code you need help with. We won't "help" by giving you the code.
Please show your code, and explain what the issues are before expecting any help here. We're not here to do your homework for you.
int random = (int)(Math.random() * (41) - 20 );
Note quite, reread my post. You have to cast it to an int
while the number is still positive (move a parenthesis, hint hint).
if(random >= 0) ...
if(random < 0) ...
While this does work, it is good practice to use an else
block in this case, like so:
if(random >= 0) {
...
}
else {
...
}
sumNegativeNum -= random;
This would give you a positive results (since your negating a negative number). You'd probably want to keep this negative like so:
sumNegativeNum += random;
Other then those few small things, it looks like you're on track.
It is as JamesCherrill said. I'll try to explain each of your question as best I can. To simplify, let's assume there's a class called NewGenericDemo<E>
that derives from GenericDemo<E>
. K, here we go:
In your class, E
refers to a class which dervices from GenericDemo
. When it does not have a parameter, it is equivalent to GenericDemo<GenericDemo>
, but it could also be NewGenericDemo<GenericDemo>
since that still derives from GenericDemo
(the compiler can't be sure, it's implmentation specific). So if E
is NewGenericDemo
, the compiler cannot implicitly cast GenericDemo<NewGenericDemo>
(e2
) to NewGenericDemo<GenericDemo>
(E
), regardless of generic parameters, since GenericDemo
is the super class of NewGenericDemo
.
Let's again assume E
is NewGenericDemo
. Your return type will expect that type; however, e
will be NewGenericDemo
(which is equivalent to NewGenericDemo<GenericDemo>
, so e.getE()
would return a type of GenericDemo
. Again, this can't be implicitly casted.
Since you are specifying that e2
is GenericDemo<E>
, e2.getE()
will return the type E
, which is what the return type is.
Hope that helps. Let me know if you need me to clarify. I wasn't trying to disprove in a general sense, just trying to show one case where it wouldn't work. And compilers generally can't/won't work with uncertainty.
Well you could parse the c-string with strtok.
And why would you rely on a simple C function in a managed language?
how can I put an incrasing variable (for n splitted words) instead of 'Console.WriteLine(word)'
I honestly have no idea what you're asking here. Could you elaborate?
You generally can't, but you can try the Flag Bad Post link to get the attention of the moderators. Quick thing, Visual Studio Express doesn't have an evaluation period; maybe you downloaded the trial version by mistake...? Try this link, and download Visual C# 2010 Express. The programs are split up by programming language. Also, the .xaml.cs is not generated from the .xaml file, it is different than WinForms designer. I could elaborate, but from your last post, it seems you may have figured it out.
According to the second line, its occurring in the ProjectGUI.findbuttonActionPerformed()
method at line 278 in the ProjectGUI.java file. We'd need to see your source code to help you figure out why...
Many many hair-pulling hours of Dark Souls. I got away from it for a bit, with the recent baby and another one on the way, but some new DLC is coming out today, so I'll have to make some time for it. And Battlefield 3 is a tough one to get away from.
I agree with Lucaci, but there's a couple things you need to be aware of. First, I wouldn't recommend using Math.random()
, but you should of course use what the instructor tells you to. There is one problem however. From the Java API for Math.random():
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
This means that when you mutliply the random value by 40, it will never equal 40. It could be 39.99...; however, since casting to an int
simply removes everything after the decimal, this will give you 39. So, to start we need to change it to:
int random = (int)(Math.random() * (41) + (-20) );
And let's get rid of the unnecessary parenthesis:
int random = (int)(Math.random() * 41 - 20);
This isn't the only problem though. Negative numbers cast to an int
the same way, but this also means they round in the opposite direction than a positive number. For example, 5.8 rounds to 5 and -5.8 rounds to -5, both towards 0. This becomes a problem for the number -20, since the only way you can get this value is by getting exactly -20 (definately possible, but rare), where as -19 is possible for any value greater than -20 and less than or equal to -19. This creates a problem with the distribution, because not all of the numbers have the same probability. After all of that, there …
You should create a Random
class at the beginning of the method, instead of using the Math
class. The Random
class gives you the option to generate int
s directly. nextInt(n)
returns an integer in the range 0 (inclusive) and n
(exclusive). So, in your case, you would need to use nextInt(41)
, then adjust for the range -20 through +20. You should also try and do everything in one loop (it is possible to use a seed value to achieve the same random values in mutliple loops, but is inefficient and unnecessary). Then, initialize a few variables, such as:
a) countPos
and countNeg
b) sumPos
etc.
Then use those variables after the loop to generate the required results. Give it a try, and let us know how you make out. If you run into any issues, please give an explanation of what isn't working correctly (i.e. what results you're getting vs. what results you expect).
There a question here?
Is there a question here other than doing your assignment for you? Show some effort and ask some specific questions if you want help here.
The spec tells you to use void methods for everything except for the calculation of gross pay, and they are referring to the return type. They want you to use the out and ref modifiers to "return" the value to the calling method. Check the links for more info, but I'll give you a quick explanation. In C++ terms, it is basically passing in a pointer to the object, instead of the object itself (or a pointer of a pointer, in the case of classes). They are essentially the same, in that the variable passed into the method, will take on whatever value the called method gives it, for instance:
public static void Main()
{
int n = 1;
Foo(ref n);
Console.WriteLine(n);
}
public static void Foo(ref int n)
{
n++;
}
This program will output 2. Note that any method call must explicitly use the ref
modifier. out
works similar to this; however, with out
, the method assumes the value was never instantiated. In other words, the method must assign a value before it can use it for anything. Hope this helps. Feel free to ask if you need any clarification.
You're initializing visits[]
and percentages[]
to have 39 elements. This means they will have indices of 0 through 38. Each of your for-loops iterate over the indices 0 through 39. So, 39 is going to cause an issue. Remember, the last index of a zero-based array, is the size minus one. With high-level languages, it is generally good practice to use the length in a for-loop when iterating through an entire array, instead of explicit values, like so:
int[] array = new int[40];
for(int i = 0; i < array.length; i++)
{
//do something with array[i];
}
This helps prevent a program from going outside array bounds.
Thread
s only support two types of delegates, ones with no parameters, and ones with a single object parameter. You can use structs (or classes, depending on the circumstances) to pass in multiple parameters, like so:
public struct MyParams
{
public string Name;
public int Id;
}
...
public void RunThread(object obj)
{
MyParams params = (MyParams)obj;
...
}
You could then call it like this:
Thread thread = new Thread(RunThread);
thread.Start(new MyParams("test", 1));
You can also use Anonymous Methods to do this:
public void RunThread(string name, int id)
{
...
}
And call it like this:
string name = "test";
int id = 1;
Thread thread = new Thread(delegate() { RunThread(name, id); });
thread.Start();
This uses captured variables, as discussed in the above link, under Remarks. Given that methods started by threads are generally specific to the thread, I wouldn't normally recommend the use of anonymous methods though.
Your isPrime()
method cannot be contained within the main()
method. You have to keep them separate, like this:
public class PrimeNumber
{
public static void main(String[] args)
{
...
}
public static boolean isPrime(int n)
{
...
}
}
You could then call the method, from main()
, by doing a method call like this: isPrime(n);
.
Few other things to note:
A couple of checks before if (n%2==0) return false;
would fix your method.
You shouldn't have to download it; it should be included with the .NET Framework. If you are using Visual Studio:
If you're not using VS, just Google how to do it in your IDE or with the command line. The assembly you're looking for is Microsoft.VisualBasic.dll.
Could you post some code to show what you are trying to accomplish?
And please quit bumping your posts; I can't speak for others, but I tend to read posts with 0 replies first.
The class is public, but each instance variable can have an access modifier as well; see Dim Statement and Access Levels in Visual Basic for more info. When you don't explicitly give it an access modifier, it takes on a default access level (Private
in this case); see Declaration and Contexts and Default Access Levels for more info on that. In short, you have to put Public
in front of it, like so:
Public Class Form2
Public Dim var1 As Integer
...
End Class
As a side note, Dim
becomes optional when you use most keywords in a variable declaration, like this:
Public Class Form2
Public var1 As Integer
...
End Class
Nobody is going to do your work for you. Give it a try, show us some work and ask specific questions if you run into any issues, if you want any help.
If you want to set an instance variable an any Object (including a Form), the variable itself must be public. The access level of the function it is instantiated in doesn't matter.
If it is declared in a function, then it is a local variable to that function, and inaccessible to every other function (with the exception of pass-by-reference of course).
product1.Element("productsessiondata")
returns the first child element, with the name "productsessiondata", of product1
. In the for-loop, you're iterating through each of the child elements, which is stored in product2
. So there's no need to get the child element from product2
, you want its value directly (i.e. product2.Value
).
Here... to get you started:
For Each product1 As XElement In product.Elements("productsession")
...
Next
You're inner for-loop should be referencing elements from product
, not descendants of the document, and the inner-most for-loop should be referencing elements from product1
...
You just need another For Each
loop, instead of the If
statement, to iterate through each XElement
of product.Elements("productsessiondata")
.
You could use the Card Layout for this. Basically, you add JPanel
s to a container, and call the show()
method on CardLayout
object to specify which panel to display.
You can use the DataGridView.ColumnStateChanged event, and the DataGridViewColumnStateChangedEventArgs.StateChanged property to determine if it was a visibility change.
That seems way more complex then it needs to be. You should be able to do that with one for-loop and without the dp
array. You can use a few of variables, such as count
, max_count
and max_num
. Use count
for each sequence. Once your done with a sequence (i.e. number less than the last), if count
equals max_count
, increment max_num
. Otherwise, if count
is greater than max_count
, set max_count
to count
and reset max_num
to 1. Simplify your code, and give it a try.
If we're just talking about C#/.NET, I've had a much better experience with WPF over WinForms. As long as you know what you are doing, it can be pretty easy to make some fairly complex GUI's work very well across different systems. No solution will ever be perfect though...
This isn't a free tutoring service. There are plenty of free easy online tutorials for just about any programming language.
It's shorthand for:
carry = carry / 10;
You can use it for many operators, see the Compound assignment section of this article.
Try this. Changing the system volume relies on the Windows API, which requires COM Interop, so there will be no simple way to do it (aside from finding a third-party library that provides a simplified interface, which I haven't seen). There is no way to do it directly with the standard library in the .NET Framework that I am aware of.
EDIT: Note that this may not work properly on an application built for a 64-bit system without some modifications. That can be one of the downfalls of working with unmanaged applications.
How is it any different? What's your code for exporting in a Form? And what's not working about it in a console application? You might simply be missing references...
is there some code sample to extract?
When you install UnRAR.dll, it has some code samples, including one for C#. Look for UnrarDLL\Examples\C#\
in your Program Files folder.
Did you have a question? Or did you want someone to do your homework for you?
Couple things:
Now, as for your code. I don't understand what a "sequence" is supposed to be; it looks like your putting one result into a text box. Try explaining, in more detail, what exactly you are trying to do, and what your current code is doing wrong.
You can use intptr_t
, which I believe is defined in stdint.h
. It's an integral data type that is supposed to always be able to hold a pointer. If I'm not mistaken, it is part of the C99 standard.
Were you asking a question, or protesting proper use of OO design?
If you want performance, you should use a low level language (such as C/C++). If you want to simplify the coding, you could use a managed language (such as Java, C# or VB.NET). That is not to say that a managed language wouldn't be more than sufficient. For instance, Paint.NET was written in C# (in addition to C++ for some things I believe).
can you please tell me sir where can i put the
Private Sub killchar(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub LetterOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub NumberOnly(ByVal e As System.Windows.Forms.KeyPressEventArgsim a newbie in vb.net :D thank you
I wouldn't put it anywhere if I were you; the code's incredibly buggy.
Yes, several applications do (Google Chrome, Command Prompt, etc.). You typically use the GetSystemMenu() function. It gives you a handle (HEMNU) to a copy of the default system menu, that you can modify using the menu functions listed in the link I gave you.
EDIT: By system menu, I am assuming you are talking about the menu displayed when you click on the application icon on the top-left of a window.
From WM_TIMER message in the WinAPI documentation:
The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.
EDIT: Ok, left this post open for a while, and is irrelevant now... please ignore.