Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[Java] My Progress filter_list
Author
Message
[Java] My Progress #1
Hello HC, I am just posting this to 1: show off my progress that I make in java, and 2: so other beginners can read it and better themselves. I will post the objective/assignment that I have completed, and the source for it. This will be updated when I have made new programs. So here it goes.

My first program as you all probably saw was a super simple CLI calculator. Here is the code for it:
Code:
import java.util.Scanner;

public class calculator {
        public static void main(String args[]) {
            Scanner lightx = new Scanner(System.in);
            
            double fnum, snum, answer = 0, operation;
            
            System.out.println("Enter your first number: ");
            fnum = lightx.nextDouble();
            
            System.out.println("Enter your second number: ");
            snum = lightx.nextDouble();
            
            System.out.println("What operation would you like to use? (+ = 1, - = 2, * = 3, / = 4)");
            operation = lightx.nextDouble();
            
            if (operation == 1){
                answer = fnum + snum;
            }
            
            if (operation == 2){
                answer = fnum - snum;
            }
            
            if (operation == 3){
                answer = fnum * snum;
            }
            
            if (operation == 4){
                answer = fnum / snum;
            }
                
            System.out.println(answer);
            
            }
        }


This next one is a program that takes your input and returns it to you until you enter "exit". Code:
Code:
import java.util.Scanner;

public class Repeat {
    public static void main(String args[]){
        Scanner word = new Scanner(System.in);
        
        String word1;

        do {
            
             System.out.println("Input: ");
             word1 = word.nextLine();
            
             if(!word1.equals("exit")){
                 System.out.println(word1);
                }
            } while(!word1.equals("exit"));
    }
}


This one is another simple program that takes a number input from you and counts from 0 to your number.
Code:
import java.util.Scanner;

public class LightX {
    public static void main(String args[]){
        Scanner number = new Scanner(System.in);
        
        int lightx = 0;

        System.out.println("What would you like the number to end on?");
        int num = number.nextInt();
        
        while (lightx <= num){
            System.out.println(lightx);
            lightx++;
        }
    }

}


This program takes the users input and makes a staircase with the number of steps as the user inputed.
Code:
import java.util.Scanner;

public class Stair {
    
    public static void main(String args[]) throws Exception {
        Scanner s = new Scanner(System.in);


        System.out.println("Number of stairs: ");
        int maxLines = s.nextInt();
        
        String stair = "";

        
        for(int n = maxLines; n > 0; n--) {
            
        stair += "*";
        System.out.println(stair);
        }
    }

}



Here is a program that encodes your message (By encoding I mean moving the character up one step in the ASCII chart.)
Code:
import java.util.Scanner;

public class Encode {
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        
        System.out.print("Input goes here: ");
        String word = s.nextLine();
        
        for(char a: word.toCharArray()){
            int w = a;
            w++;
            System.out.print(Character.toChars(w));
        }
    }
}


This one just takes the input (age) of the user, and the input (age) of the computer and tells you how much older you/it are compared to the other.
Code:
import java.util.Scanner;

public class Comp {
    public static void main(String args[]) {
        
        Scanner s = new Scanner(System.in);
        
        int userAge,compAge = 0;
        System.out.println("How old are you?");
        userAge = s.nextInt();
        
        System.out.println("How old is your computer?");
        compAge = s.nextInt();
        
        if(compAge > userAge){
            System.out.println("Your computer is " + (compAge - userAge) + " years older than you. Time for a new one.");
        } else {
            System.out.println("You are " + (userAge - compAge) + " years older than your computer.");
        }
    }
}


Computer price depreciation - This program basicly takes your input on how much the computer costs new, your input on how old it is, and your rate of depreciation and calculates how much it is worth now.
Code:
import java.util.Scanner;

public class Price {
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        
        int price,age,d = 0;
        
        System.out.println("How much did your computer cost new?");
        price = s.nextInt();
        
        System.out.println("How old is your computer? (In years)");
        age = s.nextInt();
        
        System.out.println("What is your depreciation rate?");
        d = s.nextInt();
        
        for(int compAge = age; compAge > 0; compAge--) {
            price /= d;
            
        }
        System.out.println("Your computer is worth $" + price);
    }
}


Ask the user for a string - The program shall sum up the ASCII values of each character of the input string and print the sum.
Code:
import java.util.Scanner;

public class Encode {
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        
        System.out.print("Input goes here: ");
        String word = s.nextLine();
            
        int w = 0;
            
        for(char a: word.toCharArray()){
            
            w += a;
            
        }
        System.out.println(w);
    }
}

Reply

RE: [Java] My Progress #2
Practice makes perfect Smile Nice work mate
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: [Java] My Progress #3
Update: Added the stair program.

Reply

RE: [Java] My Progress #4
Updated with the "encoder"

Reply

RE: [Java] My Progress #5
You are doing a lot. That will definitely help you getting better. It is cool that you come up with your own assignments.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Java] My Progress #6
Good job LightX! Keep going mate!
[Image: hacker10.jpg]

Reply

RE: [Java] My Progress #7
(02-27-2013, 11:12 AM)IDetox Wrote: Good job LightX! Keep going mate!

Thanks! Smile I really like java. Biggrin

Reply

RE: [Java] My Progress #8
I like it too .. because it needs enormous amount of coding Biggrin
Java <3 <3 <3
[Image: cooltext980231940.gif]

Reply

RE: [Java] My Progress #9
Good job. I like it how you challenge yourself with these little programs, keep it up and it will pay off!
[Image: 2YpkRjy.png]
The extremity is only the commencement of further progress.

Reply

RE: [Java] My Progress #10
Good job. I like it how you challenge yourself with these little programs, keep it up and it will pay off!
[Image: 2YpkRjy.png]
The extremity is only the commencement of further progress.

Reply







Users browsing this thread: 1 Guest(s)