aspose file tools*
The moose likes Beginning Java and the fly likes Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variables" Watch "Variables" New topic
Author

Variables

Cindy Chao
Greenhorn

Joined: Mar 16, 2012
Posts: 3
Im new to using java, and was given this question:



Create a new class called CutMyCurls with these class attributes:
Variables: stylist1Name, stylist2Name, stylist1Available, stylist2Available, balance – these variables will store the names of two stylists and whether on not the stylist is available for an appointment (use booleans for these), and the amount of cash collected.
Constants: select appropriate names, datatypes and values for the hairdressing services

Select the most appropriate data types for these attributes and initialise them in the constructer


Ive typed it out so many times, but it just doesn't seem to compile. How would i type it out? Can anyone help me?
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
We can help you better if you show us what you've done -- the code itself -- and tell us the (exact) error message you're getting. Otherwise you're just asking us to do programming for you.

rc
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18716
    
  40

Ishara Humaira wrote:Im new to using java, and was given this question:



Create a new class called CutMyCurls with these class attributes:
Variables: stylist1Name, stylist2Name, stylist1Available, stylist2Available, balance – these variables will store the names of two stylists and whether on not the stylist is available for an appointment (use booleans for these), and the amount of cash collected.
Constants: select appropriate names, datatypes and values for the hairdressing services

Select the most appropriate data types for these attributes and initialise them in the constructer


Ive typed it out so many times, but it just doesn't seem to compile. How would i type it out? Can anyone help me?


Well, if you showed us the code that you did so far, along with the error that the compiler is throwing at you, we can probably give you hints to help you figure out the compile errors.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Cindy Chao
Greenhorn

Joined: Mar 16, 2012
Posts: 3


This is what i have so far... im not sure whats going wrong, or what to do because its my first time doing programming
Cindy Chao
Greenhorn

Joined: Mar 16, 2012
Posts: 3
Ishara Humaira wrote:public class CutMyCurls
{
// instance variables - replace the example below with your own
private String stylist1Name;
private String stylist2Name;
private String stylist1Available;
private String stylist2Available;
private int balance;

/**
* Constructor for objects of class CutMyCurls
*/
public CutMyCurls()
{
// initialise instance variables
stylist1Name = cindy;
stylist2Name = candy;

This is what i have so far... im not sure whats going wrong, or what to do because its my first time doing programming
the error says cannot find symbol.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Ishara, can you go back and edit your second last post to add Code tags. UseCodeTags (link)

Now for your problem, Closing curly braces for your constructor and class is missing. Do you know the syntax for class/constructor?

Also, I would suggest you remove everything from constructor (for now) and see if it compiles?

After every step below compile your code and see if it throws any errors.

- First, just declare the class
- Add constructor
- Declare instance variables (stylist1Name etc)

Benefit of step by step approach is, you would know exactly what part of the code throws an error and it would be easy to debug.

Good Luck and Welcome to Javaranch :-)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Ishara Humaira wrote:
Ive typed it out so many times, but it just doesn't seem to compile. How would i type it out? Can anyone help me?


First: STOP STOP STOP thinking about it as "typing" and "what do I type". We're not Harry Potter, and we're not memorizing the words of magic spells. You need to understand the Java language, what the various pieces mean, and how you can relate you problem's domain objects and actions to Java.

If you find yourself thinking, "What do I type?" then you're doing it wrong and you're just setting yourself up for frustration.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
You are going to need to understand some basic concepts to "know what to type", though, God help us, typing it is still by far the most common way to get the code written.

You evidently do have some examples, you have been introduced to the terms "variable" and "class" and "compile"; that's a start.

Help on the Ranch tends to be answers to more specific questions than you appear to have. If what you need is a tutorial, there are better places for that (since few of us want to type up individual tutorials).

One immediate problem with the code you have is that, to assign a literal string to a String variable, you need to enclose what you want to assign in double quotes


I recommend taking a working example from a tutorial and modify it slightly to explore new things you're trying to understand. That will lead to more specific questions that we can then help you with. But if all you do is type in partial examples and say "I don't know what to do", then it is difficult to help you here.

rc


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Saurabh Pillai wrote:Ishara, can you go back and edit your second last post to add Code tags. UseCodeTags (link) . . .
I have done so, and you can see how much better it looks now

You also need to read the instructions; it says clearly what sort of variables you should use for available. Also (although I don’t like BlueJ myself), take note that BlueJ provides you with templates, which you can use as an example and alter.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Ralph Cook wrote:You are going to need to understand some basic concepts to "know what to type", though, God help us, typing it is still by far the most common way to get the code written.


Right, and I may have overreacted just a bit but I get nervous every time I see "what do I type?" and my point was simply that, rather than thinking, for example, "the way to print an array is to type for (int i = 0; i < arr.length; i++) ..." and so on, it's better to take an approach like, "I want to print the elements of this array, so that means I'll need to iterate over it and print each element. I know that the for loop is the most common way to do that, and I know that the array's indices go from 0 to length - 1, so I'll set up the initialization as i=0 and the test as i < arr.length..." and so on. Not necessarily that mentally verbosely, of course. (And yes, I know foreach exists.)

It's kind of like taking a car from A to B. You don't think, "I need to turn the ignition a half turn clockwise for 3-5 seconds, then depress the brake, move the shifter into 'R', slightly release the brake, ... 400m later turn the steering wheel clockwise 180 degrees ..." Rather, it's, "Start the car, back out of the driveway, North on 1st to Main, right on Main, ..."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variables