•

Check out our Community Blogs

Chall

Member Since 19 Jan 2012
Offline Last Active Sep 21 2015 05:22 PM

#667386New to Android Programming? Stop in here

Posted by on 15 January 2014 - 10:22 PM

Android has an IDE, based on IntelliJ, find it here. http://developer.and...talling/studio.

• 1

#643917[SOLVED] Need Help Debugging - Calculating Hotdog Pricing

Posted by on 07 November 2012 - 09:00 PM

In your check, use wantChili.ToUpper() == "Y"

```If( wantChili.ToUpper() == "Y")
```

In case you didn't know, String.ToUpper() makes all the characters upper case, so that if I entered "y", instead of failing to be equal to "Y", if I did "y".ToUpper(), it would now be the same as "Y", so it would count as equal. You could also do ToLower(), whatever floats your boat.

You have some unneeded if statements. Just have it initialize the base price, then add an if statement for chili, and an if statement for cheese, and have both if statements appends the price of the wanted item. For example:

```const double BASIC_DOG_PRICE = 2.00;
const double CHILI_PRICE = 0.69;
const double CHEESE_PRICE = 0.49;
String wantChili, wantCheese;
double price = BASIC_DOG_PRICE;
...
if(wantChili == "Y") { price = price + CHILI_PRICE; }
if(wantCheese == "Y") { price = price + CHEESE_PRICE; }
...
```

Wow thanks it works! So in the first statement price gets the value of \$2 + 0.69 which equals \$2.69. So 2.69 is the current value of price at this point? So, If the next statement is true, then it takes \$2.69 and adds 0.49\$? I'm still confused to why we had to assign BASIC_DOG_PRICE to Price...If thats the rules of the language, then so be it. But I think there is somethings that you don't need to assign values to when you create it...

The reason I set price to BASIC_DOG_PRICE is because price is always going to be atleast the cost of a regular hotdog. You could also just initialize price with the value of a hotdog, but you can't use BASIC_DOG_PRICE because that will never change.
• 1

#643817[SOLVED] Need Help Debugging - Calculating Hotdog Pricing

Posted by on 06 November 2012 - 07:43 PM

Ok. So I change the code to this and now I get an error saying "use of unassigned local variable 'price'.

```const double BASIC_DOG_PRICE = 2.00;
const double CHILI_PRICE = 0.69;
const double CHEESE_PRICE = 0.49;
String wantChili, wantCheese;
double price;
Console.WriteLine("Basic dog: \${0}, Chili: \${1}, Cheese: \${2}", BASIC_DOG_PRICE, CHILI_PRICE, CHEESE_PRICE);
Console.Write("Y/N-Do you want chili on your dog? ");
Console.Write("Y/N-Do you want cheese on your dog? ");
if (wantChili == "Y" && wantCheese == "Y") { price = BASIC_DOG_PRICE + CHILI_PRICE + CHEESE_PRICE;}
if (wantChili == "Y" && wantCheese == "N") { price = BASIC_DOG_PRICE + CHILI_PRICE; }
if (wantChili == "N" && wantCheese == "Y") { price = BASIC_DOG_PRICE + CHEESE_PRICE; }
if (wantChili == "N" && wantCheese == "N") { price = BASIC_DOG_PRICE; }

You have some unneeded if statements. Just have it initialize the base price, then add an if statement for chili, and an if statement for cheese, and have both if statements appends the price of the wanted item. For example:
```const double BASIC_DOG_PRICE = 2.00;
const double CHILI_PRICE = 0.69;
const double CHEESE_PRICE = 0.49;
String wantChili, wantCheese;
double price = BASIC_DOG_PRICE;
...
if(wantChili == "Y") { price = price + CHILI_PRICE; }
if(wantCheese == "Y") { price = price + CHEESE_PRICE; }
...
```

• 2

#643608.h vs .cpp - When to use them?

Posted by on 04 November 2012 - 06:09 PM

I have a question related to this topic. Last time I tried including an external .h file, there was a value in the main script and a value in the .h that had the same name, and they conflicted with eachother. When you include a .h, does it literally add the code to the script before compile time?
• 1

#643600[SOLVED] Need Help Debugging - Calculating Hotdog Pricing

Posted by on 04 November 2012 - 05:48 PM

First thing first. Why are you using if statements without {} brackets? And second what is the result if you type "Y" as an answer, and "Y" as a second answer? Give us your results for all solutions.

He is probably using if statements without brackets because you can. I do it sometimes in Java too, but it isn't recommended.
Also, when you check to see if they wanted cheese/chili, it checks for an upper case "Y". I'm not very good at C#, but if the user entered a lower case "y", I don't think that it would still be the same as "Y".
Also, you never allow the user to enter no for both chili and cheese: if they didn't want chili, then the else statement that follows automatically appends the value of cheese without considering if the user actually wanted cheese. Instead of the 4 outputs:

Cheese and chili, just chili, just cheese, nothing

You only have 3:

Cheese and Chili, Just chili, just cheese
• 1

#643598.h vs .cpp - When to use them?

Posted by on 04 November 2012 - 05:40 PM

The preprocessor is part of the compiler, it merges files together when it runs into #include directives. The .h file is the code to be included. The result is something like this:

You run the compiler on your .cpp file. The preprocessor looks at the contents, and substitutes out any #include with the contents of the referenced file, as well as replacing any macros.

The resulting (temporary) file is then run through the compiler, which converts it to byte code. This is then run through the linker, which turns it into an executable file.

So the .cpp will not have any "actual" code in it, just references?
Sorry if this is a stupid question but the tutorial I watched was not helpful at all.

The .cpp is where you put the main code, the actual program. The references are things you use to help the .cpp accomplish it's goal. For example, if I had a random program that printed the contents of a string, if I were going to be using a string, I would have to include (reference) string, so that the .cpp can use it to store the value, and then print it.
• 1

#6434012 Questions

Posted by on 01 November 2012 - 07:59 PM

Last question do you type the code to compile it in a file or in a program?

Both the code to compile and run are typed into a terminal, or console. When on windows, the console can be accessed by going to Run, and typing cmd, which will pull up command prompt. Inside the command prompt/terminal/console, type the command, and hit enter.

One helpful thing about the compile command is that if you type:
```javac *.java
```
It will compile all the files inside the current directory.
• 1

#6433972 Questions

Posted by on 01 November 2012 - 07:49 PM

once making a game in java and save it as a .java do you need to make a exe to run it?

Okay, so you save the source as .java, but then you need to compile it using the command:
```javac NAME.java
```
Replace NAME with the name of the file.

This creates a .class file, which can be run with:
```java NAME
```
Replace NAME with the name of the file. No need for extension.

It will run, but you have to type that command each time. If you want to make the program more user friendly, you will need to make an executable jar file. There are tutorials in the Java section on how to do this, I believe.
• 1

#6433882 Questions

Posted by on 01 November 2012 - 07:32 PM

In Notepad what do you save the file as?

In any text editor, all Java source files will end with .java, so if your class was called Example, then it would be Example.java.

If you are saving a Javascript file, you will save it with .js extension, so if you had a Javascript called Example, it would be Example.js

• 1

#643374Is Linux used a lot in programming?

Posted by on 01 November 2012 - 04:29 PM

Here is a tutorial I found with a quick search that uses just the command line to install Wine (Same process I used).

The command:
```sudo apt-get update && sudo apt-get install wine
```

After that, if all went accordingly, you should be able to run windows executables.
• 1

#6433702 Questions

Posted by on 01 November 2012 - 04:13 PM

Javascript is more for web development, where Java is for software development. Javascript does not need a compiler, and is always open source (unless encrypted (is that even possible?)). Java does need a compiler, but is not easily readable once compiled, and is only open source if you release the source.

Java and Javascript can both be written in notepad, but it is better to use either an IDE (Integrated development environment), or a text editor that supports syntax highlighting (One of, if not the best, free one is Notepad++). An IDE is good because it allows you to set up a development environment easily, and allows you to produce code much faster and more efficiently. IDE's also offer useful utilities like code formatting, indent correction, and other things. A text editor with syntax highlighting just highlights keywords and other things, but is still useful as it allows you to read the code faster by using color to identify parts of the script faster than normal.

Any script written in a text editor must be saved with the extension .java, and then compiled using a compiler.

You can find tutorials on Java here, and you can find tutorials on Javascript here.

If you need anymore help, feel free to ask.
• 2

Posted by on 23 October 2012 - 07:37 PM

My new desktop since I got Kubuntu!

*The red ball is just that--a red ball, that I can bounce around and mess with*

View on MS Windows since getting Linux: Microsoft Windows... whats that?
• 1

#642413Need help in Minesweeper program in java.

Posted by on 19 October 2012 - 06:50 PM

row cannot be resolved to a variable
column cannot be resolved to a variable
neighborCount cannot be resolved to a variable
col cannot be resolved to a variable

Change modifiers to public, just to test.

The method setAdjacentMines(int) is undefined for the type MineSweeper.GameSquare
The method push(MineSweeper.GameSquare) is undefined for the type OurStack<MineSweeper.GameSquare>
The method isEmpty() is undefined for the type OurStack<MineSweeper.GameSquare>
The method pop() is undefined for the type OurStack<MineSweeper.GameSquare>
The method push(MineSweeper.GameSquare) is undefined for the type OurStack<MineSweeper.GameSquare>
The public type LinkedStack must be defined in its own file

To start, remove LinkedStack, and put it into it's own file, because you can never have a public class nested in another class. That might fix the other method problems.

I, personally, would just suggest removing all the nested classes, and placing them into their own files. Would make the code alot more readable.
• 2

#641602Java Game: Tic-Tac-Toe (Revised Game)

Posted by on 11 October 2012 - 04:52 PM

Today, I created a new Java tutorial based on the very popular tutorial Tic-Tac-Toe. To get to the tutorial, simply click on the link above. The game I will be sharing uses a basic AI program, and if you don't use some of those impossible to beat moves, you will find it hard to beat. Here is the game I made:

Requires Java 7 to run. If you want to play two player, run it with
```java -jar TicTacToe.jar anythinghere
```

Picture:

• 1

#641601Important Forum Information

Posted by on 11 October 2012 - 04:37 PM

Get well soon! Forums are a bit emptier without you

~Get well soon, Roger!~
• 1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download