• Post Reply Bookmark Topic Watch Topic
  • New Topic

store a state of a project  RSS feed

 
Daryl Frisbee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I am taking an class in virtual college on Android App. And I have to know Java. Yea I know, But its to late for me to drop out and get any money back.

The instructor gave me 1 assignment 2 weeks ago, the Hello World program. We had to build it. Ok no problem.

Last week we got this assignment... ( remember the hello world is the only code I have ever written in java)

Assignment 3

Write a basic Java program that will implement one class to store a state of a project.

The class should have one property to store a textual name of the state.

When a object of this class is created the initial state should be "Open".

1) Class should have one method next() which will move the project to the next step in the sequence: Open - In progress - Closed.

If next method is called for a project in the Closed state it should do nothing.

2) Class should have a method close() which will move the project into the Closed state.

3) Class should have a method print() that will output a current state of the project.

Submit a java code file as your assignment.

Do not hesitate to contact me if you have any troubles with the assignment.


I have been working on this thing for almost a week, and really don't have a clue on what to do. I know I have to use a string = open, and I know I have to create an object. But man, could someone please help me out here, with some kind of example to use. I have emailed the teacher several times, and get the response of I really want to help you, but you need to learn this on your own. I don't have a clue on how to do this. I have read the chapter so many times, I almost memorized it, but what he wants is nothing like our demo in the book. the Book used set and get, and utility scanner, but he doesn't want any of that. Just a basic code that will move from Open --- in progress --- closed.

The best I can tell what he wants is when I set the object to open it will display " project is open", then when I set it to " in progress" it will read project is "in progress". I don't have a clue what close is suppose to do, or the print method.

I'm sorry for such a long post, but I'm at my end, and this thing is due tomorrow evening at midnight.

Thanks
Daryl
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66305
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Daryl Frisbee wrote:Do not hesitate to contact me if you have any troubles with the assignment.


Have you taken advantage of this?

What have you got so far? The description gives you a lot of clues to setting up at least the skeleton of the class.
 
Daryl Frisbee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is what I have go so far, Yes I have emailed the instructor several times, he has been helpful, but just doesn't seem to give me the information I need to figure this out. He tells me , that I need to think more creative. Java is a art, and it can be done different ways. But I don't know no ways, but hello world. And he doesn't want anything our book shows us. So what do I do?




 
Pallavi Sadit
Ranch Hand
Posts: 50
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daryl,
Since you have mentioned that you have not coded anything other than a "Hello World" program and that is your knowledge in Java, I suggest you to get hold of a good Java book and get a basic understanding of topics like Class, Object , instance variables, constructors, how to write a class, how to create an object, how to call a method on an object, how to set instance variables, using conditional statements. Once you are through with these topics, you will be able to complete this assignment. This may seem to be a great deal of work, but again there are no shortcuts when you are learning.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

I can see an error, that you have marked something static. you should never use static anywhere without a good reason. The main method has to be static, so that counts as a good reason. But what about state? Why have you made that static?
What have you been taught about the structure of an ordinary class? I think you want to create an ordinary class.
Also you haven't told us anything about the Main class. Apart from the fact that Main is a poor name for a class, what is it doing?
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When it says store, does it mean store? When I see people write store, I think they want to write things in a file or a database or something so the data are available for later use. I suspect you only want to reflect the state and don't actually want to store it in a file.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best advice is to StopCoding (<--click that). Don't think about Strings or arrays or java. Just talk through the problem out loud. Write down in English what the program should do, as if you were trying to explain to a child what it does.

For example...

I need to keep track of what state something is in.
It will have one of three states.
the states can only progress forwards...from state 1 to state 2 to state 3.
Once it is in state 3, it doesn't ever change again.
It needs to be able to display what the current state is


Then you look at these parts, and only try and implement one at a time. And remember that each should be independent. For example. the code that displays the state doesn't care how you get to that state. Write the method while remembering that. The method also shouldn't care how many possible states there are, or what the specific states can be. All it has to do is know how to find out what the current state is and print it out.

This means that when you want to test it, you can set the state in any way that works. You don't have to worry about the next() method. you can simply force your state to whatever in some temporary code you write and will later throw away.

I have found that when I'm writing a program, I usually write at least twice as much code as what is in my final piece. I write tons of code that does nothing but helps me test, then when I'm sure things are good I delete it. Don't be afraid to do that.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!