Posts

Showing posts from August, 2017

DIY java hearts

I am discovering that I am not very good at reading explicit instructions....  another reason I suck at baking sweets, and another reason I always felt bad for the kids at Hogwarts in potions class. Something new I really need to focus on, because from what I've learned so far about coding, it requires a great deal of doing things in a precise order, and in a precise way. I can do this. Give me a skillet, stove top or a steak and it's instinctual to me, implicit. Cook it until it stops bleeding. Boil it too long and it will be crap.  Make it tastes how you'd want it to taste. Never trust a skinny cook(unless they eat like a starving hyena (lucky sons-o-jackolaterns eat whatever they want and never have to pay for it)). Tell me to bake a cake from scratch, I might get a surge of anxiety. I did all right in chemistry classes... I never blew the class up doing it wrong.... But then again it's not like the experiments involved anything so volatile that this was possib

complete playable Hangman JAVA

Here is the link to the JAR download from my google drive: The random selector worked in this one.  Think I need to look up what 'seeded' means. https://drive.google.com/open?id=0B3jCoMOxti9fV05TdVU1aUlSSjQ Next up, Project 16: Crazy Eights.

working JAVA Hangman

This isn't complete. I still have to add the text file with all the different phrases for it to use.  But it is a working program. A lot of the problems I had with it were because I would skip over parts of the lesson that were redundant, or would be changed later,  and then my code would end up in the wrong places, so I had to go back through the lesson and fix all the locations. Error 1:  if you enter more then 1 letter, it adds both to the 'wrong letters' Error 2: typing more then one correct letter will fill them in. Fixed Errors with :     found = true;     index = -1; I'm going to keep trying to mess with it to find all the problems. Will add anymore I find. Fixes will be highlighted. package nellie.tobey.Hangman; import nellie.tobey.mystringmethods.MyStringMethods; import nellie.tobey.mywindow.MyWindow; public class Hangman extends MyWindow {  private String phrase;  private String clue;  private String wrongLetters;  public Hangman() {  

guess my word JAVA completed

This is the working version: I'll highlight the changes that fixed it. package nellie.tobey.wordmastermind; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Random; import nellie.tobey.mystringmethods.MyStringMethods; import nellie.tobey.mywindow.MyWindow; public class WordMastermind extends MyWindow {  private String word;  private String clue;  private static final int numberOfWords = 342;  private static final String filename = "wordMastermind.txt";  public WordMastermind() {   String words[] = new String[numberOfWords];     //this fixed random   //int rand = (int) (Math.random() * numberOfWords);   try {    BufferedReader in = new BufferedReader(new FileReader(new File(filename)));    for(int i = 0; i < numberOfWords; i++) {     words[i] = in.readLine();    }    in.close();    boolean repeat = true;    while(repeat) {     //here random now    

guess my word not working

I know I have things wrong.  It runs, but not how I want it to, first error: the first random word it picks is 'said'  every time.  That's not random. second error: It doesn't restart the game cleanly.  Things print I don't want it to. third error: It doesn't pick a new random word until the third play through. First two words are said. fourth error: It doesn't close properly when you tell it that you do not want to repeat. I'll post a corrected version when I figure it out.  Once again the cheat it the back is almost completely useless.  Learning the hard way.  Hurray. package nellie.tobey.wordmastermind; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Random; import nellie.tobey.mystringmethods.MyStringMethods; import nellie.tobey.mywindow.MyWindow; public class WordMastermind extends MyWindow {  private String word;  private

eclipse doesn't like my imports

Besides eclipse not helping me figure out what's wrong with my {},  it also doesn't like to recognize imports from java.io.   I save it, close it, close eclipse, open it all back up, and it tends to recognize them after that. Not sure if saving the workspace is changing the way the paths are running.... I can't find the reason it's doing this on google. If I figure it out, or anyone knows why, feel free to comment and let me know. There are mistakes all over that I keep having to find the hard, long way round.  I really wish Annette Godtland would have put the full completed code in the back instead of the snippets from each part of the lesson. I guess learning the hard way will teach me more, but sometimes its just really infuriating to think I've done what she told me, just to find out I did something wrong along the lines.

Empty prompt

Lesson 14.... The author has a tendency to have to write stuff half way and complete it, clean it up later in the lesson.  In the beginning of this lesson you create a new promptForYesNo(), that has it's own prewritten prompt in a while loop. The thing I find odd is that you have to give a prompt in the function call to make it run properly,  but that prompt will not be used at all.  I'll copy and paste the code and highlight what I'm talking about.  It seems like a waste somehow, but I can see how having a function to just ask to continue would be useful, but if you want to change the prompt, you have to change it in the method's while loop, and not in the class you're importing the method too.   Maybe this will be addressed later,  will update. MasterMind class method:  public WordMastermind() {   boolean repeat = true;   while(repeat) {    print("Hello!");     repeat = promptForYesNo("");   Whatever you put into the prompt will not

secret messages Java

I am on lesson 13, and I am completely missing something... her cheats in the back of the book aren't helping much because it's only pieces of the code for each set of instructions.  Some instructions have you move previously written code, or delete previously written code,  and that is not visible in the cheats. Bugger.  I'm going through the lesson and the cheats to see what the heck I missed.  The code is not changing the index position so I only get the coded message back in one letter. Hello World,  comes back as  NNNNNNNNNNN which means my else statement isn't executing either.  It should for the "_",  or anything that isn't in the alphabet. So it's finding the index, and giving a code letter,  but then just using that code letter for every space in the original message....   Arggg. I'll figure it out.  Then I'll update with where the mistake was.  This might take a bit. Found it.... I figured it out without the book.  It was

imports not recognized by eclipse

So I googled my problem and found this solution https://stackoverflow.com/questions/15992779/why-is-eclipse-not-recognizing-java-libraries Eclipse would not recognize the imports I asked for,  No real idea why, but like the person in StackOverFlow said,  I just deleted them and did the Ctrl+shift+O, and the eclipse fixer imported them... then they worked. Not sure why Eclipse had this issue, something beyond my skills, Anyhoo, if you find this issue, this fixed it for me. These are the imports I had issues with: {{ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; }}

word scramble complete

Word scrambler completed, from :  Do-It-Yourself Java Games, by Annette Godtland. I haven't come up with something I want to alter about this one. package nellie.tobey.wordscramble; import java.util.Random; import nellie.tobey.mywindow.MyWindow; public class WordScramble extends MyWindow {  public WordScramble() {   String words[] = {"ANIMALS", "ELEPHANT", "GIRAFFE",     "PENGUIN", "GORILLA", "NEWT", "LEMMMING", "RED HARRING"   };   int numberofWords = words.length;   //create a loop that scrambles all the words on the list   for(int i= numberofWords; i > 0; i--) {     String scrambled = scramble(words[i - 1]);   print(scrambled);    }}     private String scramble(String word) {      String scrambled = "";      //repeat these steps until original word is gone      while(word.length()> 0) {      //pick random letter from word      Random rand = new Random();      int length = wor

java word scramble problem

On lesson 12.3,  and after entering the code as she has it written,  the part that is supposed to remove a letter from the original word is not working.  She says it should, but it isn't.  I can't find my mistake, and have checked to make sure I have the code that I'm supposed to.... (used the cheat sheet in the back of the book to see complete code). Time to google again and see what I'm missing.  Will update when I find the issue. Found it....  I did not have the code like she said to... The blue line should be :   String firstString = word.substring(0, index); not :   String firstString = word.substring(0, index +1); Google didn't help, so I played with it, and realized I hadn't compared it to the cheat thoroughly. package nellie.tobey.wordscramble; import java.util.Random; import nellie.tobey.mywindow.MyWindow; public class WordScramble extends MyWindow {  public WordScramble() {   String word = "ANIMALS";   String scrambled = scramb

java number game fixed

Turns out I fixed my problem by putting the game loop into it's own method.  That allowed me to run the code involved in the game only if the player says they want to play.  I tried moving the variables all over the place to get them to work how I wanted them too, but in the end it was best to put all the stuff I needed into a separate method, and then have the other method run it if the player says yes.  Putting the variables into the while loop would mess it all up.  I tried doing all kinds of stuff until I decided to put it into it's own method.  If there's a better option, I'll update. Remember I'm new at this,  so I wouldn't copy any of this for an actual college class, I have no idea if it's good coding.  I just like to make stuff run at the moment, and will worry about the flowery bits later. You do not have to know how to read to speak,  you do not have to know the rules of grammar to communicate.  No one will ever know if you spell a word wrong

java number guessing game

Ok, I wanted to modify this from the lesson in the book.  Took me a while to get it to run right.  Little lesson I learned....  Maximize your code screen so that the little {} doesn't hide on you offscreen. I added code so the game will ask if you want to play again,  and as simple as that seems, it took me a while to make it all run right. After reviewing the program again, I realized that if you tell it no, after play again, or anything other then Y, y,  it will still prompt for your number guess before it shuts down. I tried putting the line (myGuess = promptForInt("Pick a number between 0 - 100"); at the beginning of the while loop, but that messed up to.   Will make another post when I figure out how to fix it. package nellie.tobey.guessmynumber; import nellie.tobey.mywindow.MyWindow; import java.util.Random; public class GuessMyNumber extends MyWindow {  public GuessMyNumber() {   print("Play?");   String s = input();   int guessCount = 1;

java eclipse calculator

finished product from lesson 8, Do-It-Yourself Java Games, by Annette Godtland. https://drive.google.com/file/d/0B3jCoMOxti9fdmlsWDMtRDdkZ1U/view?usp=sharing or package nellie.tobey.calculator; import com.godtsoft.diyjava.DIYWindow; public class Calculator extends DIYWindow {  public Calculator() {   print("Do some math?");   String s = input();   while (s.startsWith("Y")|| s.startsWith("y")) {   double a = promptForDouble("Enter a number:");   String operation = promptForString("Enter an operator: * - + / ?");   double b = promptForDouble("Enter another number:");   double c = 0;   switch(operation) {   case "+":    c = a + b;    print(a + "+" + b + "="+ c);    break;   case "*":    c = a * b;    print(a + "*" + b + "="+ c);    break;   case "/":    try {    c = a / b;    print(a + "/" + b + "="+ c);}    catch (ArithmeticExcept

more changing the variable inside the loop.

Image
Another error I encountered... I found the fix for this by reading ahead in the book.   apparently running the  private String promptForString(String prompt) {   print(prompt);   String s = input();   return s;} will make the while statement evaluate to true, no matter what input() it receives from the prompt. in order for that not to happen, instead of just running promptForString("Do some math?"); I had to assign it as the value for s. s = promptForString("Do some math?"); I'm thinking that for whatever reason,  I'll try to google it.... The ( return s), does not change the value of s in the loop. therefor we have to tell it to set s = promptForString();

changing a local variable inside a while loop

Image
So after I wrote out the first part of lesson 8,  I got curious.  Why didn't changing the variable s, inside the while loop, end the loop?   if the loop requires s to equal Y or y,   and the new s in the loop is not Y or y,  why didn't it shut the loop down?   I found very little to explain,  but it seems what the great mighty google says is that a local variable changed inside the loop will not be saved... But the program will not loop again unless I add that last bit of code highlighted,  code in which I can have the user answer yes again and have it restart.   Eclipse would not allow me to create a new String s = input(); into the loop, because it would change the local variable.  But changing s to a new input ("yes") allows the program to run again. So clearly I changed the variable for the math, then changed it back again to yes.... shouldn't the loop stop the first time s is changed to not fit the statement? Going to surf some more and

JavaScript experiment state engine class

Image
I've been working with my Chingu project a ton, and haven't posted recent experiments, so as I was working on figuring something out today, I kept in mind to share the experiment on blogger. I start off like I do the other javascript experiments, Make a folder on desktop (anyname): in anyname folder,  I make a JavaScript file, and a HTML file. (optional css file) *This one also has a small css file to just give it some shape*  Now when I want to test how my files are interacting and running,  I go to my anyname folder, double click the HTML file,  and my browser loads it up for me. Then time to Google!     * JavaScript class     * localStorage     * JavaScript State Engines     * if/else clauses You can make changes as you go, and refresh the page. One thing I did learn with this experiment, is that refresh does not change localStorage items, which is exactly what I was hoping for.  I also wanted to see how to incorporate a class mechanism for the sta

making an input BOLD

So I wrote this exercise from my book (Do-It-Yourself Java Games),  and added the 'toUpperCase' as an experiment. I was thinking when I got through this one, I would make a little Mad Libs program. I was also thinking I could make the user input   "input()"  print out Bold, or Italics when the completed story ran..... I did a lot of searching, and it seems that there is no simple way to tell the program to print out the specific string that comes into the input() bold or anything else. You can make a JLabel and format that,  it's easy to google.  But the Label needs the specific text and can't accept an input(). So I looked in the book to see if she had loaded any font changers into the JAR provided, but the only real reference to changing something the way I needed it was the name.toUpperCase(); Here's my code.  I just spent 2 hours trying to find a way to change the way the user input is printed out,  but it looks like it's something I wil

easy now

Now that Eclipse has recognized, and found the JAR files, it's easy peasy.  I'm debating deleting and reloading the whole bit and see if the same issue arises.  Then I can check each step to see where the problem was. If the problem was the Mcaffee security however, I won't be reloading that crap back on my computer, so no way to test that. I'm not against Mcaffee for people who need such a program.  Sure use it.  But in my humble opinion if uninstalling a program makes components (that without it's instillation would be fine on their own) of your computer crash, or become dysfunctional, then it is a bad program. I may be paranoid, but I think it's a malicious bug purposefully put in the program to make you think your computer can not operate properly with out it. I had a similar issue with Norton Anti-Virus a long long time ago.  After uninstalling it, a different program was left behind to constantly tell the user that the computer was going to stall a