i never thought anyone would reply , but after some modifications and some advice from my school teacher,
the program is still not complete and has some errors.i do not understand how does your (while myScanner.hasnext()) works. so i have 3 if branches making up the 3 choices,and yea in order to do number 2 i need to have inputs from number 1 .
/*Chin Zhi Qiang
*Computer programming Project
*/
import java.util.Scanner;
import java.text.*;
class ChinZhiQiang {//////Start of Class/////
static double capital = 100000.00;//starting capital
static int[] unitBought = new int[99];
static double[] unitPrice = new double[99];
static String[] stockName = new String[99];
static String[] stockSym = new String[99];
static String[] portFolioS = new String[99];
static Scanner myScanner = new Scanner(System.in);
static double cashLeft = 0.00;
static double totalStock = 0;
public static void main(String args[]){//Main Method
/***Variables***/
int count1 = 0;//assign value of portFolio() into counter
boolean mod = true;
int myInt = 0;
int choice,i;//choice prompt and for loop init
do
{
/////Menu/////
System.out.println("\tStock Portfolio\t");
System.out.println("======================================");
System.out.println("1) Select 1 to create stock portfolio.");
System.out.println("2) Select 2 to update share price.");
System.out.println("3) Select 3 to exit.");
/////Prompt Choice/////
System.out.println();
System.out.print("Please enter your choice(1 - 3): ");
choice = myScanner.nextInt();
System.out.println("-------------------------------");
if(choice == 1){
count1 = portFolio();
while(mod){
for( i = 0;i<count1;i++){
stockName[i] = portFolioStockName();
stockSym[i] = portFolioStockSym();
unitPrice[i] = portFolioUnitPrice();
unitBought[i] = portFolioUnitBought();
portFolioSummary(i);
System.out.print("If Ok, enter 0 else enter 1 to modify :");
myInt = myScanner.nextInt();
mod = (myInt != 0);
totalStock = unitPrice[i]*unitBought[i];
cashLeft = capital - totalStock;
}
}
System.out.println("---Accepted--- cash value left $:"+cashLeft);
}
if(choice == 2){
System.out.println("Here is your current list of stocks : \n");
System.out.print("\t\t\t\tBought Current Stock\n");
System.out.println("Stock Name\tSymbol\tUnits\tPrice\tPrice\tValue ");
System.out.print("----------\t------\t-----\t-----\t-----\t-----\n");
for(i = 0; i<count1;i++){
System.out.println(stockName[i]+"\t\t"+stockSym[i]+"\t"+unitBought[i]+"\t"+unitPrice[i]);
}
}
if(choice == 3){
for(i = 0;i<=count1;i++){
totalStock = unitBought[i]*unitPrice[i];
}
System.out.print("Current Stock Portfolio Worth\t"+totalStock);
System.out.println();
System.out.print("Cash = ");
System.out.println();
System.out.println("Total Worth = ");
System.out.println();
System.out.println("Thanks for using!");
System.out.println("**************************");
}
}while(choice <=3 && choice !=3);
}//End of Main method
static int portFolio(){//portFolio method
int stocks;
System.out.print("Number of stocks in your portfolio (max 99): ");
stocks = myScanner.nextInt();
System.out.println();//line break
return stocks;
}//End of portFolio Method
static String portFolioStockName(){//Start of portFolioInfo Method
boolean again = true;
String stockName;
do{
System.out.print("Please Enter Stock name ( between 8 and 14 characters ): ");
stockName = myScanner.next();
if(stockName.length()>14)
System.out.println("Only 14 letter max");
else{
again= false;
}
}while(again);
return stockName;
}//End of portFolioInfo Method
static String portFolioStockSym(){//Start of portFolioStockSym Method
boolean again = true;
String stockSym;
do{
System.out.print("Please Enter 3 or 4 letter stock symbol: ");
stockSym = myScanner.next();
if(stockSym.length()>4)
System.out.println("Only 4 letter max");
else{
again = false;
}
}while(again);
return stockSym;
}//End of portFolioStockSym method
static double portFolioUnitPrice(){//Start of portFolioUnitPrice method
double unitPrice;
System.out.print("Please Enter unit price: ");
unitPrice = myScanner.nextDouble();
return unitPrice;
}//End of portFolioUnitPrice Method
static int portFolioUnitBought(){//Start of portFolioUnitBought method
int unitBought;
System.out.print("Please Enter no. of units bought: ");
unitBought = myScanner.nextInt();
return unitBought;
}//End of portFolioUnitBought method
static void portFolioSummary(int i ){//Start of portFolioSummary method
System.out.println("You have entered: ");
System.out.println(stockName[i]+"\t"+stockSym[i]+"\t"+unitPrice[i]+" units\t"+"@ "+unitPrice[i]*unitBought[i]);
}//End of portFolioSummary method
}/////End of Class/////