Question: Need help with fixing the percentage portion the 0.0% is suppose to show the change in percentage between the two number the method is in

Need help with fixing the percentage portion

the 0.0% is suppose to show the change in percentage between the two number

the method is in sthe stock package

Need help with fixing the percentage portion the 0.0% is suppose to

Here is my code it consists of 4 classes

Main class:

package BrokeragePkg;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.InputMismatchException;

import java.util.Scanner;

import javax.swing.JFileChooser;

import javax.swing.JOptionPane;

public class FinalProject_MainClass {

public static void main(String[] args) {

Brokerage brk = new Brokerage("Paine Webber");

JFileChooser fileOpenDlg = new JFileChooser();

int status = -1;

do {

status = fileOpenDlg.showOpenDialog(null);

if (status == JFileChooser.CANCEL_OPTION) {

JOptionPane.showMessageDialog(null,

"You've chosen to cancel the program. Exiting.");

System.exit(0);

}

} while (status != JFileChooser.APPROVE_OPTION);

int tmpPortID = -1;

int tmpInt = -1;

int numPortfolios = -1;

try {

File selectedFile = fileOpenDlg.getSelectedFile();

Scanner myScan = new Scanner(selectedFile);

while (myScan.hasNext()) {

tmpInt = myScan.nextInt();

if (tmpPortID != tmpInt) {

Portfolio p = new Portfolio();

p.setPortfolioID(tmpInt);

brk.portfolioList.add(p);

tmpPortID = tmpInt;

numPortfolios++;

}

Stock s = new Stock();

s.setSymbol(myScan.next());

s.setName(myScan.next());

s.setPreviousClosingPrice(myScan.nextInt());

s.setCurrentPrice(myScan.nextInt());

brk.portfolioList.get(numPortfolios).stockList.add(s);

}

System.out.println("Brokerage: " + brk.brokerageName);

for (Portfolio port : brk.portfolioList) {

System.out.println(" Portfolio ID: " + port.getPortfolioID()

+ " ");

for (int i = 0; i

System.out.print(port.stockList.get(i).getSymbol() + " ");

System.out.print(port.stockList.get(i).getName() + " ");

System.out.print(port.stockList.get(i).getPreviousClosingPrice() + " ");

System.out.print(port.stockList.get(i).getCurrentPrice() + " ");

System.out.println(port.stockList.get(i).changePercent() + "% ");

}

}

} catch (FileNotFoundException ex) {

JOptionPane.showMessageDialog(null, ex.getMessage() + " Exiting.");

} catch (InputMismatchException ex) {

JOptionPane.showMessageDialog(null, "Wrong file type selected."

+ " Exiting.");

}

}

}

Bokerage Package

package BrokeragePkg;

import java.util.ArrayList;

public class Brokerage {

String brokerageName;

ArrayList portfolioList;

Brokerage(String brokerageName) {

this.brokerageName = brokerageName;

portfolioList = new ArrayList();

}

public String getBrokerage() { return brokerageName; }

public void setterBrokerage(String brokerageName){ this.brokerageName = brokerageName; }

}

Portfolio package

package BrokeragePkg;

import java.util.ArrayList;

public class Portfolio {

ArrayList stockList;

private int portfolioID;

public void setPortfolioID(int id) { portfolioID = id; } public int getPortfolioID() { return portfolioID; }

public Portfolio() {

stockList = new ArrayList();

}

}

Stock PAckage

package BrokeragePkg;

public class Stock { private String symbol,name; private int previousClosingPrice, currentPrice;

public Stock() { symbol = " "; name = " "; previousClosingPrice = 0; currentPrice = 0; } public Stock(String symbol, String name) { symbol = symbol; name = name; } public String getSymbol() { return symbol; } public String getName() { return name; } public void setSymbol(String symbol1) { symbol = symbol1; } public void setName(String name1) { name = name1; } public int getPreviousClosingPrice() { return previousClosingPrice; } public int getCurrentPrice() { return currentPrice; } public void setPreviousClosingPrice(int price) { previousClosingPrice = price; } public void setCurrentPrice(int price) { currentPrice = price; } public double changePercent() { return (currentPrice - previousClosingPrice) / previousClosingPrice; }

}

un Brokerage: Paine Webber Portfolio ID: 445 GTC GwinTech 60 65 0.0% ITT ITTTech 22 23 0.0% GTH GATech 44 49 0.0% Portfolio ID: 988 XTC EXTREM 67 71 0.0% HVP HALVP 83 87 0.0% LAC LACTOSE 99 101 0.0% ZLK ZEBRALINES 77 87 0.0% VTA VITAPILL 91 99 0.0% Portfolio ID: 617 BKC BACKPCK 11 14 0.0% XXV EXCITEV 66 81 0.0% BUILD SUCCESSFUL (total time: 25 seconds)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!