Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java - File IO and Interfaces Files: Test.java - Use this class to test your program Tickers.txt - Include this file in your project for

Java - File IO and Interfaces

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Files:

Test.java - Use this class to test your program

Tickers.txt - Include this file in your project for testing purposes

The following are example text files used to mock our services. Include these in your project.

NLPService.txt

UHStockService.txt

ExternalService.txt

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Test.java:

public class Test { public static void main(String[] args) { int numberOfTestsPassed = 0;

StockMachine machine = new StockMachine("Tickers.txt");

//Test 1 - getBestPriceFor() String price = machine.getBestPriceFor("AAPL");

if(price.equals("149.55")){ numberOfTestsPassed ++; System.out.println("Passed test 1- getBestPriceFor()"); } else{ System.out.println("Error testing getBestPriceFor() method!"); System.out.println("Checked: AAPL and expected: 149.55"); System.out.println("Answer received was: " + price); }

//Test 2 - getServiceWithHighestAvg() String serviceWithHighestAverage = machine.getServiceWithHighestAvg();

if(serviceWithHighestAverage.equals("UH")){ numberOfTestsPassed ++; System.out.println("Passed test 2- getServiceWithHighestAvg()"); } else{ System.out.println("Error testing getServiceWithHighestAvg() method!"); System.out.println("Expected: UH"); System.out.println("Answer received was: " + serviceWithHighestAverage); }

//Test 3 - getServiceWithLowestAvg() String serviceWithLowestAverage = machine.getServiceWithLowestAvg();

if(serviceWithLowestAverage.equals("External")){ numberOfTestsPassed ++; System.out.println("Passed test 3- getServiceWithLowestAvg()"); } else{ System.out.println("Error testing getServiceWithLowestAvg() method!"); System.out.println("Expected: External"); System.out.println("Answer received was: " + serviceWithLowestAverage); }

if(numberOfTestsPassed == 3) System.out.println(" Passed all Tests! Enjoy the weeknd. :)"); else System.out.println(" Error. You passed: " + numberOfTestsPassed + " of 3 tests.");

} }

21.7 HW 7 - File IO and Interfaces Homework 7: File IO and Interfaces Due on zyBooks Monday, November 12 2018 1 Objective For this assignment, students will practice interfaces, File I0, polymorphism, and inheritance. 2 Problem Write a Java program that performs operations on stock data. Instead of gathering live stock prices, we will mock our data using File I0. In order to do so, you will be given a file with stock ticker symbols and their corresponding prices. A stock ticker symbol uniquely describes a company's stock price (e.g. Apple has ticker symbol AAPL). When a company issues shares to the public marketplace, it selects an available ticker symbol for its securities that investors use to place trade orders. A tick is any change in the price. This change can be either an increase or decrease in the price. A stock ticker automatically displays these ticks, along with other relevant information, like volume, that investors use to stay informed about current market conditions. We will ignore all other information for this assignment and assume that what we read in our program is the current price The example below displays the contents of a file, Service1.txt AAPL 1.25 GOOG 122.4 MSET 22.3 ORCL 4.32 AMZN 123.4 INTC 4.53 XXYZ -2.50 Here, we can see the price for Apple (AAPL) is 1.25, the price for Google (GOOG) is 1224, Microsoft (MSFT) is 22.3, and so on. As can be seen, some of these prices may be negative. Handling such cases is outlined in section 3. To retrieve these prices from the market, we rely on several stock services. These stock services store prices and ticker symbols from the input file and return price for a given ticker symbol. You will have three stock services and each will return a price for a ticker. In other words, for each service, there will be a corresponding input file. We will use an interface, StockPriceService, to create a blueprint for our concrete classes: UHStockService, ExternalService, and NLPService. Moreover you will compare these services. You will perform operations on these services in a class called StockMachine. The constructor for StockMachine takes a name of a file as a parameter. Then, it reads a certain subset of ticker symbols from a given file and stores them in a private field. The input file will be in the following format: numofTickerSymbols -number of ticker symbols in the file TickerSymbol1 -ticker symbol TickerSymbol2- ticker symbol TickerSymbol3-ticker symbol 21.7 HW 7 - File IO and Interfaces Homework 7: File IO and Interfaces Due on zyBooks Monday, November 12 2018 1 Objective For this assignment, students will practice interfaces, File I0, polymorphism, and inheritance. 2 Problem Write a Java program that performs operations on stock data. Instead of gathering live stock prices, we will mock our data using File I0. In order to do so, you will be given a file with stock ticker symbols and their corresponding prices. A stock ticker symbol uniquely describes a company's stock price (e.g. Apple has ticker symbol AAPL). When a company issues shares to the public marketplace, it selects an available ticker symbol for its securities that investors use to place trade orders. A tick is any change in the price. This change can be either an increase or decrease in the price. A stock ticker automatically displays these ticks, along with other relevant information, like volume, that investors use to stay informed about current market conditions. We will ignore all other information for this assignment and assume that what we read in our program is the current price The example below displays the contents of a file, Service1.txt AAPL 1.25 GOOG 122.4 MSET 22.3 ORCL 4.32 AMZN 123.4 INTC 4.53 XXYZ -2.50 Here, we can see the price for Apple (AAPL) is 1.25, the price for Google (GOOG) is 1224, Microsoft (MSFT) is 22.3, and so on. As can be seen, some of these prices may be negative. Handling such cases is outlined in section 3. To retrieve these prices from the market, we rely on several stock services. These stock services store prices and ticker symbols from the input file and return price for a given ticker symbol. You will have three stock services and each will return a price for a ticker. In other words, for each service, there will be a corresponding input file. We will use an interface, StockPriceService, to create a blueprint for our concrete classes: UHStockService, ExternalService, and NLPService. Moreover you will compare these services. You will perform operations on these services in a class called StockMachine. The constructor for StockMachine takes a name of a file as a parameter. Then, it reads a certain subset of ticker symbols from a given file and stores them in a private field. The input file will be in the following format: numofTickerSymbols -number of ticker symbols in the file TickerSymbol1 -ticker symbol TickerSymbol2- ticker symbol TickerSymbol3-ticker symbol

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Organizing Your Speech Points

Answered: 1 week ago