Hi, I need some help with some method in my classes. I started on some if not all of them. I just cant seem to find what im doing wrong here. Any help would be greatly excepted. Thanks
Here is code:
[B][LEFT]import[/LEFT]
[/B]
[LEFT]java.util.Scanner;[/LEFT]
[B][LEFT]public[/LEFT]
[/B]
[LEFT][B]class[/B] Assignment3[/LEFT]
[LEFT]{
[B]public[/B] [B]static[/B] [B]void[/B] main(String args[])
{
Scanner scan = [B]new[/B] Scanner(System.[I]in[/I]);[/LEFT]
[LEFT]System.[I]out[/I].println("Enter the name of the stock:");
String name = scan.nextLine();[/LEFT]
[LEFT]System.[I]out[/I].println("Enter the symbol of the stock:");
String symbol = scan.next();[/LEFT]
[LEFT]Stock stock = [B]new[/B] Stock(name, symbol);[/LEFT]
[LEFT]System.[I]out[/I].println("Enter the quantity of stock purchased (-1 to quit):");
[B]int[/B] quantity = scan.nextInt();[/LEFT]
[LEFT][B]while[/B] (quantity > 0)
{
System.[I]out[/I].println("Enter the price of the stock purchased:");
[B]double[/B] price = scan.nextDouble();[/LEFT]
[LEFT]Purchase purchase = [B]new[/B] Purchase(quantity, price);
stock.addPurchase(purchase);[/LEFT]
[LEFT]System.[I]out[/I].println("Enter the quantity of stock purchased (-1 to quit):");
quantity = scan.nextInt();
}[/LEFT]
[LEFT]System.[I]out[/I].println("Enter the current stock price:");
[B]double[/B] currentPrice = scan.nextDouble();
stock.printReport(currentPrice);
}
}
==========================================[/LEFT]
[B][LEFT]import[/LEFT]
[/B]
[LEFT]java.math.BigDecimal;[/LEFT]
[B][LEFT]public[/LEFT]
[/B]
[LEFT][B]class[/B] Purchase [/LEFT]
[LEFT]{
[B]private[/B] BigDecimal m_quantity;
[B]private[/B] BigDecimal m_price;[/LEFT]
[LEFT][B]public[/B] Purchase([B]int[/B] quantity, [B]double[/B] price)
{
quantity = 0;
price = 0;
}[/LEFT]
[LEFT][B]public[/B] [B]int[/B] getQuantity()
{
[B]int[/B] quantity = m_quantity.intValue();
[B]return[/B] quantity;[/LEFT]
[LEFT]}[/LEFT]
[LEFT][B]public[/B] [B]double[/B] getPrice()
{
[B]double[/B] price = m_price.doubleValue();
[B]return[/B] price;
}[/LEFT]
[LEFT][B]public[/B] [B]double[/B] getCost()
{
BigDecimal c = m_quantity.multiply(m_price);
[B]double[/B] cost = c.doubleValue();
[B]return[/B] cost;
}[/LEFT]
[LEFT]/* public double getCostAtPrice()[/LEFT]
[LEFT]{
BigDecimal c2 = m_quantity.multiply(******);
double cost2 = c2.doubleValue();[/LEFT]
[LEFT]return cost2;
}[/LEFT]
[LEFT]public double getGainAtPrice(double price)
{
BigDecimal c = m_quantity.multiply(m_price);
BigDecimal c2 = m_quantity.multiply(******);
double gain = c.doubleValue()- c2.doubleValue();
return gain;
}
*/[/LEFT]
}
=========================================
[B][LEFT]import[/LEFT]
[/B]
[LEFT]java.util.ArrayList;[/LEFT]
[B][LEFT]public[/LEFT]
[/B]
[LEFT][B]class[/B] Stock[/LEFT]
[LEFT]{
[B]private[/B] String m_name = [B]null[/B];
[B]private[/B] String m_symbol = [B]null[/B];
[B]private[/B] ArrayList<Purchase> m_purchases; [/LEFT]
[LEFT][B]public[/B] Stock(String name, String symbol)
{
m_name = name;
m_symbol = symbol;
m_purchases = [B]new[/B] ArrayList<Purchase>();
}
[B]public[/B] String getName()
{
[B]return[/B] m_name;
}
[B]public[/B] String getSymbol()
{
[B]return[/B] m_symbol;
}[/LEFT]
[LEFT][B]public[/B] [B]void[/B] addPurchase(Purchase p)
{
m_purchases.add(p);
}
[B]public[/B] [B]double[/B] calculateGain([B]double[/B] price)
{
[B]for[/B] (Purchase p : m_purchases)
{
price = price + price;[/LEFT]
[LEFT]}
[B]return[/B] price;
}
[B]public[/B] [B]void[/B] printReport([B]double[/B] price)
{[/LEFT]
[LEFT]System.[I]out[/I].println("");
System.[I]out[/I].printf("-----------------------------------------------------%n");
System.[I]out[/I].printf("Report for %s (%s) @$%s/share %n",m_name, m_symbol,price );
System.[I]out[/I].printf("-----------------------------------------------------%n");
System.[I]out[/I].printf("%-15s%-15s%-15s%-15s%n" ,"Qty","Price","Cost","Gain");[/LEFT]
[LEFT]System.[I]out[/I].printf("-----------------------------------------------------%n");
System.[I]out[/I].printf("%-45s%-15s%n" ,"Total Gain:","$",calculateGain(price));
} [/LEFT]
}
Im not worry about the output. I know how to do that part but the methods is what i need help on....again thanks