Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Stock. java public class Stock { private String name; /ame of company private String symbol; //Symbol of company on Stock Exchange private double price; //price

image text in transcribedimage text in transcribedimage text in transcribed

Stock. java

public class Stock { private String name; /ame of company private String symbol; //Symbol of company on Stock Exchange private double price; //price per share private int shares; /umber of shares /** Constructor with name and symbol */ public Stock(String newName, String newSymbol) { name = newName; symbol = newSymbol; price = 0.0; shares = 0; } /** Get name of stock @return name of stock */ public String getName( ) { return name; } /** Get symbol of stock @return symbol of stock */ public String getSymbol( ) { return symbol; } /** Get price of stock @return price of stock */ public double getPrice( ) { return price; } /** Get number of shares @return number of shares */ public int getShares( ) { return shares; } /** Set price of shares @param newPrice price of shares */ public void setPrice(double newPrice) { price = newPrice; } /** Set number of shares @param newShares number of shares */ public void setShares(int newShares) { shares = newShares; } }

TradeStock.java

public class TradeStock { public static void main(String[] args) { //declarations Scanner in = new Scanner(System.in); String name; //Name of stock String symbol; //Symbol of stock double price; //price per share of stock int shares; /umber of shares of stock //Get name and symbol System.out.print("Enter name of stock: "); name = in.nextLine( ); System.out.print("Enter symbol of stock: "); symbol = in.nextLine( ); } //Instantiat Stock object with price and symbol Stock myStock = new Stock(name, symbol); //prompt user for price and set it System.out.print("Enter price of stock: "); price = in.nextDouble( ); while(in.nextDouble()) { if (price

Exercise 1 - Validating Stock Information (4 points) Must be completed during the lab period. 1. Download the file Lab07Starter.zip from myCourses and unzip to obtain two files named Stock.java and TradeStock.java. The class named Stock with the following attributes and methods: AttributeDescription name Name of stock as type String symbolSymbol for stock on appropriate stock exchange as type String Price of one share as type double Number of shares as type int price shares Parameters / Return Two parameters. First parameter is name Constructor to create a of stock. Second parameter is symbol for Stock object stock. No return type. Description Name Stock getName No parameters. Returns name of stock as Accessor for name getSymbol No parameters. Returns symbol of stock Accessor for symbol getPriceNo parameters. Returns price of stock asAccessor for price attribute. getShares No parameters. Returns number of setPriceOne parameter with new price of stock asMutator for price attribute. setShares One parameter with new number of attribute. type String. as type String. type double. shares as type int. type double. No return value. shares as type int. No return value. attribute. Accessor for shares attribute. Mutator for shares attribute. 2. The class TradeStock allows the user to enter the information for a stock, set the values, and then print them. Run the program a few times to understand how it works

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

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago