Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Basic Class
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
goboenomo




PostPosted: Fri Oct 21, 2005 11:26 am   Post subject: Basic Class

Im taking a programming class at my high school
its really easy...
hahah i have so much extra time... i can submit one of the programs we had to make
code:

import java.io.*;
public class Invoice
{
    public static void main (String[] args)
        throws java.io.IOException
    {
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

        String name;
        String addy;
        String city;
        String prov;
        String postcode;
        String scds;
        int cds;
        String sdvds;
        int dvds;
        double subtot;
        double gst;
        double pst;
        double total;

        double cdc = 16.99;
        double dvdc = 24.99;

        System.out.println ("What is your name?");
        name = br.readLine ();
        System.out.println ("What is your address?");
        addy = br.readLine ();
        System.out.println ("What province do you live in?");
        prov = br.readLine ();
        System.out.println ("What city do you live in?");
        city = br.readLine ();
        System.out.println ("What is your postal code?");
        postcode = br.readLine ();
        System.out.println ("CDs are $16.99, how many would you like to buy?");
        scds = br.readLine ();
        System.out.println ("DVDs are $24.99, how many would you like to buy?");
        sdvds = br.readLine ();

        cds = Integer.parseInt (scds);
        dvds = Integer.parseInt (sdvds);

        subtot = (cds * cdc) + (dvds * dvdc);
        gst = subtot * .07;
        pst = subtot * .08;
        total = subtot + gst + pst;

        System.out.println ("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");


        System.out.println ("                                    INVOICE");
        System.out.println ("");
        System.out.println (name);
        System.out.println (addy);
        System.out.println (city + ", " + prov);
        System.out.println (postcode);
        System.out.println ("");
        System.out.println ("");
        System.out.println ("                                    CDs - QUANTITY    " + cds);
        System.out.println ("                                             xCOST    $" + cdc);
        System.out.println ("");
        System.out.println ("                                    DVDs - QUANTITY   " + dvds);
        System.out.println ("                                              xCOST   $" + dvdc);
        System.out.println ("");
        System.out.println ("                                           SUBTOTAL   $" + subtot);
        System.out.println ("                                                GST   $" + gst);
        System.out.println ("                                                PST   $" + pst);
        System.out.println ("                                              TOTAL   $" + total);
        System.out.println ("\n\n\n\n\n");
    }
}

*Yawn*
We got 2 classes (2hours and 30 mins) to work on this.. it took me 20 minutes
hahahahah
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Oct 21, 2005 1:59 pm   Post subject: (No subject)

Java:
int cds = Integer.parseInt(br.readLine());


And lose the:

Java:
String scds;


Java:
int cds;


Java:
scds = br.readLine();


And:

Java:
cds = Integer.parseInt(scds);


Lines.
goboenomo




PostPosted: Sun Oct 23, 2005 10:38 pm   Post subject: (No subject)

right now in class we have to promt the user and recieve as a string then change to int... so for now i need those variables
1of42




PostPosted: Mon Oct 24, 2005 3:16 pm   Post subject: (No subject)

What wtd is doing is the exact same thing, but he uses an anonymous variable for the String input, and puts intialization and assignment on one line.
goomba




PostPosted: Sun Oct 30, 2005 9:20 pm   Post subject: (No subject)

Very easy, says the newbie. Very Happy Since you have sooo much extra time, how about skipping ahead of your class and reading up on how to write proper OOP code?

If you want to show off some real Java skillz, try rewriting your program to consist of an InvoiceApp class and an Invoice class. The Invoice class should have methods to get, set, and calculate values as well as one or two constructors to set common values on instantiation. The InvoiceApp class should generate Invoices based on user input and store these in a list of some sort.

Razz
goboenomo-855




PostPosted: Sun Oct 30, 2005 10:38 pm   Post subject: (No subject)

goomba wrote:
Very easy, says the newbie. Very Happy Since you have sooo much extra time, how about skipping ahead of your class and reading up on how to write proper OOP code?

If you want to show off some real Java skillz, try rewriting your program to consist of an InvoiceApp class and an Invoice class. The Invoice class should have methods to get, set, and calculate values as well as one or two constructors to set common values on instantiation. The InvoiceApp class should generate Invoices based on user input and store these in a list of some sort.

Razz

i would, u fucking asshole...
but my teacher wont let me
goomba




PostPosted: Sun Oct 30, 2005 11:33 pm   Post subject: (No subject)

Yeah, cause teachers HATE it when you go above the requirements. Rolling Eyes
Hikaru79




PostPosted: Sun Oct 30, 2005 11:46 pm   Post subject: (No subject)

goboenomo-855 wrote:

i would, u ****ing *******...
but my teacher wont let me

If your teacher won't let you use real, correct code perhaps you should just drop the class, because it will hurt you more than help you at that rate...
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: