• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Java Beginner

 
Daniel Sheppard
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have an assignment that asks the following. If someone could give me some guidance it would be much appreciated. The professor only taught us what javax.swing.JOptionPane does but not how to execute it. I have never programmed so I don't even know where to start. The assignment reads:


Create a program that Asks users to enter an estimated dollar amount for monthly restaurant bill. (You can take
users’ input through the console using the Scanner class or through the input dialog box of
the javax.swing.JOptionPane class.)
 Decide the tip amount: Suppose that users usually give 18% tips, calculate the
corresponding tips for the estimated monthly restaurant bill.
 Decide the monthly IRA investment: Add the tips to the monthly restaurant bill and the total
will be the monthly IRA investment.
 Ask users to enter the number of years that they plan to save (invest) in this way. Again, you
can take users’ input through the console using the Scanner class or through the input
dialog box of the javax.swing.JOptionPane class.

This is the only part of the assignment I cannot figure out. We have a portion for Future Value but she taught that better. Thanks.
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel, welcome to Java Ranch!

You say you've never programmed before, so does that mean you don't know how to compile and execute Java code? If that's the case, then this assignment is definitely too hard for you. You will have to build up to it. A good place to start is the Java Tutorials page maintained by Oracle. You could run through the first three or four of them, then jump ahead to the one on Swing.
 
Daniel Sheppard
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue with the tutorial links you sent me is that they show something called JFrame. Are professor never taught us this option and told me that the whole thing must be completed within the source screen. My mind is literally blown because we were just taught this today:

public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

I don't see how one goes from this to that assignment.... do you?
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All your Swing components will be contained by a JFrame, so that's where you have to start. I agree it's a big leap to go from a "Hello, World" program to a GUI tip calculator in a single step. Does the class have prerequisites, or is it specifically targeted at people who want to learn on their own, but with a general guidance?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The assignment says you can use the console for input and output. That's far easier than a Swing GUI.
 
Daniel Sheppard
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its Intro to Business Programming. It has no prereqs...its the first step.
 
Carey Brown
Bartender
Posts: 2249
28
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TO THE MODERATOR - Op can and should use console IO for this project as this is simpler than digging in to swing. With that in mind I suggest moving this thread back to 'beginner'.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:TO THE MODERATOR - Op can and should use console IO for this project as this is simpler than digging in to swing. With that in mind I suggest moving this thread back to 'beginner'.

It's in both forums. It can be removed from Swing should the OP decide to go that way (recommended).

Complete aside: what lame course excepts a Swing GUI after introducing "Hello world"?
 
Brett Spell
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,

It is possible to do this without using a JFrame and reading the bill amount using JOptionPane can be done with about the same amount of code that it would take using Scanner.

Take a look at the documentation on JOptionPane, specifically showInputDialog() and then experiment with it. I should add, too, that although the documentation doesn't say it, you can (and in this case should) specify null for the parentComponent parameter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!