Please follow me here!

Monday, December 24, 2012

Need some help for other holidays to come

Hello, guys. How have you been this past week?

I haven't been typing blogs because I was occupied with trying to find work online, playing games (mostly Archimedean Dynasty by Blue Byte Software GmbH in 1996) and have been watching relentlessly the news on the 2012 Mayan apocalypse where other people were making rumors about the day that the Mayan Long Calendar completed its thirteenth bak'tun by Friday, December 21st that the world would end. Luckily, nothing happened; even six major points about the predicted doomsday were dropped down by NASA.

Now, I have been taking a look at several surroundings for Christmas and even tried out a few levels of the Season Greetings scenario from Angry Birds Chrome, and even wanted to decorate my father's house as well as get a tree with a stand, but unfortunately, it was a failure because of lack of finances on my side for leisure and holiday purposes.

As soon as I completed my Mechanics exam on Tuesday, December 11, I immediately took some time to try to find some work online, besides what I did the weekend before, for a full-time job where I would work at least 30 hours a week and earn $300 or more. But as I took more time to find jobs, I knew I was starting to get into trouble.

I got no calls nor e-mails for interviews, mostly because either my candidacy profile does not fit all the requirements or simply all candidates who were hired must speak French, which is sadly a language that even though I was born in, I have been doing really badly, all because I let English assimilate me. Still, I shouldn't be limited to just Quebecois traditions.

Anyway, I have tried going to a few complex buildings, two malls, a few restaurants, and even a computer shop in applying through the old-fashioned way, and I haven't received any calls or e-mails for interviews. I went through numerous job openings on Emploi Quebec's Online Placement Search Engine and still don't get any requests for interviews.

Last week, I took the time checking out the online job system on oDesk.com to see if there really is job openings that I can apply and help others out; I found out that the rates are lower than what Quebec's minimal wage is, mostly because oDesk.com is designed to outsource jobs to people around the world and help them out in their local economies.

I even tried signing up on sites where online surveys are taken, and guess what? No available surveys for me! Even if I would sign up for other survey sites right now, I would be out of luck because the marketing analysis is closed until sometime in January.

And just today, I went outside to see if I can get some money by selling my kept copies of my music videos (Traffic & The River) where I had ten copies originally with me and went around the neighborhood; more than ten houses out of those I went out to see (probably 15) said they are not interested. From there, I began to feel really discouraged about how I can't really get myself more money for me to enjoy a wonderful Christmas. I want a Wii U, and the occasion I had at my mom's house on December 16 allowed me to get $230, but I still need another $200 to get the Deluxe version of the system and a first Wii U game, which would be New Super Mario Bros. Wii U.

Earlier this weekend I've managed to sell two copies of my music videos to my neighbors around the street my dad's house is on and earned $20, which means I could use that to buy some games online. But I will still feel that I am not having a really pleasant Christmas, all because one, I am suffering from lack of French, two, I did not make any money from sales of my music videos during the summer, and three, I was too absorbed with the marketing process of my videos instead of getting a job during the summer.

Now, I want to get some help from you guys on the holidays during 2013, because I really want to have a more pleasant time instead of being off holidays for too long. For now, just leave me comments and I'll get back to you soon because my time on the Internet is about to go down, so I'll see you guys later.

Saturday, December 15, 2012

JAVA Program: Coin Toss

This is a JAVA program for an automatic coin toss; you enter the number of tosses you want to make and then the program does the tosses by itself, where it also checks to see if the result of the toss is heads or tails. This is from Chapter 5 of Tony Gaddis' Starting out with JAVA, 4th Edition.

Here's the program; a series of details follows onwards.

import javax.swing.JOptionPane;
import java.util.Random;

public class Chapter5CoinToss
{
    public static void main(String[] args)
    {
        String input;
        int numberOfTosses;
       
        input =
            JOptionPane.showInputDialog("How many times do you want this virtual coin to be tossed?");
        numberOfTosses = Integer.parseInt(input);
       
        coinToss(numberOfTosses);
       
        JOptionPane.showMessageDialog(null, "Thank you and come again!");
       
    }
   
    public static void coinToss(int number)
    {
        int numberOfHeads = 0,
            numberOfTails = 0,
            currentNumber,
            currentToss = 1;
   
        Random tossMachine = new Random();
   
        while (currentToss <= number)
        {
        currentNumber = tossMachine.nextInt(1 + 1);
       
        if (currentNumber == 0)
            numberOfHeads++;
        else if (currentNumber != 0)
            numberOfTails++;
       
        currentToss++;
        }
       
        JOptionPane.showMessageDialog(null, "Out of the number of tosses you asked, there were " +
                                      numberOfHeads + " heads resulted and " + numberOfTails + " tails.");
       
    }
}


It is simply three JOptionPane windows where the first, you enter the number of tosses to execute. Then, through one of the Random class methods and a custom method named coinToss consisting of four integer variables, one Random object, a while loop, an if-else-if statement, and the JOptionPane's showMessageDialog method, the program executes the tosses and checks if the resulting toss is heads or tails.

There are no images used; it's all computer logic, in binary numbers.  All of this invisible process happens within just less than 50 lines of code.

Well, I'll see you around! 

Friday, December 14, 2012

JAVA Program: Lottery Class

Here's another JAVA Program I want to share with you guys, which is a demonstration of the Lottery class I was asked to design from my copy of Tony Gaddis' textbook.

Below is the code for the class:

import java.util.Random;

public class Lottery
{
    private int[] lotteryNumbers;
    private int matches;
   
    public Lottery()
    {
        final int maxNumber = 10;
       
        Random numberGenerator = new Random();
       
        lotteryNumbers = new int[5];
       
        for (int x = 0; x < lotteryNumbers.length; x++)
        {
            lotteryNumbers[x] = numberGenerator.nextInt(maxNumber);
        }
    }
   
    public void lotteryCheck(int[] playersNumbers)
    {
        int numberOfMatches = 0;
       
        for(int y : playersNumbers)
        {
            if (playersNumbers[y] == lotteryNumbers[y])
                numberOfMatches++;
        }
       
        matches = numberOfMatches;
    }
   
    public int getNumberOfMatches()
    {
        return matches;
    }
   
    public int[] getLotteryNumbers()
    {
        return lotteryNumbers;
    }
   
    public void noWin()
    {
        System.out.println("Sorry, you did not win the grand prize.");
    }
   
    public void grandPrizeWinner()
    {
        System.out.println("Congratulations! All of your numbers match the lottery; you win the grand prize!");
    }
}




Over here is the code that executes the class' methods:

import java.util.Scanner;

public class LotteryProgram
{
    public static void main(String[] args)
    {
        boolean safeEntry = true;
        final int arraySize = 5;
       
        int[] playerNumbers = new int[arraySize];
        int[] returnNumbers;
       
        Scanner Keyboard = new Scanner(System.in);
       
        System.out.println("This program will run a check for winners of a five-element lottery game. " +
                           "If all of your numbers matches the draw numbers, you win the big prize.");
       
        System.out.println("\nFor each element, enter a number between 0 and 9 according to your paper.\n");
       
        for (int x = 0; x < playerNumbers.length; x++)
        {
            System.out.println("Element " + (x + 1) + ":");
            playerNumbers[x] = Keyboard.nextInt();
           
            if (playerNumbers[x] < 0 || playerNumbers[x] > 9)
            {
                System.out.println("Invalid number. Please run the program again and enter a digit that is between 0 and 9.");
                x = 5;
                safeEntry = false;
            }
        }
       
        if (safeEntry)
        {
            Lottery drawNumbers = new Lottery();
           
            System.out.println("The numbers from the draw are as follows:");
            returnNumbers = drawNumbers.getLotteryNumbers();
           
            for (int p = 0; p < returnNumbers.length; p++)
            {
                System.out.print(returnNumbers[p]);
            }
           
            System.out.println();
           
            if (drawNumbers.getNumberOfMatches() == 5)
                drawNumbers.grandPrizeWinner();
            else
                drawNumbers.noWin();
        }
    }
}


Thanks for reading!

JAVA Program: Car Class

Hello, people.

Sorry if I'm late with my Bloggers, but at least I know for sure that I need to upload one!

Anyway, let me show you one of the initial exercises I had in my JAVA Programming classes for creating classes instead of inputting those already from loaded packages.

There is no description of this, unfortunately, but this exercise comes from two JAVA files because the Car class is in a class file of its own.

Here it is:

public class Car
{
    private int yearModel;
    private String make;
    private int speed;

    public Car(int modelAndYear, String manufacturer)
    {
        yearModel = modelAndYear;
        make = manufacturer;
        speed = 0;
    }

    public void accelerate()
    {
        speed += 5;
    }

    public void brake()
    { 
        speed -= 5;
    }

    public int getYearModel()
    {
        return yearModel;
    }

    public String getMake()
    {
        return make;
    }

    public int getSpeed()
    {
       return speed;
    }

}

Below is the demonstration code for the Car class. In this case, the created car accelerates five times and have its speed displayed, then decelerates five times with its speed displayed. To make this simple, two for loops were used.

public class CarClassProgram
{
    public static void main(String[] args)
    {
        Car car1 = new Car(87, "Chevrolet");
       
        for (int x = 0; x < 5; x++)
        {
            car1.accelerate();
            System.out.println(car1.getSpeed());
        }
       
        for (int y = 0; y < 5; y++)
        {
            car1.brake();
            System.out.println(car1.getSpeed());
        }
    }
}


Well, I hope you've enjoyed checking this out! Later!

Wednesday, December 5, 2012

String Letter Counter (JAVA Program)

Hello, guys.

This is another JAVA Program I want to share with you guys. It's a counter for a specific letter in an entered string straight from a program.

The code shown here shows how it works.

import javax.swing.JOptionPane;

public class Chapter4LetterCounter
{
    public static void main(String[] args)
    {
        String enterString;
        String characterSearch;
        char characterSearchLetter;
        char existingCharacter;
        int numberOfMatches = 0;
        int enterStringLength;
        int characterCounter = 0;
       
        enterString =
                JOptionPane.showInputDialog("Enter a string. This program will enter how many times a letter in" +
                                            " the string exists.\nPlease note that it will only search for " +
                                            "characters that are distinct from its opposite case partners.");
        enterStringLength = enterString.length();
       
        characterSearch =
                JOptionPane.showInputDialog("What character do you want this program to search?");
        characterSearchLetter = characterSearch.charAt(0);
       
        while (characterCounter < enterStringLength)
        {
            existingCharacter = enterString.charAt(characterCounter);
           
            if (existingCharacter == characterSearchLetter)
            {
                numberOfMatches++;
            }
           
            characterCounter++;
        }
       
        JOptionPane.showMessageDialog(null, "The program has found " + numberOfMatches + " matches of the " 

             + characterSearchLetter + " character.");
       
        System.exit(0);
       
       
    }

}




Fun with Music, Drama and Comedy

This is a persuasive speech I did in my Sec. 5 English class. It wasn't a great speech, unfortunately, but I'm posting it anyway for the sake of building an audience for myself, including you people.

Anyway, enjoy!



            Justin Bieber, Rihanna, Lady Gaga and The Beatles are some of the most influential celebrities in the world in terms of visual arts. But sometimes drama and comedy would add up to the fun of music or combined with it, depending on what we understand about it and how we earn the “past-on” experience from experts. Just how do we earn incredible emotion and recognition from performing these kinds of arts? My purpose is to interest my audience with drama, singing with music, and comedy, looking into the ideas of them with a little bit of my experience. For example, knock, knock, who’s there? It’s me! Anyway, it’s time to call to listen to the world of music, drama and comedy as we move beyond into music.

            Music is a sound, a form of sound where its properties create a sense of melodrama from various instruments, such as drums or guitars, that may include voice-overs. I happen to have a story. In the Black History Month Variety Show, I consider this party as “Bieber Fever” when I sang “Pray” by Justin Bieber and everyone cheered for it, along with the relaxed, smooth popularity of the voice on the mic. The music themselves, the artists and the lyrics, all add up to the hearts and/or brains of teenage girls and the minds of teenage boys. Melodrama is out there, allowing us to go into the feelings of others and feeling so proud. The stage is the magic, the cheering is the vial and the performance is all together, the potion. The reputation stands out as the singer shares his or her voice with their skills, even though you may be scared to perform in occasions like this. “To be or not to be,” as Prince Hamlet says in Shakespeare’s play Hamlet. “That is the question.”

            The props, the literature, the emotion and the movement. Drama is a kind of fiction related to literature shown in performance. The most famous ones include William Shakespeare’s screenplays, including Romeo & Juliet, Macbeth and Hamlet. Only one day of the year, one day, a school here, either in MonterĂ©gie-Est, Montreal or even Ottawa, the Montreal Shakespeare Company shows up. Don’t wait till the last minute, ask the cast how passionate a play or drama can be. When you see a bunch of sets on the stage, you’re already absorbed into a new world, like the world of Star Wars, Mario or Pokemon. However, Lucas, Miyamoto and Tajiri are in the world of video games and movies. Instead of big plays where you say, “Throw your mistemper’d weapons to the ground,” why not small ones like Danny, King of the Basement? But sometimes plays can’t be presented with one thing our minds are manipulated by: comedy.
           
The cell phone. It rumbles as if Winnie the Pooh says, “I rumbly in my tumbly.” Comedy is a discourse in a humorous manner to let the audience laugh at through techniques of verbal communication, tone and body language. Consider Jim Carrey, Michael J. Fox and Tom Green. They’re all silly men. They aren’t even going to play blackjack if they have to pay Rick Riordan all of Percy Jackson’s troubles. Of course, people try to look for jokes, but they ain’t always right. Only a soul would play a cartoon monster, yet it makes the public and the comedian’s friends feel happy and favourable. Although this person from Naples, Florida is going to college for broadcasting and/or narration, he’s still making jokes, along with the epic “No!”, in his video game walkthroughs. This person is Emiliano “Emile” Rodolfo Rosales-Birou, also known as YouTube user Chuggaaconroy. “Hey, everybody, it’s Chuggaaconroy!”
           
As a restatement, my purpose of the speech is to stimulate you to go up to the auditorium and show your valuable self with some speech and movement. Just don’t forget to hand in your CV or ask the director first! Take your chance and show what you’ve got, all to earn a big recognition. You’ll need a stage to do this. Don’t feel too proud before the director says his or her opinion, because you may lose your prize. And don’t feel too sad, have your friends help you. Although some of you are anxious to do it but feel that you’ll be happy with the strong recognition you can earn, just keep this in mind. “Never Say Never,” Justin Bieber. Whenever you’re in the cast or not, it’s there. A sense of entertainment and influence is there for you. I sing in music, I play in drama and I joke around in comedy.


Monday, December 3, 2012

JAVA Program - City Water Company Bill [The use of the while loop]

Hello, guys.

Here's another JAVA Program I want to show off; this is another one I did more than a year ago. A description is provided at the top of this computer file and all the necessary comments should be there. Enjoy reading!

/*
 *         WHILE Loop Lab -
 *         City Water Company Water Bill Program
 *
 *         File Name: CityWaterCompanyWaterBillProgram.java
 *
 *         Developed by Gregory Desrosiers
 *         Student of Champlain College St-Lambert
 *         St-Lambert, Quebec, Canada
 *
 *         Teacher: Mrs. Linda McGirr
 *
 *         This program is designed to calculate and print out bills for a
 *         city water company. The billing system consists of uploading
 *         input data from a text file, selecting the case of what the pay
 *         rate is based on the account's code, then determining the price
 *         and saving the results on another text file as well as
 *         displaying it in a dialog box.
 *
 *         The program contains a method to convert gallons to litres
 *         which is then studied for payment processing.
 *
 *         Tested Input File: WaterProgramTestInputData.txt
 *         Output File: WaterCompanyBill.txt
 *         (This will be found in the same directory as the project.)
 *        
 *         Coding Start Date & Time:
 *         Saturday, October 29, 2011, 8:05 PM
 *
 *         Coding End Date & Time:
 *
 *         Due Date : November 7, 2011
 *
 */

import java.io.*;
import javax.swing.JOptionPane;

public class CityWaterCompanyWaterBillProgram
{
    public static void main(String[] args) throws IOException
    {
        String inputFile,
               charToString,
               accountNumberString,
               currentTextLine,
               waterUsedInGallonsString = "",
               yesOrNoString;
       
        boolean yesOrNoQuestionAnswered = true,
                inputQuestion = true,
                codeValid = true,
                accountNumberDigitValid = true,
                faultyWaterCharacter = false;
       
        char currentCharacter = 0,
             accountNumberDigit,
             waterRateCode,
             waterUsedInGallonsCharacter,
             yesOrNo;
       
        double waterUsedInLitres;
       
        float  pST,
               gST,
               subTotal = 0,
               subTotalPlusGSTAndDiscount,
               discountedTotal,
               disCount,
               finalTotal;
       
        int characterTestNumber,
            lineLength,
            waterUsedInGallonsStringLength,
            waterUsedInGallons;
       
        final double gallonsToLitres = 3.78541178;
            // Retrieved from Google Calculator
       
        final float baseCostH = 5.00f,
                    baseCostC = 1000.00f,
                    payRateH = 0.0005f,
                    payRateC = 0.00025f,
                    rateGST = 0.05f,
                    ratePST = 0.075f,
                    lowDiscountRate = 0.05f,
                    highDiscountRate = 0.10f;
       
        PrintWriter outputFile = new PrintWriter("WaterCompanyBill.txt");
       
        JOptionPane.showMessageDialog(null, "Welcome to the McGirr" +
                                      " Water Payment System, powered" +
                                      " by JAVA. This program will" +
                                      " produce a water bill for" +
                                      " Montreal’s water company.");
       
        yesOrNoString =
                JOptionPane.showInputDialog("Is this your first time" +
                                            " using this program?" +
                                            " Type in 'Y' for yes" +
                                            " or other character for" +
                                            " no.\nThis is also where" +
                                            " you can see the format" +
                                            " the input file must be.");
       
        if (yesOrNoString != null)
        {
            yesOrNo = yesOrNoString.charAt(0);
       
            if (yesOrNo == 'Y' || yesOrNo == 'y')
            {
                JOptionPane.showMessageDialog(null, "What this program does" +
                                              " is it loads a file contain" +
                                              "ing the raw data (as a text" +
                                              " file, .txt) and takes the " +
                                              "raw data for calculations.\n" +
                                              "It reads the account number " +
                                              "and the code that is output" +
                                              "ted in a file called " +
                                              "WaterCompanyBill. The " +
                                              "data for consumption\n(in " +
                                              "gallons) is converted to " +
                                              "litres which the money is" +
                                              " then processed, depending" +
                                              " on the account code and how" +
                                              " many litres\nof water have " +
                                              "been consumed. The discount " +
                                              "is affected before the tax in" +
                                              " the subtotal, where it gives" +
                                              " a 5% discount for\nsubtotals " +
                                              "ranging from $20.00 to $75.00" +
                                              " or a 10% discount for sub" +
                                              "totals between $75.01 and " +
                                              "$999.99. If the total is " +
                                              "outside\nthe range, no " +
                                              "discount is applied. Either" +
                                              " have a discount or not, the" +
                                              " final steps remain the same.");
           
                JOptionPane.showMessageDialog(null, "In order to run the prog" +
                                              "ram, create a text file that ho" +
                                              "lds the data needed to produce " +
                                              "the bill.\n\nBe sure that the" +
                                              " text looks like this:\n\n1325" +
                                              " C 234524\n2135 H 332\n9423 I" +
                                              " 78932\n\nwhere the four digits" +
                                              " on the left is the account num" +
                                              "ber, the letter in the middle " +
                                              "is the account code,\nand the" +
                                              " number on the right is the " +
                                              "consumption (in gallons)." +
                                              " A space seperates each of t" +
                                              "he components.\n\nWARNING: Do" +
                                              " not enter labels. This progra" +
                                              "m will generate errors if the i" +
                                              "nput text file is not like the" +
                                              " example in\nthis dialog box." +
                                              " Do not add more than one spa" +
                                              "ce between the values because "+
                                              "the program will recognize the" +
                                              "\nextra spaces as invalid charac" +
                                              "ters.\n\nThe program will now a" +
                                              "sk you to enter the file name.");
            }
        }
       
        else
        {
            JOptionPane.showMessageDialog(null, "Error: No entry for" +
                                          " the first question. Please" +
                                          " restart the program and " +
                                          "answer the question.");
            yesOrNoQuestionAnswered = false;
        }
       
        if (yesOrNoQuestionAnswered)
        {
            inputFile =
                    JOptionPane.showInputDialog("Enter the file in which" +
                                                " the bill is to be" +
                                                " produced.\nDo not enter" +
                                                " the .txt file extension" +
                                                " unless it is part of the" +
                                                " name itself.\n.txt files" +
                                                " only.");
       
            // This is when the user clicks on Cancel, no matter what is
            // typed inside the input dialog box's entry box.
           
            if (inputFile == null)
            {
                JOptionPane.showMessageDialog(null, "Error: No file name" +
                                              " entered.\nPlease run the program" +
                                              " again and enter the text file" +
                                              " name.");
                inputQuestion = false;
            }
            else
            {
                FileReader textFileReader = new FileReader(inputFile + ".txt");
                BufferedReader inputTextFile = new BufferedReader(textFileReader);
       
                currentTextLine = inputTextFile.readLine();
               
                /*
                 *  If the text file can be read, it is tested to see if the first
                 *  line does not contain anything. If it passes, then it can go
                 *  for processing.
                 */
               
               
                if (currentTextLine == null)
                {
                    JOptionPane.showMessageDialog(null, "Error: No text written" +
                                                  " in the file.\nPlease restart" +
                                                  " the program and enter a file" +
                                                  " name containing the input da" +
                                                  "ta.");
                    inputQuestion = false;
                }
               
                else
                {
                   
                    outputFile.println("Please note that there are approximate" +
                                       " values in this file, but only the" +
                                       " last decimal place is harmed.");
                    outputFile.println("The cost is determined by the consumpt" +
                                       "ion in litres. To check the cost, mult" +
                                       "iply consumption by 3.78541178, then a" +
                                       "nalyze.");
                    outputFile.println("");
                    outputFile.println("Account | Code | Consumption |  Subtotal" +
                                       "  | Discount | Discounted Price |   GST " +
                                       "  | Discounted Price |    PST    | " +
                                       "Final Cost");
                    outputFile.println("Number  |      |  (Gallons)  |          " +
                                       "  |          |                  |       " +
                                       "  |     Plus GST     |           |");
                    outputFile.println("");
                   
                    System.out.println("Please note that there are approximate" +
                                       " values in this file, but only the" +
                                       " last decimal place is harmed.");
                    System.out.println("The cost is determined by the consumpt" +
                                       "ion in litres. To check the cost, mult" +
                                       "iply consumption by 3.78541178, then a" +
                                       "nalyze.");
                    System.out.println("");
                    System.out.println("Account | Code | Consumption |  Subtotal" +
                                       "  | Discount | Discounted Price |   GST " +
                                       "  | Discounted Price |    PST    | " +
                                       "Final Cost");
                    System.out.println("Number  |      |  (Gallons)  |          " +
                                       "  |          |                  |       " +
                                       "  |     Plus GST     |           |");
                    System.out.println("");
               
                    // All of the processing happens inside this loop.
               
                    while(currentTextLine != null && codeValid && accountNumberDigitValid &&
                            !faultyWaterCharacter)
                    {
                   
                        currentCharacter = 0;   
                        accountNumberString = "";
                   
                        while (currentCharacter >= 0 && currentCharacter <= 3 &&
                                accountNumberDigitValid)
                        {   
                            accountNumberDigit = currentTextLine.charAt(currentCharacter);
                       
                            characterTestNumber = (int)accountNumberDigit;
                       
                            if (characterTestNumber < 48 || characterTestNumber > 57)
                            {
                                accountNumberDigitValid = false;
                                currentCharacter += 4;
                            }
                            else
                            {
                                // The toString method is to convert the character to
                                // a string which can be then assigned to the
                                // variable holding the account number.
                       
                                charToString = Character.toString(accountNumberDigit);
                                accountNumberString += charToString;
                                currentCharacter++;
                            }
                        }
                   
                        /*
                         *  To prevent the program from generating an exception error
                         *  of converting a mixed string (numbers and nonnumerical
                         *  characters), this conditional statement will stop the
                         *  loop only if one of digits is not valid. Otherwise,
                         *  it is safe to convert the string into an integer.
                         */
                   
                        if (accountNumberDigitValid == false)
                            break;
                   
                        waterRateCode = currentTextLine.charAt(5);
                   
                        // Testing to see if waterRateCode contains an invalid
                        // character.
                   
                        if (waterRateCode != 'H' && waterRateCode != 'h' &&
                                waterRateCode != 'C' && waterRateCode != 'c' &&
                                waterRateCode != 'I' && waterRateCode != 'i')
                        {
                            codeValid = false;
                            break;
                        }
                   
                        else
                        {
                            lineLength = currentTextLine.length();
                            currentCharacter = 7;
                       
                            waterUsedInGallonsString = "";
                       
                            /*
                             *
                             */
                           
                            while (currentCharacter < lineLength && !faultyWaterCharacter)
                            {
                           
                                waterUsedInGallonsCharacter =
                                        currentTextLine.charAt(currentCharacter);
                                characterTestNumber =
                                        (int)waterUsedInGallonsCharacter;
                           
                                if (characterTestNumber < 48 || characterTestNumber > 57)
                                    faultyWaterCharacter = true;
                                else
                                {
                                    charToString =
                                            Character.toString(waterUsedInGallonsCharacter);
                                    waterUsedInGallonsString += charToString;
                                    currentCharacter++;
                                }
                           
                            }
                       
                            if (faultyWaterCharacter)
                                break;
                            else
                                waterUsedInGallons =
                                        Integer.parseInt(waterUsedInGallonsString);
                        }
                   
                        waterUsedInLitres = waterUsedInGallons * gallonsToLitres;
                   
                        switch (waterRateCode)
                        {
                            case 'H':
                            case 'h':
                            {
                            subTotal = (float)(baseCostH + payRateH * waterUsedInLitres);
                            break;
                            }
                   
                            case 'C':
                            case 'c':
                            {
                                if (waterUsedInLitres <= 4000000)
                                {
                                    subTotal = baseCostC;
                                }
                       
                                else
                                {
                                subTotal = (float)(baseCostC +
                                        (waterUsedInLitres - 4000000) * payRateC);
                                }
                       
                                break;
                            }
                       
                            case 'I':
                            case 'i':
                            {
                       
                                if (waterUsedInLitres <= 4000000)
                                    subTotal = 1000;
                       
                                else if (waterUsedInLitres > 4000000 &&
                                        waterUsedInLitres <= 10000000)
                                    subTotal = 2000;
                       
                                else
                                    subTotal = 3000;
                            }
                           
                            /*
                             * No default is needed because the letter is
                             * already checked if it's valid. Otherwise
                             * it's duplicate coding.
                             */
                        }
                   
                        disCount = 0.00f;
                        discountedTotal = subTotal;
                   
                        if (subTotal > 20.00 && subTotal <= 75.00)
                        {
                            disCount = subTotal * lowDiscountRate;
                            discountedTotal = subTotal - disCount;
                       
                            gST = discountedTotal * rateGST;
                       
                            subTotalPlusGSTAndDiscount = subTotal + gST;
                       
                            pST = subTotalPlusGSTAndDiscount * ratePST;
                       
                            finalTotal = subTotalPlusGSTAndDiscount + pST;
                        }
                   
                        else if (subTotal > 75.00 && subTotal < 1000.00)
                        {
                            disCount = subTotal * highDiscountRate;
                            discountedTotal = subTotal - disCount;
                       
                            gST = discountedTotal * rateGST;
                       
                            subTotalPlusGSTAndDiscount =
                                    discountedTotal + gST;
                       
                            pST = subTotalPlusGSTAndDiscount * ratePST;
                       
                            finalTotal = subTotalPlusGSTAndDiscount + pST;
                        }
                   
                        /*
                         * To make output easier, we will use the printf
                         * statement and use subTotalPlusGSTAndDiscount
                         * to display the price plus GST that doesn't
                         * have a discount.
                         */
                        else
                        {
                            gST = subTotal * rateGST;
                   
                            subTotalPlusGSTAndDiscount = subTotal + gST;
                   
                            pST = subTotalPlusGSTAndDiscount * ratePST;
                   
                            finalTotal = subTotalPlusGSTAndDiscount + pST;
                        }
                   
                        outputFile.print(accountNumberString + "       " +
                                         waterRateCode + "     " +
                                         waterUsedInGallons);
                       
                        System.out.print(accountNumberString + "       " +
                                         waterRateCode + "     " +
                                         waterUsedInGallons);
                   
                        waterUsedInGallonsStringLength =
                                waterUsedInGallonsString.length();
                   
                        // The switch statement may have its cases duplicated,
                        // but this is to tell the compiler how many spaces
                        // should the consumption and the subtotal be
                        // seperated to create a neat appearence.
                   
                        switch(waterUsedInGallonsStringLength)
                        {
                            case 1:
                            {
                                outputFile.print("             ");
                                System.out.print("             ");
                                break;
                            }
                            case 2:
                            {
                                outputFile.print("            ");
                                System.out.print("            ");
                                break;
                            }
                            case 3:
                            {
                                outputFile.print("           ");
                                System.out.print("           ");
                                break;
                            }
                            case 4:
                            {
                                outputFile.print("          ");
                                System.out.print("          ");
                                break;
                            }
                            case 5:
                            {
                                outputFile.print("         ");
                                System.out.print("         ");
                                break;
                            }
                            case 6:
                            {
                                outputFile.print("        ");
                                System.out.print("        ");
                                break;
                            }
                            case 7:
                            {
                                outputFile.print("       ");
                                System.out.print("       ");
                                break;
                            }
                            case 8:
                            {
                                outputFile.print("      ");
                                System.out.print("      ");
                                break;
                            }
                           
                                // There is no default because it won't be possible
                                // for the consumption to be negative numbers or
                                // have 9 digits or more.
                        }
                       
                        /*
                         * The following format lines produce the contents of the
                         * output file in such a way where it aligns them according
                         * to the field size for each field. This can only work if
                         * the font for both the console and the output text editor
                         * is set to Consolas or Lucida Console.
                         */
                   
                        outputFile.printf("$%9.2f", subTotal);
                        outputFile.printf("    $%5.2f", disCount);
                        outputFile.printf("       $%9.2f", discountedTotal);
                        outputFile.printf("      $%7.2f", gST);
                        outputFile.printf("     $%9.2f", subTotalPlusGSTAndDiscount);
                        outputFile.printf("      $%8.2f", pST);
                        outputFile.printf("   $%9.2f", finalTotal);
                   
                        outputFile.println();
                       
                        System.out.printf("$%9.2f", subTotal);
                        System.out.printf("    $%5.2f", disCount);
                        System.out.printf("       $%9.2f", discountedTotal);
                        System.out.printf("      $%7.2f", gST);
                        System.out.printf("     $%9.2f", subTotalPlusGSTAndDiscount);
                        System.out.printf("      $%8.2f", pST);
                        System.out.printf("   $%9.2f", finalTotal);
                   
                        System.out.println();
                   
                        currentTextLine = inputTextFile.readLine();
                    }
       
                    inputTextFile.close();
                }
            }
        }
       
        /*
         * The three following conditions are only to see if an error
         * has been encountered during the program and it declares
         * a variable has a problem, in which the following prevent
         * the program from crashing due to improper handling or
         * exception errors.
         */
       
        if (accountNumberDigitValid == false)
            JOptionPane.showMessageDialog(null, "Error: Invalid Account"
                                          + " Number.\nPlease make sure"
                                          + " all the characters in the"
                                          + " account number are digits"
                                          + " or have no spaces, " +
                                          "then run the program again.");
       
        else if (codeValid == false)
            JOptionPane.showMessageDialog(null, "Error: Invalid"
                                          + " Account Code.\n"
                                          + "Please correct the code"
                                          + " and run the program" +
                                          " again. ");
       
        else if (faultyWaterCharacter)
            JOptionPane.showMessageDialog(null, "Error: Invalid"
                                          + " Character in Water"
                                          + " Quantity\nPlease " +
                                          "make sure all the " +
                                          "characters in the " +
                                          "Consumpution field are " +
                                          "digits or have no space" +
                                          "s, then run the program" +
                                          " again.");
       
        /*
         * If the full text file successfully completes the loop,
         * the literal "Produced by the McGirr Water Payment System"
         * is printed at the bottom of the bill.
         */
       
        if (accountNumberDigitValid && codeValid &&
                faultyWaterCharacter == false && yesOrNoQuestionAnswered
                && inputQuestion)
        {
            outputFile.println();
            outputFile.println("Produced by the McGirr Water " +
                               "Payment System.");
           
            System.out.println();
            System.out.println("Produced by the McGirr Water " +
                               "Payment System.");
           
            JOptionPane.showMessageDialog(null, "Thank you.\nThe" +
                                          " bill has been produced.");
        }
       
        /*
         * This is only if an error is encountered during the loop,
         * because the program can't erase the output file when it
         * encounters one.
         */
       
        else if (accountNumberDigitValid == false || codeValid == false ||
                faultyWaterCharacter)
            JOptionPane.showMessageDialog(null, "Some of the outpu" +
                                          "t has been made, except" +
                                          " the lines where the er" +
                                          "ror was found and those" +
                                          " after it.");       

        /*
         * The following condition is to let the dialog box display only
         * if the program directs the user to the loop once the file
         * is read. It is not executed if the question on the user using
         * the program the first time is not answered.
         */
       
        if ((accountNumberDigitValid && codeValid &&
                faultyWaterCharacter == false && yesOrNoQuestionAnswered
                && inputQuestion) || (accountNumberDigitValid == false
                || codeValid == false || faultyWaterCharacter))
            JOptionPane.showMessageDialog(null, "If the font you're" +
                                          " using on Notepad or any" +
                                          " text editor is not set " +
                                          "to Consolas or Lucida Co" +
                                          "nsole,\nyour bill is not" +
                                          " going to look nice beca" +
                                          "use of how many spaces s" +
                                          "eperate the fields and h" +
                                          "ow each\nfont family has" +
                                          " a different space width" +
                                          ".\n\nThe bill can also b" +
                                          "e seen on the screen thr" +
                                          "ough an IDE's console or" +
                                          " if you're running the p" +
                                          "rogram\non the command p" +
                                          "rompt.");
       
        JOptionPane.showMessageDialog(null, "Program Complete.");
       
       
        outputFile.close();
        System.exit(0);
    }
}


Please read up my blog on my volunteering! http://gregorypdesrosiersmontreal.blogspot.ca/2015/08/my-mission-to-volunteer-for-reaching-my.html

Google+ Followers

Popular Posts by Gregory