Need some JAVA basic programming help
My teacher doesn't teach in my class jsut tells us to read the chapters and do homework. So I have no real understanding for java at all. I need someone to help me start a basic program and possibly guide me through. I am trying to teach myself which is difficult.
This is the question
Create the program below in as a Java file in TextPad.Write a program that asks 3 people (include your first name and the first names of 2 other people) to enter the name of the stock purchased (for example, IBM, Google, Microsoft, Coca Cola), the number of shares of stock purchased, and the price per share of stock purchased. Each person must pay his or her stock broker a 2 percent (.02) commission for his or her stock transaction. Request the input data from each person by using the appropriate JOptionPane dialog box. Create a formula to calculate stock value (hint: stock price per share * number of stock shares purchased), commission (hint: stock value * .02), and total amount paid for the stock (hint: stock value plus commission). Using the appropriate JOptionPane dialog box, display each person’s name, name of stock he or she purchased, the stock value, the amount of the stock commission, and the total amount paid for the stock.
Re: Need some JAVA basic programming help
Have you written any code yet? What questions do you have about your assignment?
Make a list of the steps the program must do and then write the code for the first step, compile it and execute it.
Fix the problems and go on to the second step.
Re: Need some JAVA basic programming help
Here is the question I am trying to answer....
Write a program that asks 3 people (include your first name and the first names of 2 other people) to enter the name of the stock purchased (for example, IBM, Google, Microsoft, Coca Cola), the number of shares of stock purchased, and the price per share of stock purchased. Each person must pay his or her stock broker a 2 percent (.02) commission for his or her stock transaction. Request the input data from each person by using the appropriate JOptionPane dialog box. Create a formula to calculate stock value (hint: stock price per share * number of stock shares purchased), commission (hint: stock value * .02), and total amount paid for the stock (hint: stock value plus commission). Using the appropriate JOptionPane dialog box, display each person’s name, name of stock he or she purchased, the stock value, the amount of the stock commission, and the total amount paid for the stock.
HTML Code:
public class Stock
{
public static void main(String[] args)
{
//Declare variables
int numberofShares = 0,priceperShare = 0,valueofShares=0;
double commission = 0.00; double totalStockcost = 0.00; double StockCom = 0.00;
//Ask for First and Last name
String name = "";
String Firstname = JOptionPane.showInputDialog(
null, "Please enter your first name: ");
String LastName = JOptionPane.showInputDialog(
null, "Please enter your last name: ");
//Create list string to call later
String list =
"1 for Apple \n"+
"2 for Microsoft \n"+
"3 for DELL \n";
//Ask for the number corresponding to the Stock
String s2 = JOptionPane.showInputDialog(null, "Please pick a number corresponding to the stock that you bought: \n " + list);
;
String s3= JOptionPane.showInputDialog(null, "Number of Stock Purchased");
}
}
So I have gotten where I can input all the information, but my problem is converting the Apple or Dell stock to an actual numerical value. So that I can multiply that value, by the amount purchased to figure out total spent on stock..
Re: Need some JAVA basic programming help
Quote:
my problem is converting the Apple or Dell stock to an actual numerical value
What is a "stock"? Is it a String containing numeric digits?
See the API doc for the Integer class, it has a static method for converting a String to an int value.
Re: Need some JAVA basic programming help
What? I am very new to java only been using it for a week. I have no idea what any of that means.
Re: Need some JAVA basic programming help
Which part don't you understand?
String
numeric digits
int
convert String to int
Integer class
static method
API doc
Here is a link to the API doc. You should save it and use it often. I use it many times a day.
http://download.oracle.com/docs/cd/E...se/6/docs/api/
Find the name of the class in the lower left, click it and the doc will be shown in the main frame.
Re: Need some JAVA basic programming help
API has not been taught to be yet therefore I cannot use it. I am only suppose to use chapter 1 and 2 in my text book.
Re: Need some JAVA basic programming help
I just want to say apple= 1$ if that makes sense or DELL= 2 etc,,, so that I can use those to multiple
Re: Need some JAVA basic programming help
Then look in chapters 1 & 2 for the classes and methods you need.
Re: Need some JAVA basic programming help
I dont understand them....
Re: Need some JAVA basic programming help
What classes and methods are in the textbook?
Re: Need some JAVA basic programming help
I can not see your textbook so you will have to be the one to read it.