SilabGarza - RS Private Server  
Home Forum Play Register Store Market Highscores Mark Forums Read
Go Back   SilabGarza - RS Private Server > SilGar Media > Computers > Programming
Reload this Page Need java help asap!!


Need java help asap!!
Old
  (#1 (permalink))
Hanging On is Offline
Senior Member
image
 
Hanging On's Avatar
 
Posts: 3,028
Cookies Given: 4
Cookies Received: 209
Time Online: 33 d 18 h 24 m
   
Default Need java help asap!! - 09-11-2013, 08:51 PM

My stupid college requires everyone to take a coding class at some point.

I do not get any of this. I am just in need of guidance, as I cannot figure it out past this point.

Taking any help I can get.



Directions:

Write a program that will calculate the number of cents in a specific number of dimes
and nickels. The program will perform the following tasks:
[X]Ask the user to enter the number of dimes.
[X]Ask the user to enter the number of nickels.
[]Calculate the total number of cents.
[]Display to the monitor the number of cents.


Code:
import javax.swing.JOptionPane;

public class Pass2
{
   public static void main(String[]args)
   {
    
      System.out.println("Programming Assisgnment 2");
      
      String name;
name = JOptionPane.showInputDialog(
         "Number of Dimes?");
         
name = JOptionPane.showInputDialog(
         "Number of Nickels?");

} }

I cannot figure out how to get the numbers to add up.

Example:

Dimes = 0.10 each... Nickles = 0.05 each.

2 Dimes + 2 Nickles = 0.30


A few of my Achievements over the years:

[x] Admin
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod

[x] Forums Mod
[x] Forums Mod
[x] Forums Mod

[x] ChatBox Mod
[x] ChatBox Mod

Last edited by Hanging On; 09-11-2013 at 08:54 PM.
  
Old
  (#2 (permalink))
Gir is Offline
Owner of SilabGarza
image
 
Gir's Avatar
 
Posts: 18,447
Cookies Given: 93
Cookies Received: 1,463
Time Online: 53 d 13 h 54 m
Clan: The Forgotten
   
Default 09-11-2013, 09:20 PM

eh i never use jswing but here's a quick version of it

Code:
import javax.swing.JOptionPane;

public class Pass2 {
	public static void main(String[]args) {
		System.out.println("Programming Assisgnment 2");
		String dimeCounter;		//string for dimes
		String nickleCounter;		//string for nickles

		dimeCounter = JOptionPane.showInputDialog("Number of Dimes?");			//the string is set to whatever the field is sending
		nickleCounter = JOptionPane.showInputDialog("Number of Nickels?");		//same with this one, different string name so different string
		System.out.println("You currently have: "+dimeCounter+" dimes & "+nickleCounter+" nickles.");	//displays the strings

		int dimeInt = (int) String.toInt(dimeCounter);		//converts string into int for dimes
		int nickInt = (int) String.toInt(nickleCounter);	//converts string into int for nickles

		double totalAmount = 0.00;	//setting a double (an int that has a decimal value)

		totalAmount += (dimeInt * 0.10); //dime amount added
		totalAmount += (nickInt * 0.05); //nickles added

		System.out.println("You currently have $"+totalAmount+"!");
		

	}
}
some things are probably over complicated, not sure but i think you can use the option panels to send int's aswell


edit: here's cleaned up version

Code:
import javax.swing.JOptionPane;

public class Pass2 {
	public static void main(String[]args) {
		System.out.println("Programming Assisgnment 2");
		int dimeCounter;
		int nickleCounter;

		dimeCounter = Integer.parseInt(JOptionPane.showInputDialog("Number of Dimes?"));
		nickleCounter = Integer.parseInt(JOptionPane.showInputDialog("Number of Nickels?"));
		System.out.println("You currently have: "+dimeCounter+" dimes & "+nickleCounter+" nickles.");

		double totalAmount = 0.00;	//setting a double (an int that has a decimal value)

		totalAmount += (dimeCounter * 0.10); //dime amount added
		totalAmount += (nickleCounter * 0.05); //nickles added

		System.out.println("You currently have $"+totalAmount+"!");
		

	}
}
warning: use this as a reference, if you turn this in, your teacher might think you know what you're doing
  
The Following User Says Thank You to Gir For This Useful Post:
Hood Rat (09-13-2013)
Old
  (#3 (permalink))
Hanging On is Offline
Senior Member
image
 
Hanging On's Avatar
 
Posts: 3,028
Cookies Given: 4
Cookies Received: 209
Time Online: 33 d 18 h 24 m
   
Default 09-11-2013, 09:31 PM

Quote:
Originally Posted by Gir View Post

warning: use this as a reference, if you turn this in, your teacher might think you know what you're doing
I will, in class I couldn't even get words to display in front of him.

You've just saved my grade. Thank you very much!


A few of my Achievements over the years:

[x] Admin
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod

[x] Forums Mod
[x] Forums Mod
[x] Forums Mod

[x] ChatBox Mod
[x] ChatBox Mod
  
Old
  (#4 (permalink))
GoogleSlayer is Offline
Senior Member
image
 
GoogleSlayer's Avatar
 
Posts: 7,368
Cookies Given: 1,174
Cookies Received: 1,131
Time Online: 167 d 23 h 14 m
   
Default 09-12-2013, 05:03 AM

I had programming classes too, including Java, and currently PHP, but I'm very curious how your output is. Can you show me like a screenshot of the window? I'm probably very noob, I learned how to program that stuff into applets, like this:

Code:
  
   public void calculateButton_ActionPerformed(ActionEvent evt) {
    int nickels = Integer.parseInt(nickleField.getText());
    int dimes = Integer.parseInt(dimesField.getText());
    double totalNickelsAmmount = 0.00;  
    double totalDimesAmmount = 0.00;  
    totalDimesAmmount = (dimes * 0.10); 
    totalNickelsAmmount = (nickels * 0.05);
    int totalAmmount = (int) (100*(totalNickelsAmmount + totalDimesAmmount));
    ammountLabel.setText("You currently have " + String.valueOf(totalAmmount) + " cents in dimes and nickels.");
With a small applet looking like this:



Like I said, I have almost no knowledge, but this is how I learned it.
@Hanging On




My Steam Profile (from SteamDB)


~Gifts ~
Spoiler

Last edited by GoogleSlayer; 09-12-2013 at 05:22 AM.
  
Old
  (#5 (permalink))
D Kai V2 is Offline
Senior Member
image
 
D Kai V2's Avatar
 
Posts: 299
Cookies Given: 39
Cookies Received: 58
Time Online: 14 d 12 h 59 m
   
Default 09-12-2013, 05:09 AM

would it be easier just to use Scammer? It's a pretty basic task.


<3 Ervin is #1. <3


"New/updated content and small fixes do a lot for the server, even though they may seem small."
-Jokerjake72


  
Old
  (#6 (permalink))
Hanging On is Offline
Senior Member
image
 
Hanging On's Avatar
 
Posts: 3,028
Cookies Given: 4
Cookies Received: 209
Time Online: 33 d 18 h 24 m
   
Default 09-12-2013, 02:36 PM

With the help of Gir and Ahri, this is what the end result was:


@GoogleSlayer


A few of my Achievements over the years:

[x] Admin
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod
[x] Mod

[x] Forums Mod
[x] Forums Mod
[x] Forums Mod

[x] ChatBox Mod
[x] ChatBox Mod
  
Old
  (#7 (permalink))
GoogleSlayer is Offline
Senior Member
image
 
GoogleSlayer's Avatar
 
Posts: 7,368
Cookies Given: 1,174
Cookies Received: 1,131
Time Online: 167 d 23 h 14 m
   
Default 09-13-2013, 05:01 AM

Quote:
Originally Posted by Hanging On View Post
With the help of Gir and Ahri, this is what the end result was:


@GoogleSlayer
Ah alright, it was what I expected, though I have never programmed java that way.




My Steam Profile (from SteamDB)


~Gifts ~
Spoiler
  
adsense code2.3
Closed Thread

Bookmarks

Need java help asap!!

Programming




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
adsense2.6
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 06:35 PM.





Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.