Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    30
    Rep Power
    0

    Default 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default 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'.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Homework Assignment, Need some help
    By xdrazkalnytex in forum New To Java
    Replies: 3
    Last Post: 04-28-2012, 01:56 AM
  2. Homework assignment: NEED HELP Please.
    By cinderelladreams in forum New To Java
    Replies: 4
    Last Post: 04-27-2012, 08:06 PM
  3. Homework Assignment, Need some help
    By xdrazkalnytex in forum New To Java
    Replies: 17
    Last Post: 04-11-2012, 06:56 PM
  4. Replies: 7
    Last Post: 02-29-2012, 02:15 PM
  5. Calculator Program HELP NEEDED FAST! Homework assignment
    By SteroidalPsycho in forum New To Java
    Replies: 3
    Last Post: 03-05-2009, 05:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •