i cant write java code very well

Paul Agyapong

Honorable
May 24, 2013
7
0
10,510
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
 

ksham

Honorable
Mar 29, 2013
175
0
10,760
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.
 

ksham

Honorable
Mar 29, 2013
175
0
10,760
@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.
 

ksham

Honorable
Mar 29, 2013
175
0
10,760
Code:
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.
 

Paul Agyapong

Honorable
May 24, 2013
7
0
10,510
@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.



 

ksham

Honorable
Mar 29, 2013
175
0
10,760
Should use a database. But anyway, it's along the lines of this. It can be written better, but I'm just lazy.

Code:
// 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
 

Paul Agyapong

Honorable
May 24, 2013
7
0
10,510
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);

}
}









 

Paul Agyapong

Honorable
May 24, 2013
7
0
10,510
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.






 

Paul Agyapong

Honorable
May 24, 2013
7
0
10,510
Thanks for the help.The red signs is off but if i want to run any equation, it gives an error. it cant.why?