General Category > Programming

Alex's "I'm learning how to Program" thread.

(1/2) > >>

RedAxie:
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);
    }
}<<<<

RedAxie:
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");
            }
    }
}
            <<<<

RedAxie:
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 );
    }
}<<<<

RedAxie:
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);
   }
}
<<<<

RedAxie:
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);
   
   
    }
}
<<<<

Navigation

[0] Message Index

[#] Next page