Super simple Conversation Program.

Posts 112 of 12 · Page 1 of 1
Super simple Conversation Program.
Code:
import java.io.*;

class Conversation {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int myAge = 15;
        System.out.println("What is your name?");
        String name = in.readLine();
        System.out.println("Your name is " + name + ", great name.");
        System.out.println("How old are you?");
        String age = in.readLine();
        System.out.println("You are " +age+".");
        System.out.print("If you added our ages together we would be" + (age + myAge) + " :)");
        System.out.println("What is your favorite hobbie?");
        String hobby = in.readLine();
        System.out.println("What do you like about " + hobby+"?");
        String otherHobby = in.readLine();
        System.out.println("So what you're saying about " + otherHobby + " is neat.");
        System.out.println("Well it was nice talking to you");
        System.out.println("Please rate this program 1 - 10");
        System.out.println("Type a number:");
        String rating  = in.readLine();
        int value = Integer.parseInt(rating); 
        if (value > 5)  {
            System.out.println("You voted: "+value+".");
        } else  {
            System.out.println("You voted: "+value+".");

        }
        System.out.println("End of program"); 
    }
}
Bro, this is good can you expain what this mean?
throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Quote Originally Posted by Richtextbox View Post
Bro, this is good can you expain what this mean?
throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
When you throw an exception, it means that the handling of a runtime error is passed off to the caller of the function which sent it, and no UI message or other such annoyance occurs. A BufferedReader is a class which is used to read a string of characters in from the console byte by byte and parse them into a String.
You seem to be around the same skill level as me, and if you are - hello!
Anyway, couldn't Scanner(in the java.util library) achieve the same thing as BufferedReader? I find Scanner more reliable than BufferedReader, as you don't have to parse into integers and that sort of stuff...
Quote Originally Posted by iknowlots View Post
You seem to be around the same skill level as me, and if you are - hello!
Anyway, couldn't Scanner(in the java.util library) achieve the same thing as BufferedReader? I find Scanner more reliable than BufferedReader, as you don't have to parse into integers and that sort of stuff...
They can both achieve the same thing, although I prefer to use javax.swing.JOptionPane.showInputDialog("prompt") method. It returns a string, but it is much better than console input IMO.
>.< i did this program as pratice for my java class last week lol...didnt know it was here heheheheh
Quote Originally Posted by yair View Post
>.< i did this program as pratice for my java class last week lol...didnt know it was here heheheheh
Lol me too.
As advice I recommend making a text adventure to help with learning if statements,objects,and classes.
Y U no use scanner keyboard!!!!
Any questions left concerning how to catch and throw exceptions and or use user-defined exceptions?
Quote Originally Posted by FLubz View Post
Any questions left concerning how to catch and throw exceptions and or use user-defined exceptions?
Dude, sorry but this is spam !
I find the scanner class a lot more convenient, and that's probably because I use it more often than the clunky Buffer class.
As much as I love buffered reader, scanner does a whole lot of job for me . Also now you might wanna grab in the output you give from a text file and manipulate using Arrays to make it more advanced
This code is really sloppy, or at least looks like it from thr mobile version. Space everything out.
Posts 112 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?