Results 1 to 2 of 2
Thread: Homework Assignment
- 10-02-2012, 03:50 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 30
- Rep Power
- 0
Homework Assignment
I had to make a class and a test class. In the class I made 4 instance variables which are :
private String Company;
private int SharesHeld;
private int DollarPrice;
private int EighthsPrice;
I also made the the get and return methods. What this program is supposed to do is allow a user to input the company name, number of shares (stock), dollars, and eighths.
Example:
String Company = JOptionPane.showInputDialog
("Enter the name of the company") ;
String input = JOptionPane.showInputDialog
("Enter the number of shares") ;
int SharesHeld = Integer.parseInt(input) ;
System.out.println("The name of the company is: " + StockPortfolio.getCompany());
System.out.println("The number of shares are " +
StockPortfolio.getSharesHeld());
So let's say the user inputs Walmart as the company then my program will print Walmart. Similarly, if the user inputs 50 shares, the program prints 50.
My instructor said I had to create a method that modifies the stock price. This method has to have 2 int parameters which are the change in the dollar portion of the price and the change in the eighths portion of the price. I have this:
public void Change(int DollarChange, int EighthsChange)
{
int newDollarPrice = (DollarPrice + DollarChange) ;
DollarPrice = newDollarPrice;
int newEighthsPrice = (EighthsPrice + EighthsChange);
EighthsPrice = newEighthsPrice ;
This doesn't work because the user has to input the change in dollars and eighths and then my program supposed to print the amount. For example let's say the user input 37 for dollars and 5 for the eighths then my program prints out 37 5/8. I've gotten that far however the confusing part is this... The user supposed to type the change so lets say he inputs 7 for dollars and 2 for eighths then my program has to print out 44 7/8. How can I do this? I think I have to use the modifying method that has to be created in the class but I have no idea.. Can someone please help me. Thank you
- 10-02-2012, 06:51 AM #2
Re: Homework Assignment
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
Go through those and edit your post accordingly. To change the subject line, click 'Go advanced'.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Homework Assignment, Need some help
By xdrazkalnytex in forum New To JavaReplies: 3Last Post: 04-28-2012, 12:56 AM -
Homework assignment: NEED HELP Please.
By cinderelladreams in forum New To JavaReplies: 4Last Post: 04-27-2012, 07:06 PM -
Homework Assignment, Need some help
By xdrazkalnytex in forum New To JavaReplies: 17Last Post: 04-11-2012, 05:56 PM -
Need Help with Homework Lab Assignment on Loops and File Input/Output
By Terminus_Est in forum New To JavaReplies: 7Last Post: 02-29-2012, 01:15 PM -
Calculator Program HELP NEEDED FAST! Homework assignment
By SteroidalPsycho in forum New To JavaReplies: 3Last Post: 03-05-2009, 04:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks