i cant write java code very well

hey! i have started a java program but i cant type the codes well. we started with declaring variables and now on inheritance but i cant figure out which code comes after which please help me.give me the steps how i can write short applications and know the codes and understand it very well.
Thanks .paul ghana
16 answers Last reply
More about write java code
  1. Java applications are anything but short. They are overly redundant and wordy. I'm not understanding your problem. Can you provide an example to a problem that you are having? I can't teach you the entire Java language in this thread.
  2. google "java tutorial"
  3. codeacademy.com is a good website for learning to code.
  4. @Stealthinator: that's more web-related. For Java, codingbat.com is what I'd go with. :) It still won't teach OP inheritance, which was OP's concern. Still waiting for OP to reply.
  5. I think you should leave inheritance for a while and focus on more basic programming concepts. If a short (whatever that really means) application is what you are after, you probably won't need inheritance anyway.
  6. Thanks for your suggestions. i just want to understand how to declare a variable and declare a variable to hold 6 arrays
  7. 
    ArrayList<E> some_array = new ArrayList<E>();
    // E = type; so ArrayList<String> = Arrays of String.
    // You can have E = ArrayList for it to hold ArrayList instead
    
    some_array.add(<SOME_ITEM_OF_TYPE_E>); // do this 6 times
    


    That is as much as I can help with. Would be more useful to say what you're doing. Maybe using Arrays is not the best route.
  8. @Ksham thanks very much. can you send me your email address. this is the question i gave myself but i having chanllenges.
    Itemcode Itemname Amount Quantity
    C001 Rice 200.50 10
    C002 Milk 10.35 100
    C003 Cake 250.00 50
    C004 Coke 15.00 24
    C005 Milo 3.00 250

    Declare 1 dimensional array for each column and use it to display the row of items by their code.
    If you enter the item code, the item name, amount, and quantity should display.

    Paul Agyapong
    please help me.I was told that if i understand this, i will be able to tackle more java applications and even teach others.

    randomizer said:
    I think you should leave inheritance for a while and focus on more basic programming concepts. If a short (whatever that really means) application is what you are after, you probably won't need inheritance anyway.


    
    ArrayList<E> some_array = new ArrayList<E>();
    // E = type; so ArrayList<String> = Arrays of String.
    // You can have E = ArrayList for it to hold ArrayList instead
    
    some_array.add(<SOME_ITEM_OF_TYPE_E>); // do this 6 times
    


    That is as much as I can help with. Would be more useful to say what you're doing. Maybe using Arrays is not the best route.[/quotemsg
  9. Should use a database. But anyway, it's along the lines of this. It can be written better, but I'm just lazy.

    
    // I'm representing the numbers as a String -- just laziness.
    // Again, can be designed better.
    Hashtable<String, Hashtable<String, String>> items = new Hashtable<String, Hashtable<String, String>>();
    
    Hashtable<String, String> tmp = new Hashtable<String, String>();
    tmp.put("Itemname", "Rice");
    tmp.put("Amount", "200.50");
    tmp.put("Quantity", "10");
    
    items.put('C001', tmp);
    
    tmp.clear();
    
    // keep going
    
  10. Hey i have this code to program a calculator but i can run it.help me
    this is the code;


    package calculator;
    import java.util.Scanner;
    /**
    *
    * @author Libertydmi
    */
    public class TryCalcu {
    public static void main(String[] args){
    int a, b, answer;
    String operator;
    Scanner.s = new Scanner(System.in);

    log("enter any maths equation using +, -, *, or /:");
    a = s.nextInt();
    operator = s.next();
    b = s.nextInt();

    if (operator.contains("+")){
    answer = a + b;
    log("" + answer);
    }
    if (operator.contains("-")){
    answer = a - b;
    log("" + answer);
    }
    if (operator.contains("*")){
    answer = a * b;
    log("" + answer);
    }
    if (operator.contains("/")){
    answer = a / b;
    log("" + answer);
    }
    }
    public static void log(String get){
    System.out.println(s);

    }
    }






    ksham said:
    
    ArrayList<E> some_array = new ArrayList<E>();
    // E = type; so ArrayList<String> = Arrays of String.
    // You can have E = ArrayList for it to hold ArrayList instead
    
    some_array.add(<SOME_ITEM_OF_TYPE_E>); // do this 6 times
    


    That is as much as I can help with. Would be more useful to say what you're doing. Maybe using Arrays is not the best route.
  11. I don't see anything wrong with that code. What is your problem?
  12. The problem is this;
    Cannot find symbol.The variable s location; class Scanner.
    so the variable s is being underlined red. and due to that, it can't run the application.
    Any suggestion on that.Thanks.


    ksham said:
    I don't see anything wrong with that code. What is your problem?
  13. Ah.

    1. Replace the dot before the variable with a space.
    2. The last println method should use the variable "get" and not "s".
  14. Thanks for the help.The red signs is off but if i want to run any equation, it gives an error. it cant.why?


    ksham said:
    Ah.

    1. Replace the dot before the variable with a space.
    2. The last println method should use the variable "get" and not "s".
  15. Tokens are per line. Read the javadoc. Programming will require a lot of reading of documentation. Get used to it. :)
Ask a new question

Read More

Programming Java Apps