[quote=mystic rain;#3643504;1277915955]corrections about my program are well appreciated or in other words your help.[/quote]
Great!! you almost got it right!

All you need is practice to have a better looking and error free programs

First question I would like to ask...
[b]Did you run your sample program? and find it working?[/b]
The best way to create good programs is to start in trial and error basis

most programmers start that way... even I always do this until now

So I guess it would be much better if you have your computer with you to run those codes

one error I found in your code is this
[quote]int numberOfItems=[b]lol[/b].nextInt();[/quote]
where did you get lol? hehe... anyways, its ok... coz you are still starting you progress

but if you have your pc with you and compiled your codes... you can easily see errors

[b]NEXT:[/b]
Part of being a programmer is to write their codes in a much cleaner.. and readable way...
and you are doing great on that!

APLAUSE!
however, you still need to practice code conventions. putting constant variables in your class

Since you have constant items and prices... I think you need to put them in the class as its variables.
here is an example:
[quote]import java.util.Scanner;
import java.util.Arrays;
public class Practice {
final String [] items = {"Jacket","Pants","Blouse","Bag","Shoes"};
final Double [] prices = {10.00,25.00,35.00,15.00,5.00};
public static void main(String [] args){
// your codes here later on
}
}[/quote]
A much cleaner code aint it?

[b]NEXT:[/b]
If you create a class... that has some process.. or there will be functionality for a class
in OOP terms... method.. you need to create one if it will perform a process.
So, since this class will have some processes:
-display items
-get input item
-get item quantity
-get item Total Price
Then you need to create methods.
The methods will be [b]displayItems[/b], [b]getInputItem[/b], [b]getItemQuantity[/b], [b]getTotal[/b]
[quote]import java.util.Scanner;
import java.util.Arrays;
public class Practice {
final String [] items = {"Jacket","Pants","Blouse","Bag","Shoes"};
final Double [] prices = {10.00,25.00,35.00,15.00,5.00};
Scanner inputted=new Scanner(System.in);
public static void main(String [] args){
// your codes here later on
}
public void displayItems() {
// your codes here to display the items
}
public String getInputItem() {
// your codes here to get input
}
public int getItemQuantity() {
// your codes here to get the item quantity
}
public Double getTotal() {
// your codes here to get the Total
}
}[/quote]
[i]You asked: [/i]Why do we need to create methods? and how can we identify them?
[i]Answer:[/i] We need to create methods in order to re-use them... for example... in your code... you need to ask another item again.. then you can re-use that method to get an item. How do we identify them? Simple.. just know what you need to do... or the process that was involved in your program

[b]NEXT:[/b]
In the void Main, you need to fill it up first... then you will know what those methods will do.
It will have a series of method calls to make your program work
[quote]import java.util.Scanner;
import java.util.Arrays;
public class Practice {
final String [] items = {"Jacket","Pants","Blouse","Bag","Shoes"};
final Double [] prices = {10.00,25.00,35.00,15.00,5.00};
Scanner inputted=new Scanner(System.in);
public static void main(String [] args){
displayItems(); // display the items
String itemSelected = getInputItem(); // selected by user
int howMany = getItemQuantity(); // will get quantity
Double total = getTotal(itemSelected, howMany);
System.out.println("The total price would be: "+total);
}
public void displayItems() {
// your codes here to display the items
}
public String getInputItem() {
// your codes here to get input
}
public int getItemQuantity() {
// your codes here to get the item quantity
}
public Double getTotal(String itemName, int quantity) {
// your codes here to get the Total
}
}[/quote]
[b]NEXT:[/b]
Since you already have the structure of the Class and its method.. Then you are ready to fill-in the BLANKS for your program to work

I know you can do it on your own... so I leave that work to you

Just replace those comment tags with your codes and it should be working great!
If you got any questions... please feel free to post it here

Thank you

My own version of this program:
<">
Last edited by nanix84 (2010-07-03 00:35:31)