i decided to use vectors here it the code

code :
Code:
import java.io.*;
import java.util.*;

public class Cw1{ 
    
	//Section 1: global variables
	
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static String input,code,desc, weight,cost,amount;
	static float TotalWeight = 0.0f,TotalCost = 0.0f,grandTotalWeight=0.0f,grandTotalCost=0.0f;
	static boolean isItemCode = false,isItemDesc = false,isItemWeight = false,isItemCost = false,isItemAmount = false;
	
	public static void main(String[ ] args) throws Exception{
	// Section 2 - Welcome message
	System.out.println("*****************************");
	System.out.println("** Welcome to  Trekker     **");
	System.out.println("*****************************");
	
	// Section 3 - Loop that prompts for order information,
    // tests if it is valid, prints it in a summary	
	// and stores it in a vector until user is done
	
	Vector v = new Vector();
	do{
		System.out.println("Enter Item code");	
 	
		input = br.readLine();
		code = input;						
	
	System.out.println("Enter Item Description"); 
 	do{
		input = br.readLine();
		desc = input;
		isItemDesc = isDescCorrect(input);		
	}
	while(!isItemDesc);

	System.out.println("Enter Item weight");
 	do{
		input = br.readLine();	
		weight = input;
		isItemWeight = isItemWeightCorrect(input);	
	}
	while(!isItemWeight);
		
	System.out.println("Enter Item cost");
 	do{
		input = br.readLine();
		cost = input;
		isItemCost = isItemCostCorrect(input);
	}
	while(!isItemCost);
	
		System.out.println("Enter Item amount");
 	do{
		input = br.readLine();
		amount = input;
		isItemAmount = isItemAmountCorrect(input);
	}
	while(!isItemAmount);
	
    Items myItems = new Items(code, desc, Float.parseFloat(weight), Float.parseFloat(cost), Integer.parseInt(amount),TotalCost);
	// print summary for item
	System.out.println("SUMMARY DATA FOR ITEM "+myItems.getItemCode()+", "+desc);
	TotalWeight = calculateTotalWeight(Float.parseFloat(weight),Integer.parseInt(amount));
	System.out.println("TOTAL WEIGHT: "+TotalWeight+" grams");
	TotalCost = calculateTotalCost(Float.parseFloat(cost),Integer.parseInt(amount));
	System.out.println("TOTAL COST: $"+TotalCost);
	
	// Section 5 - store user input in vector
	v.add(myItems);
		
	grandTotalWeight=grandTotalWeight+TotalWeight;
	grandTotalCost=grandTotalCost+TotalCost;
	
	System.out.println("");
	System.out.println("Would you like to add another item?");
	System.out.println("Please type Y or y for yes");
		input = br.readLine();
		if(input.equals("Y")||input.equals("y")){
			System.out.println("");
		}else{
			System.out.println("You have ordered");
			for(int i =0; i<v.size(); i++){
				System.out.print(((Items)v.elementAt(i)).getItemAmount()+" ");
				System.out.print(((Items)v.elementAt(i)).getItemDesc()+" ");
				System.out.print("("+((Items)v.elementAt(i)).getItemCode()+") ");
				System.out.print("@"+" ");
				System.out.print("$"+((Items)v.elementAt(i)).getItemCost()+" ");
				System.out.println("TOTAL COST $"+((Items)v.elementAt(i)).getItemTotalCost());
			}//close for loop
			System.out.println("GRAND TOTAL WEIGHT:"+grandTotalWeight+" grams");
			System.out.println("GRAND TOTAL COST: $"+grandTotalCost);
			System.out.println("Good bye");
			break;
		}//close else
	}//close outer do loop
	while(true);
	System.exit(0);
   	}//close main
    	
	// SECTION 4 METHODS

	
	public static boolean isDescCorrect(String itemDescription){
		if(itemDescription.equals("")||itemDescription.equals(" ")){
			System.out.println("Invalid Item,please re-enter Item.");				
			return false;
		}else{			
			return true;
		}
	}
		
	public static float calculateTotalWeight(float itemWeight, int itemAmount){
		float totalWeight = itemWeight * itemAmount;
		return totalWeight;
	}
		
	public static float calculateTotalCost(float itemCost, int itemAmount){
		float totalCost = itemCost * itemAmount;
		return totalCost;
	}
	public static boolean isItemWeightCorrect(String ItemWeight){
			float ItemWt=Float.parseFloat(ItemWeight);
			if(ItemWt <= 0){
				System.out.println("Please re-enter weight,cannot be less than or equal to 0");				
				return false;
			}else{			
				return true;
			
		}
	}
	public static boolean isItemCostCorrect(String ItemCost){
			float ItemCst=Float.parseFloat(ItemCost);
			if(ItemCst <= 0){
				System.out.println("Please re-enter cost,cannot be less than or equal to 0");				
				return false;
			}else{			
				return true;
		    }
	}
	public static boolean isItemAmountCorrect(String ItemAmount){
			int ItemAmt=Integer.parseInt(ItemAmount);
			if(ItemAmt <= 0){
				System.out.println("Please re-enter items required,cannot be less than or equal to zero");				
				return false;
			}else{			
				return true;
			}
	}
}
only problem is in the grand total cost for the first item it prints zero for the second item it prints the first grand total. what am i doing wrong?

Last edited by shabbir; 11Jan2010 at 10:38.. Reason: Code Block