• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with assignment  RSS feed

 
Greenhorn
Posts: 1
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, this is the first time I've ever been on a forum or even posted a topic before. So go easy on me!

I'm having a lot of trouble wondering where to even being with my assignment. I've been off ill from school for a couple of months now and we have this assignment to hand in pretty soon. I just simply don't even know where to begin and I'm very new to programing (know how to do "Hello World"....)

But anyway, this is what I need to achieve:

You are required to write a program which carries out both string functions and number functions.

The system will have a menu which to present the user with three choices:

Option 1 — will generate a username in the format of first initial and last name. The user will be prompted to enter their first and last name.

Option 2 — will calculate the factorial of a number entered by the user. The factorial of a number is defined as the product of that number and the number which is one less than it and the number which is one less than that, etc. down to 1. For example, the factorial of 5 (or 5! as it is correctly written) is 5 * 4 * 3 * 2 * 1 = 120.

Note Output for printing the factorial should be in the format as below where the original number entered by the user is 5
5 * 4 * 3 * 2 * 1 = 120
Option 3 – QUIT


I'm not asking for anyone to do this assignment for me, I need to learn this material. I just need subtle hints of where to go

I apreciate all the help you can provide.
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac,
Welcome to CodeRanch!

To begin, try to make the menu. Try to do it in small steps. Accomplishing each of the things in this list in order is a small milestone that gets you progress towards your assignment:

1) Print statements to print the three options and a prompt for the user to enter a choice (you definitely know how to do this since you've done Hello World)
2) Read in the user's choice and print it out (did you learn about Scanner or another way to read input? Even if you were out sick, try to get the notes so you know what classes you are allowed to use)
3) If the user entered something that is not valid, print an error message
4) Write a loop that repeats the above until the user enters a valid number.

Once you get to this point, you'll have the plumbing of your program built and can start on options 1 and 2. If you get stuck on any of these steps, post a reply for more advice.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that this assignment is GUI oriented and that you do know how to design the Graphical User Interface (GUI). I can tell you the logic that'll help you program the three menu items.

Option 1:

- Make two text fields for the user to enter his/her first and last name, and appropriate labels for the text fields. Make a button for the user that says "Submit". Make a label under the submit button that says "Generated Username: " and make another label adjacent to the generatedUsername label which will be where we'll show the generated username in the next step.

- Set an Action Listener for the button. Override the Action Listener's actionPerformed method such that it stores the string inputs from both the text fields, creates a new string, parses the first-name string to get the first letter, and adds to it the last-name string in the new string, and finally sets the text of our last label to this new string.

Option 2:

I suggest that you read about 'Recursive methods in Java' and use a recursive method to get the factorial of any number.

Option 3:

Quitting should be easy. You can simply use System.exit() to quit.


I have just given you hints assuming that you know how to implement these steps in actual codes. If you do need more detail, please let me know, and I will respond soon.

Good Luck!
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sahaj and Welcome to the Ranch.

Thanks for trying to help the OP but I would imagine this not a GUI assignment. The wording and difficulty level of the question suggests a command line interface (CLI) will suffice. Jeanne has outlined the initial steps for a CLI but if you think you can add to her instructions please feel free to do so.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Issac Clarke wrote:Hi all, this is the first time I've ever been on a forum or even posted a topic before. So go easy on me!

We'll be gentle...and welcome to Java Ranch, Isaac.

I'm having a lot of trouble wondering where to even being with my assignment [...] this is what I need to achieve:

Well, for starters, read all the good advice Jeanne gave you.

Second: Don't panic. I suspect you're looking over those instructions and thinking "how on earth do I do all this?", because your mind is already leaping ahead to what the code is going to look like.

My advice (and it's a very difficult thing to do when you're starting out): DON'T.
Code is, oddly enough, one of the least important parts of a program - even if it doesn't seem like it right now - and it's also one of the last things you do.

It's actually perfectly possible to write a Java class without having the slightest idea HOW you're going to code it - and just one technique is described here.

But before you even do that, get out lots of paper and a few good pencils, and THINK. Draw diagrams; write down things you think you'll need to do, and the things you might need to do them; and do it all in English (or your native language). You need to understand a problem before you can write Java code to solve it.

And when you do start coding, follow Jeanne's advice: take things a piece at a time, compile often, and test very thoroughly before you move on to the next task.

You may also find the WhatNotHow (←click) page worth reading.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!