• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variables

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Cindy Chao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :-)
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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, ..."
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic