954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get and set method... I am confuse.

Hello,
I am currently in a programming Logic and design course at my local community college and I was give 5 chapters to read because I join the class late. I am now in 3 and I am confuse with a method that the book does not explain too much. I am stuck at the get and set method. I have read the chapter twice and I cant seem to figure how to use it in a different way from what the book shows.
Here is the example of how the books explains in pseudocode.

public class TestPizza
   public static void main()
      pizza large
      large.setPizzaSize(18)

      print “A size large pizza is “ large.getPizzaSize() “ inches in diameter”
   return
endclass

I can see that the 18 was already set in the code but the book didnt explains how a user can input the size of the pizza manually. So can some one explain how to use the get and set method or point me to the tutorial? I check the search and only found things about java that didnt explain very well for me to understand.

Nekokoneko
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

So if your code is Java, why are you posting it in the C++ forum?

For setting the pizza size, first of all you get the user's input, and store it in a variable. Such as:
int thesize=stdin.readLine();
Then you can set the pizza's size: large.setPizzaSize(thesize);
Hope this helps

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

So if your code is Java, why are you posting it in the C++ forum?

For setting the pizza size, first of all you get the user's input, and store it in a variable. Such as: int thesize=stdin.readLine(); Then you can set the pizza's size: large.setPizzaSize(thesize); Hope this helps


It's java? I did not know that. The books just says that its just logicals to writing programical codes. And thanks for replying.

Nekokoneko
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 
It's java? I did not know that. The books just says that its just logicals to writing programical codes. And thanks for replying.

Don't you have any notes from school?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
It's java? I did not know that. The books just says that its just logicals to writing programical codes.


C++ code *should* always start it's main program code with:

int main() { /*...*/ }

(some ignorant people still use void main , which is NOT encouraged.)

Whereas Java's main code is always inside of a class, and looks like this:

public static void main() { }

Of course the code you posted was not *real* Java, as it did not use any braces. But you get the idea.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You