Tale of the Cave

Tale of the Cave

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Alex's "I'm learning how to Program" thread.  (Read 1932 times)

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Alex's "I'm learning how to Program" thread.
« on: March 04, 2010, 10:37:53 AM »
I'm starting programming in school, and I'm finally starting to get the hang of it, so I thought I could come and share what I've done with people.
Also, I miss the hell outta this place and don't want to spam constantly so it's a reason to post :)

Project: CD Order Receipt thing
Description: It's supposed to be like an online CD order form. A lot of this was taken from the example used in class, and from bits of my beginning works.
Quote
import java.io.*;
class CDCost
{
    public static void main ( String [] args ) throws IOException
    {
        String inName, inTelephone, inStreetaddress, inCityProvince, inEmail, inNumCD; // The variables for collecting information
        double CDcost, GST, PST, Total; // the variables for calculating the cost of the CD   
            BufferedReader stdin=
                new BufferedReader (
                new InputStreamReader ( System.in ) );
            System.out.println("Enter Personal Information prior to making purchase");
           
            System.out.println("Name: "); // Requests Name
            inName = stdin.readLine(); // reads the input
           
            System.out.println("Telphone Number: "); // Requests Phone Number
            inTelephone = stdin.readLine(); // reads the input
           
            System.out.println("Street Address: "); // Requests Address
            inStreetaddress = stdin.readLine(); // reads the input
           
            System.out.println("City and Province: "); // Requests Location
            inCityProvince = stdin.readLine(); // reads the input
           
            System.out.println("Email Address: "); // Requests E-mail address
            inEmail = stdin.readLine(); // reads the input
           
            System.out.println(" *** Purchase Information ***");
            System.out.println("Each CD is sold for $19.99 plus taxes."); // Displays the cost of 1 CD
           
            System.out.println("How many CD's do you wish to purchase?"); // Requests how many CDs are being purchased
            inNumCD = stdin.readLine(); // reads the input
           
            CDcost = Double.parseDouble(inNumCD)*19.99; // Calculates how much CDs cost
            GST = CDcost * 0.05; // Calculates GST
            PST = CDcost * 0.08; // Calculates PST
            Total = CDcost + GST + PST; // Calculates the Total
           
            // The Following is the receipt
           
            System.out.println("/t Your Receiot");
            System.out.println("Alex's CD Warehouse");
            System.out.println("2079 St.John's road");
            System.out.println("Innisfil, Ontario");
            System.out.println("L9S 1Y3");
           
            System.out.println(" ");
            // Customer Information:
            System.out.println("\t Customer: "+ inName);
            System.out.println("\t " + inTelephone);
            System.out.println("\t " + inStreetaddress);
            System.out.println("\t " + inCityProvince);
            System.out.println("\t " + inEmail);
           
            System.out.println(" ");
            // Purchase Information
            System.out.println("\t ITEM: CD");
            System.out.println("\t QUANTITY: " + inNumCD);
            System.out.println("\t COST: " + Total);
            System.out.println(" ");
            System.out.println("\t Subtotal: \t $" + CDcost);
            System.out.println("\t GST: \t $" + GST);
            System.out.println("\t PST: \t $" + PST);
            System.out.println("\t Total Cost: \t $" + Total);
    }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread. -
« Reply #1 on: March 04, 2010, 10:40:06 AM »
I'm going to keep it to one project per post, I hope that's alright.

Project: Exam writing
Description: Depending on the average given and number of days absent, this finds out if the student has to write the final exam.
Quote
import java.io.*;
class NumberTest
{
    public static void main ( String [] args ) throws IOException
    {
        BufferedReader stdin =
        new BufferedReader ( new InputStreamReader (System.in ) );
       
            String inData;
            int my_average, days_absent;
           
            System.out.println ("Enter the student's average:");
            inData = stdin.readLine();
            my_average = Integer.parseInt( inData );
           
            System.out.println ("Enter the days absent:");
            inData = stdin.readLine();
            days_absent = Integer.parseInt ( inData );
           
            if ( my_average >=90 )
            {
                if ( days_absent <=3 )
                System.out.println ("Exempt from final");
            }
            else
            {
                System.out.println ("Must write final");
            }
    }
}
           
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #2 on: March 24, 2010, 09:34:47 AM »
3 circles of different colours.


Quote
import java.applet.Applet;
import java.awt.*;

public class ThreeColorCircle extends Applet
{
    final int width = 200, height = 200;
    final int radius = 10;
    final int radius2 = 20;
    final int radius3 = 30;
   
    public void paint ( Graphics gr )
    {
        gr.setColor( Color.blue );
        gr.drawOval( (200/2 - radius), (200/2 - radius), radius*2, radius*2 );
        gr.setColor( Color.red );
        gr.drawOval( (200/2 - radius2), (200/2 - radius2), radius2*2, radius2*2 );
        gr.setColor( Color.green );
        gr.drawOval( (200/2 - radius3), (200/2 - radius3), radius3*2, radius3*2 );
    }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #3 on: March 24, 2010, 09:36:22 AM »
My name in a circle

Quote
import java.applet.Applet;
import java.awt.*;

public class CircleName extends Applet
{
  final int width = 200, height = 200; 
  final int radius = 25;
 
  public void paint ( Graphics gr )
  {
    gr.drawOval( (200/2 - radius), (200/2 - radius), radius*2, radius*2 );
    gr.drawString("Ally",90, 105);
   }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #4 on: March 24, 2010, 09:37:23 AM »
A huge asterisk

Quote
import java.applet.Applet;
import java.awt.*;

public class PenTool extends Applet
{
    public void paint ( Graphics gr )
    {
   
     setBackground( Color.pink );
     gr.drawLine( 250, 50, 250, 450 );
     gr.drawLine( 50, 250, 450, 250 );
     gr.drawLine( 50, 50, 450, 450 );
     gr.drawLine( 450, 50, 50, 450 );
     }
}


A fail!snowman

Quote
import java.applet.Applet;
import java.awt.*;

public class Snowman extends Applet
{
    final int radius1 = 75;
    final int radius2 = 50;
    final int radius3 = 35;
    final int radius4 = 10;
    public void paint ( Graphics gr )
    {
   
    setBackground( Color.pink );
    gr.drawLine ( 0, 250, 500, 250 ); // horizon
    gr.drawLine ( 225, 205, 275, 205); // mouth
    gr.drawOval ( ( 500/2 - radius1), (400 - radius1), radius1*2, radius1*2); // bottom circle
    gr.drawOval ( ( 500/2 - radius2), (275 - radius2), radius2*2, radius2*2); // middle circle
    gr.drawOval ( ( 500/2 - radius3), (190 - radius3), radius3*2, radius3*2); // top circle
    gr.drawOval ( 225, 175, radius4*2, radius4*2); // eye1
    gr.drawOval ( 260, 175, radius4*2, radius4*2); // eye2
    }
}


Ten Concentric circles
Quote
import java.applet.Applet;
import java.awt.*;

public class TenConcentric extends Applet
{
    final int radius1 = 100;
    final int radius2 = 90;
    final int radius3 = 80;
    final int radius4 = 70;
    final int radius5 = 60;
    final int radius6 = 50;
    final int radius7 = 40;
    final int radius8 = 30;
    final int radius9 = 20;
    final int radius10 = 10;
    public void paint ( Graphics gr )
    {
   
    setBackground( Color.pink );
    gr.drawOval ( ( 500/2 - radius1), (500/2 - radius1), radius1*2, radius1*2); // outer circle
    gr.drawOval ( ( 500/2 - radius2), (500/2 - radius2), radius2*2, radius2*2);
    gr.drawOval ( ( 500/2 - radius3), (500/2 - radius3), radius3*2, radius3*2);
    gr.drawOval ( ( 500/2 - radius4), (500/2 - radius4), radius4*2, radius4*2);
    gr.drawOval ( ( 500/2 - radius5), (500/2 - radius5), radius5*2, radius5*2);
    gr.drawOval ( ( 500/2 - radius6), (500/2 - radius6), radius6*2, radius6*2);
    gr.drawOval ( ( 500/2 - radius7), (500/2 - radius7), radius7*2, radius7*2);
    gr.drawOval ( ( 500/2 - radius8), (500/2 - radius8), radius8*2, radius8*2);
    gr.drawOval ( ( 500/2 - radius9), (500/2 - radius9), radius9*2, radius9*2);
    gr.drawOval ( ( 500/2 - radius10), (500/2 - radius10), radius10*2, radius10*2);
   
   
    }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #5 on: April 09, 2010, 09:07:34 AM »
Happy late easter, guys.

Quote
import java.applet.Applet;
import java.awt.*;

public class HolidayCard extends Applet
{
    final int radius = 40; // radius of the head
    final int radius2 = 10; // of the eyes
    final int radius1 = 4; // inner eyes
    final int radius3 = 50; // horizontal body
    final int radius4 = 75; // vertical body
    final int radius5 = 45; // height of ears
    final int radius6 = 15; // width of ears
    final int radius7 = 30;// foot width
    final int radius8 = 25;// foot height
    final int width = 10, height = 10; // teeth rectangle
    public void paint ( Graphics gr )
    {
   
    setBackground( Color.green );
    gr.setColor( Color.gray );
    gr.fillOval ( 200, 205, radius*2, radius*2); // head
    gr.fillOval ( 190, 280, radius3*2, radius4*2); // body
    gr.fillOval ( 205, 123, radius6*2, radius5*2); //ear #1
    gr.fillOval ( 245, 123, radius6*2, radius5*2); // ear #2
    gr.fillOval ( 175, 415, radius7*2, radius8*2); // foot 1
    gr.fillOval ( 245, 415, radius7*2, radius8*2); // foot 2
    gr.setColor( Color.white );
    gr.fillOval ( 200, 330, radius*2, radius3*2); // stomach
    gr.setColor( Color.white );
    gr.fillOval ( 215, 225, radius2*2, radius2*2); // eye1
    gr.fillOval ( 245, 225, radius2*2, radius2*2); // eye2
    gr.setColor(Color.black );
    gr.fillOval ( 220, 231, radius1*2, radius1*2); // pupil 1
    gr.fillOval ( 250, 231, radius1*2, radius1*2); // pupil 2
    gr.setColor( Color.white );
    gr.fillRect ( 230, 265, width, height ); // left tooth
    gr.fillRect ( 240, 265, width, height ); // right tooth
    gr.setColor (Color.pink );
    gr.fillOval ( 237, 250, radius2*2, radius2*2); // mouth thing
    gr.fillOval ( 223, 250, radius2*2, radius2*2); // mouth thing
    gr.setColor (Color.black );
    gr.drawLine ( 240, 265, 240, 275 ); // tooth line
    gr.drawLine ( 180, 245, 230, 255 ); // left whisker
    gr.drawLine ( 180, 260, 230, 260 ); // left whisker
    gr.drawLine ( 180, 275, 230, 265 ); // left whisker
    gr.drawLine ( 250, 255, 300, 245 ); // right whisker
    gr.drawLine ( 250, 260, 300, 260 ); // right whisker
    gr.drawLine ( 250, 265, 300, 275 ); // right whisker
   
    gr.drawString ("Happy Easter", 200, 100); // text

    }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #6 on: April 15, 2010, 08:33:25 AM »
Ridiculously repetitive.

Quote
import java.applet.Applet;
import java.awt.*;

public class TenAlternating extends Applet
{
    final int radius = 15;
   
    public void paint ( Graphics gr )
    {
   
        setBackground( Color.pink );
        gr.setColor( Color.red );
        gr.drawOval ( 50, (200/2 - radius), radius*2, radius*2); // red/ far left circle
        gr.setColor( Color.blue );
        gr.drawOval ( 80, (200/2 - radius), radius*2, radius*2); // blue
        gr.setColor( Color.red );
        gr.drawOval ( 110, (200/2 - radius), radius*2, radius*2); // red
        gr.setColor( Color.blue );
        gr.drawOval ( 140, (200/2 - radius), radius*2, radius*2); // blue
        gr.setColor( Color.red );
        gr.drawOval ( 170, (200/2 - radius), radius*2, radius*2); // red
        gr.setColor( Color.blue );
        gr.drawOval ( 200, (200/2 - radius), radius*2, radius*2); // blue
        gr.setColor( Color.red );
        gr.drawOval ( 230, (200/2 - radius), radius*2, radius*2); // red
        gr.setColor( Color.blue );
        gr.drawOval ( 260, (200/2 - radius), radius*2, radius*2); // blue
        gr.setColor( Color.red );
        gr.drawOval ( 290, (200/2 - radius), radius*2, radius*2); // red
        gr.setColor( Color.blue );
        gr.drawOval ( 320, (200/2 - radius), radius*2, radius*2); // blue
        gr.setColor( Color.red );
        gr.drawOval ( 350, (200/2 - radius), radius*2, radius*2); // red
       
    }
}
       
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #7 on: April 15, 2010, 09:32:35 AM »
A work in progress, I need to get this animated somehow to make it look like a tornado is going across the screen, destroying the city. Any ideas? I can't figure it out. >:

Quote
import java.applet.Applet;
import java.awt.*;

public class CityScape extends Applet
{
    final int block1w = 80, block1h = 50, block2h = 90; // dimensions of the first house
    final int doorw = 20, doorh = 30; // dimensions of all doors in the drawing
    final int buildw = 90, buildh = 250;// 2nd building dimensions
    final int winwid = 30; // window dimensions

    public void paint (Graphics gr)
    {

        setBackground (Color.blue);
        gr.setColor (Color.red);
        Polygon po=new Polygon(); // roof
        po.addPoint(150,200);
        po.addPoint(190,150);
        po.addPoint(230,200);
        gr.fillPolygon(po);
        gr.drawPolygon(po); // roof
        gr.fillRect ( 150, 200, block1w, block1h ); // house 1
        gr.fillRect ( 150, 250, block1w, block2h ); // house 1
        gr.setColor (Color.black);
        gr.fillRect ( 170, 310, doorw, doorh ); // door
        gr.drawLine ( 150, 250, 230, 250 ); // house1 section separator
       
        gr.setColor (Color.gray);
        gr.fillRect ( 245, 90, buildw, buildh);
        gr.setColor (Color.pink);
        gr.fillRect ( 160, 210, winwid, winwid);  // 1st building windows
        gr.fillRect ( 160, 260, winwid, winwid);
        gr.fillRect ( 195, 210, winwid, winwid);
        gr.fillRect ( 195, 260, winwid, winwid);
        gr.fillRect ( 255, 110, winwid, winwid); // 2nd building windows
        gr.fillRect ( 295, 110, winwid, winwid);
        gr.fillRect ( 255, 150, winwid, winwid);
        gr.fillRect ( 295, 150, winwid, winwid);
        gr.fillRect ( 255, 190, winwid, winwid);
        gr.fillRect ( 295, 190, winwid, winwid);
        gr.fillRect ( 255, 230, winwid, winwid);
        gr.fillRect ( 295, 230, winwid, winwid);
        gr.fillRect ( 255, 270, winwid, winwid);
        gr.fillRect ( 295, 270, winwid, winwid);
        gr.fillRect ( 295, 310, winwid, winwid);
        gr.setColor (Color.black);
        gr.fillRect ( 260, 310, doorw, doorh);
        gr.drawLine (0, 340, 1024, 340);
    }
}
Logged

We are the control. We keep you safe. We are your hope.

RedAxie

  • Not so bright
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1124
  • Alignment: Chaotic Good
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #8 on: April 15, 2010, 09:34:07 AM »
Also, my huge huge huge project that nearly killed me.
Quote
// Assignment #3
// Name: Alex Spridgeon
// Details: A program that takes on amount of money in a set currency and converts it to another currency.

import java.io.*;
class Assignment3
{
    public static void main ( String [] args ) throws IOException
    {
        BufferedReader stdin =
        new BufferedReader ( new InputStreamReader (System.in ) );
       
            String inData;
            int mycurrency, newcurrency;
            double firstValue, tempValue=0, newValue=0;
           
            System.out.println ("Please enter the number of your starting currency:");
            System.out.println ("1. Japanese Yen");
            System.out.println ("2. Canadian Dollars");
            System.out.println ("3. American Dollars");
            System.out.println ("4. Euros");
            System.out.println ("5. Australian Dollars");
            inData = stdin.readLine();
            mycurrency = Integer.parseInt ( inData );
           
            if ( mycurrency == 1 )
            {
            System.out.println ("You have chosen Japanese Yen.");
            }
            else if ( mycurrency == 2 )
            {
            System.out.println ("You have chosen Canadian Dollars.");
            }
            else if ( mycurrency == 3 )
            {
            System.out.println ("You have chosen American Dollars.");
            }
            else if ( mycurrency == 4 )
            {
            System.out.println ("You have chosen Euros.");
            }
            else if ( mycurrency == 5 )
            {
            System.out.println ("You have chosen Australian Dollars.");
            }
        else
        {
        System.out.println ("CHOOSE AN ACTUAL OPTION YOU JERK");
        }
       
        System.out.println ("Please enter the amount of money you wish to convert.");
        inData = stdin.readLine();
        firstValue = Double.parseDouble(inData);
        if ( mycurrency == 1 )
            {
            tempValue = firstValue / 87.6654;
            }
        else if ( mycurrency == 2 )
            {
            tempValue = firstValue * 1.00;
            }
        else if ( mycurrency == 3 )
            {
            tempValue = firstValue * 0.97366;
            }
        else if ( mycurrency == 4 )
            {
            tempValue = firstValue * 0.716;
            }
        else if ( mycurrency == 5 )
            {
            tempValue = firstValue * 1.06352;
            }
           
        System.out.println ("Select the number of the currency you'd like to convert your money to:");
            System.out.println ("1. Japanese Yen");
            System.out.println ("2. Canadian Dollars");
            System.out.println ("3. American Dollars");
            System.out.println ("4. Euros");
            System.out.println ("5. Australian Dollars");
            inData = stdin.readLine();
            newcurrency = Integer.parseInt ( inData );
           
                if ( newcurrency == 1 )
                {
                newValue = tempValue * 87.6654;  //Japanese Yen output
                }
            else if ( newcurrency == 2 )
                {
                newValue = tempValue;
                }
            else if ( newcurrency == 3 )
                {
                newValue = tempValue / 0.97366;
                }
            else if ( newcurrency == 4 )
                {
                newValue = tempValue / 0.716;
                }
            else if ( newcurrency == 5 )
                {
                newValue = tempValue / 1.06352;
                }
           
            System.out.println ("Your Amount : " + newValue);
    }
}
               
           
       
         
Logged

We are the control. We keep you safe. We are your hope.

ScienceFair

  • Full Member
  • ***
  • Offline Offline
  • Posts: 390
  • Alignment: Neutral Good
  • Worst icon ever?
    • View Profile
Re: Alex's "I'm learning how to Program" thread.
« Reply #9 on: May 03, 2010, 12:34:59 PM »
Looks like Java... Unfortunately I'm pretty noobish at Java... I could share crap, but eak no time.
Logged
Pages: [1]   Go Up
« previous next »
 

Page created in 0.174 seconds with 17 queries.