• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

AnswerTeller

Get the Answer!

  • APPEARANCE
    • Hair
    • Skin
      • Tattoo
      • Piercing
    • Breasts
    • Makeup
    • Clothing
      • Lingerie
    • Shoes
    • Fashion
  • RELATIONS
    • Dating
    • Love
    • Friendship
    • Sex
    • Family
      • Husband
      • Wife
      • Parents
      • Brother
      • Sister
      • Children
    • Marriage
    • Divorce
    • Teenagers
    • Gifts
  • HOME
    • House
    • Apartment
    • Renting
    • Cooking
    • Garden
    • Pets and Animals
    • Car
    • Bikes
  • HEALTH
    • Maternity
  • LEARNING
    • School
    • College
    • University
    • Education
    • Exams
    • Maths
      • Algebra
      • Geometry
    • Physics
    • Chemistry
    • Anatomy
    • Quiz
  • KNOWLEDGE
    • Life
    • Religion
      • Bible
    • Books
    • History
    • Law
      • Crime
    • Science
    • Economics
    • Politics
    • International
    • Languages
  • WORK
    • Careers
    • Jobs
    • Interview
    • Business
    • Real Estate
    • Office
  • MONEY
    • Credit
    • Loan
    • Buying
    • Selling
    • Shopping
    • Insurance
    • Taxes
    • Stocks
    • E-Money
    • Gambling
    • Scam
  • LEISURE
    • Entertainment
      • Home Cinema
    • Celebrities
    • Sports
    • Movies
    • Music
    • Dancing
      • Ballet
    • Dining Out
      • Restaurants
      • Fast Food
    • Vacations
    • Holidays
      • Christmas
      • New Year
      • Easter
      • Halloween
    • Photography
  • TRAVEL
    • Accommodation
      • Hotels
      • Motels
    • Flights
    • Airlines
    • Trains
  • TRIVIA
    • Fortune
      • Horoscope
    • How To
    • How Do I
    • Puzzle
    • Quiz
    • Miscellaneous
Browse: Home / COMPUTER / Software

JAVA having trouble with a program of mine?

NEEDSHELP: JAVA having trouble with a program of mine?
// program to allow tracking of stock orders

//enabling JOptionPane
import javax.swing.JOptionPane ;

//beginning of class
public class Assignment3
{
//beginning of method main
public static void main(String args[])
{
//declaring variables
int numberOfShares ,
nOrderCounter ,
aOrderCounter ,
totalNShares ,
totalAShares ;

double averageNSharesPerOrder ,
averageASharesPerOrder ;

String numberOfSharesAsString ;
String exchangeNameAsString ;

//initializing variables
nOrderCounter = 0 ;
aOrderCounter = 0 ;
totalNShares = 0 ;
totalAShares = 0 ;

//ask for number of shares
numberOfSharesAsString = JOptionPane.showInputDialog
(null,
“Enter number of shares you wish to deposit” +
” (enter 0 or less to end)” ,
JOptionPane.QUESTION_MESSAGE) ;
numberOfShares = Integer.parseInt (numberOfSharesAsString) ;

//pull out first letter of exchange name
char c ;

//begin loop
while (numberOfShares > 0)
{
//ask for name of stock exchange again
exchangeNameAsString = JOptionPane.showInputDialog
(null,
“Enter desired exchange destination (NYSE or ASE)” ,
JOptionPane.QUESTION_MESSAGE) ;
c = exchangeNameAsString.charAt(0) ;

if ((c == ‘n’) || (c == ‘N’))
{
nOrderCounter = nOrderCounter + 1 ;
totalNShares = numberOfShares + totalNShares ;
}
else if ((c == ‘a’) || (c == ‘A’))
{
aOrderCounter = aOrderCounter +1 ;
totalAShares = numberOfShares + totalAShares ;
}
else
JOptionPane.showMessageDialog
(null,
“ERROR: not a valid exchange”) ;

//ask for number of shares again
numberOfSharesAsString = JOptionPane.showInputDialog
(null,”Enter number of shares (enter 0 or less to end)” ,
JOptionPane.QUESTION_MESSAGE) ;
numberOfShares = Integer.parseInt (numberOfSharesAsString) ;

}//end of while loop

//calculating the averages
averageNSharesPerOrder = (double) totalNShares / nOrderCounter ;
averageASharesPerOrder = (double) totalAShares / aOrderCounter ;

//print all info
if ((totalNShares > 0) || (totalAShares > 0))
{
JOptionPane.showMessageDialog
(null,
“NYSE:\n”
+ “You have ”
+ nOrderCounter + ” orders ”
+ totalNShares + ” shares ”
+ averageNSharesPerOrder + ” shares per order ”
+ “\nASE:\n”
+ “You have ”
+ aOrderCounter + ” orders ”
+ totalAShares + ” shares ”
+ averageASharesPerOrder + ” shares per order “) ;
}//end of info printing
else
JOptionPane.showMessageDialog
(null, “You did not enter any shares”) ;

//end
System.exit(0) ;

}//end of method main
}//end of class

the program has a 3 in the input box when i run it…does it do the same for you guys? and if so how do u fix it? id appreciate the help
also could someone tell me how to make an error message icon appear for my error messages with JOptionPane?

Answers and Views:

Answer by rascalflattsrule
You’re missing something here. After to end)”, you need to put “Input”

numberOfSharesAsString = JOptionPane.showInputDialog
(null,
“Enter number of shares you wish to deposit” +
” (enter 0 or less to end)” ,
JOptionPane.QUESTION_MESSAGE) ;

So like this instead:

numberOfSharesAsString = JOptionPane.showInputDialog
(null,
“Enter number of shares you wish to deposit” +
” (enter 0 or less to end)”,”Input”,
JOptionPane.QUESTION_MESSAGE);

Related Questions:

  • 1.  What can I do if I think a spammer has hijacked my computer?
  • 2.  Cant get Rid of PWS-WebMoney.gen Trojan any suggestions????
  • 3.  How do I transfer movies from itunes to my ipod video?
  • 4.  How do I transfer music from one iTunes list to another?

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Categories

  • APPEARANCE
    • Breasts
    • Clothing
      • Lingerie
    • Fashion
    • Hair
    • Makeup
    • Shoes
    • Skin
      • Piercing
      • Tattoo
  • COMPUTER
    • Computing
    • Hardware
    • Internet
      • Google
      • Networking
      • Spam
      • Yahoo
    • Microsoft
    • Programming
    • Software
  • HEALTH
    • Maternity
  • HOME
    • Apartment
    • Bikes
    • Car
    • Cooking
    • Garden
    • House
    • Pets and Animals
    • Renting
  • KNOWLEDGE
    • Books
    • Economics
    • History
    • International
    • Languages
    • Law
      • Crime
    • Life
    • Politics
    • Religion
      • Bible
    • Science
  • LEARNING
    • Anatomy
    • Chemistry
    • College
    • Education
    • Exams
    • Maths
      • Algebra
      • Geometry
    • Physics
    • School
    • University
  • LEISURE
    • Celebrities
    • Dancing
      • Ballet
    • Dining Out
      • Fast Food
      • Restaurants
    • Entertainment
      • Home Cinema
    • Holidays
      • Christmas
      • Easter
      • Halloween
      • New Year
    • Movies
    • Music
    • Photography
    • Sports
    • Vacations
  • MONEY
    • Buying
    • Credit
    • E-Money
    • Gambling
    • Insurance
    • Loan
    • Scam
    • Selling
    • Shopping
    • Stocks
    • Taxes
  • Popular Questions
  • RELATIONS
    • Dating
    • Divorce
    • Family
      • Brother
      • Children
      • Husband
      • Parents
      • Sister
      • Wife
    • Friendship
    • Gifts
    • Love
    • Marriage
    • Sex
    • Teenagers
  • TRAVEL
    • Accommodation
      • Hotels
      • Motels
    • Airlines
    • Flights
    • Trains
  • TRIVIA
    • Fortune
    • Horoscope
    • How Do I
    • How To
    • Miscellaneous
    • Puzzle
    • Quiz
  • WORK
    • Business
    • Careers
    • Interview
    • Jobs
    • Office
    • Real Estate

Search for More!

Copyright AnswerTeller © 2025 · About · Privacy Policy · Contacts · Sitemap Disclaimer: AnswerTeller.com is an informational website, and its content does not constitute professional advice of any kind. As an Amazon Associate, we earn from qualifying purchases.