Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[COMMENTS!]My first made from scratch Java program

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Sun Mar 18, 2007 3:36 pm    Post subject: [COMMENTS!]My first made from scratch Java program Reply with quote

Hey guys, I have had a Java book laying around for a while now, and Pillboi's thread got me thinking that I should start learning. So i read about 100 pages in it and built this program, please tell me what you think( I know its useless, but it encourages me) about the program. Thanks.
PS. This isn't an example in the book, I built it.
Code:
import java.util.Scanner;
//imports a function that allows me to get input from the user.
 
public class BillCalculate {
   //Marks the start of the class: BillCalculate
   
    public static void main(String[] args) {
       //Starts the main section of the program
       Scanner reader = new Scanner(System.in);


       //Declares a new scanner for grabbing bills
       double electricity = 0;
       //Water, Housepayment, Internetservice, and totalbill are all declarations.
       double water = 0;
       double housepayment = 0;
       double internetservice = 0;
       double totalbill = 0;
       System.out.println ("This Program will calculate a few of your bills.");
       //Shows the text "This Program will calculate a few of your bills."
          System.out.print ("What is your electricity bill? ");
          //Shows the text "What is your electricity bill? "
             electricity = (reader.nextDouble());
             //Changes electricity, a variable, to whatever the user inputs.(must be a number)
             System.out.print ("What is your Water Bill? ");
             //You should be able to tell what the rest of these do.
             water = (reader.nextDouble());
             System.out.print ("What is your House Payment? ");
             housepayment = (reader.nextDouble());
             System.out.print ("What is your Internet Service? ");
             internetservice = (reader.nextDouble());
             System.out.println ("Adding all bills...");
             totalbill = electricity + water + housepayment + internetservice;
             System.out.print ("Your Total Bill is $");
                System.out.print (totalbill);
             System.out.println ("  Thanks for using my bill adder!");
             
    }
}





Ok, I just finished making my second program, this one is based a lot off of if then statements
Code:
import java.util.Scanner;
public class ifthen {
   
    public static void main(String[] args) {
    //Declarations
    Scanner reader = new Scanner(System.in);
    double magic = 58;
    double userinput = 0;
    double score = 0;
    //Begin Code
    System.out.print ("Please enter a number: ");
    userinput = (reader.nextDouble());
    if ((userinput) > (magic)) {
       System.out.println ("YOU ARE ALMIGHTY!");
       score++;
    }
    else {
       System.out.println ("YOU ARE DUMBISH!");
       score--;
        }
        System.out.print ("The score is now ");
          System.out.println (score);
          
    System.out.println ("Please enter another number: ");
    userinput = (reader.nextDouble());
    magic = magic + 320492;
    if ((userinput) < (magic)) {
       System.out.println ("NICE, YOU SCORED!~~~");
       score++;
    } else {
       System.out.println ("You missed!");
          score --;
    }
    System.out.println ("Now lets see how you did!!!");
    if (score == 0) {
       System.out.println ("You scored 0, Nice Try!");
    } else if (score > 0){
       System.out.println ("You scored more than 0! Nice Job!");
    } else if (score < 0) {
       System.out.println ("You scored less than 0! You'll do better next time!");
    }
    System.out.println ("The final score was ");
       System.out.print (score);
   
       }
}

_________________


Last edited by ravicus on Sun Mar 18, 2007 8:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sun Mar 18, 2007 3:48 pm    Post subject: Re: [COMMENTS!]My first made from scratch Java program Reply with quote

ravicus wrote:
Hey guys, I have had a Java book laying around for a while now, and Pillboi's thread got me thinking that I should start learning. So i read about 100 pages in it and built this program, please tell me what you think( I know its useless, but it encourages me) about the program. Thanks.


Wow. I actually influenced someone. Anyway...
Even though I don't know any Java, as you can tell from my last thread, this looks quite "cool" even though it's practically useless. It's the programming that counts.

--Pillboi--

_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Sun Mar 18, 2007 6:10 pm    Post subject: Reply with quote

Thanks, I just got back from church, so I'll post my comments on your thread now.
_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Mar 18, 2007 6:22 pm    Post subject: Reply with quote

I wish I had the Scanner class when I started... I had to use this:

Code:

private static BufferedReader c = new BufferedReader (
            new InputStreamReader (System.in));


Anyways, your code looks kinda long... maybe it's because of all the commenting. Don't comment every obvious step that you do, only outline places where you would like to explain your logic. Also, you don't have to keep track of all the variables if you only want a total. One variable as a total would do fine. To make it more easily expandable, you could probably even put the questions into an array so that you could easily add new questions.

Something like this:

Code:

import java.util.Scanner;

public class BillCalculate
{
    public static void main (String[] args)
    {
        Scanner in = new Scanner (System.in);
        String[] strs = {"Water Bill",
            "House Payment",
            "Internet Service"
            };
        double t = 0;
        for (int i = 0 ; i < strs.length ; i++)
        {
            System.out.println ("What is your " + strs [i] + "?");
            t += read.nextDouble ();
        }
        System.out.println ("Your Total Bill is $" + t);
    }
}


_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Sun Mar 18, 2007 6:25 pm    Post subject: Reply with quote

Hmm, Thanks for the suggestion, except i havn't learned about strings yet, so i dont want to write code i don't understand.
_________________
Back to top
View user's profile Send private message
hallowicked
Master Cheater
Reputation: 0

Joined: 16 Aug 2006
Posts: 312
Location: Kansas City

PostPosted: Tue Mar 27, 2007 8:28 am    Post subject: Reply with quote

I haven't learned anything yet Very Happy YAY. I'm staring up on C++ Right now. Just got my clienty thingy for it and when I get home today I'm probly going to start working on SOMETHING... I have no idea what I'm going to make but y'know.
_________________
Back to top
View user's profile Send private message Yahoo Messenger
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Tue Mar 27, 2007 7:18 pm    Post subject: Reply with quote

hmmm Well, I am a lot more advanced than this code now.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites