no1zson 24 Posting Whiz in Training

Got it ... I think.
I put the Compactdisk class back in, and just modified it for the new array ... at least that is what I think I did.
It looks good, it runs well ( a few bugs to work out, but I think I have it)
Tell me what you think Ezzaral, I might have to put your name as a reference in this somewhere if I ever get it working! :o)
Just look at the name variable right now, that is all I have implimented at this point. Here is the main class.

import java.util.Scanner; //uses class Scanner

public class Inventory
{// begin class Inventory
	public static void main(String[] args)	
	{//begin method main
	
	Compactdisk thisCompactdisk = new Compactdisk(); //call Compactdisk class

	// create cd Array
	Compactdisk[] cds = new Compactdisk[5];

	cds[0] = new Compactdisk(); // adds to array
	cds[0].getName();
	
	int cdCount=0;

	
	Scanner input = new Scanner(System.in);  // create scanner
	
	String nameInput = input.next();
	
			// begin display method
			System.out.print("Enter CD Name or STOP to Exit: ");
			nameInput = input.next();  // read cd name
			
			
		  	while (!nameInput.equalsIgnoreCase("STOP"))
			{// begin main While
			
				cds[cdCount] = new Compactdisk();
				cds[cdCount].setName(nameInput);

				System.out.print("Enter Price of this CD: "); // prompt for price
				thisCompactdisk.setPrice(input.nextFloat());	// price input from user.
				while (thisCompactdisk.getPrice()<= 0)
				{// begin while
				System.out.print("Price Must Be Greater Than Zero. Enter Price: ");
				thisCompactdisk.setPrice(input.nextFloat()); // cd price loop from user.
				} // End while
		
				System.out.print("Enter CD Item Number: "); // prompt for cd item number
				thisCompactdisk.setItemno(input.nextInt()); // cds item number …
no1zson 24 Posting Whiz in Training

That is what I have spent most of the morning trying to accomplish, building off Ezzaral's suggestion.
At this point I am just not sure how or where to set up the get and set commands. I think I have wrapped my brain around most of the rest of it.

no1zson 24 Posting Whiz in Training

Cerberos - thank you for that tip. If I understand it correctly, it will still have me setting up the information inside the array myself and then just calling those values later.
What I am trying to do is more like what Ezzaral has suggested, I want the user to enter the values, and my array store and use that information.
I do appreciate your help though. Thanks again.

no1zson 24 Posting Whiz in Training

That does make sense. I had the count worked out in my head, but could not figure out how the array statements worked in to the while loop.
I did some testing last night on it, tried coding all this morning and think I have it mostly worked out. Take a look.

import java.util.Scanner; //uses class Scanner

public class Inventory
{// begin class Inventory
	public static void main(String[] args)	
	{//begin method main
	
	Compactdisk thisCompactdisk = new Compactdisk(); //call Compactdisk class

	// create cd Array
	Compactdisk[] cds = new Compactdisk[5];

	cds[0] = new Compactdisk(); // adds to array
	
	
	Scanner input = new Scanner(System.in);  // create scanner
	
	
			// begin display method
			System.out.print("Enter CD Name or STOP to Exit: ");
			thisCompactdisk.setCDName(input.next());  // read cd name
			
			int cdCount=0;
			String nameInput = input.next();
		  	while (!nameInput.equalsIgnoreCase("STOP"))
			{// begin main While
			
				cds[cdCount] = new Compactdisk();
				cds[cdCount].setName(nameInput);

				System.out.print("Enter Price of this CD: "); // prompt for price
				thisCompactdisk.setPrice(input.nextFloat());	// price input from user.
				while (thisCompactdisk.getPrice()<= 0)
				{// begin while
				System.out.print("Price Must Be Greater Than Zero. Enter Price: ");
				thisCompactdisk.setPrice(input.nextFloat()); // cd price loop from user.
				} // End while
		
				System.out.print("Enter CD Item Number: "); // prompt for cd item number
				thisCompactdisk.setItemno(input.nextInt()); // cds item number input from user
		
				System.out.print("Enter Number of these CDs in Stock: "); // prompt for cd stock
				thisCompactdisk.setNstock(input.nextInt()); // cds in stock input from user
				
        
				System.out.print("CD "+thisCompactdisk.getCDName()+", Item Number "+thisCompactdisk.getItemno()+","); // display name
				System.out.printf(" is worth %c%.2f.\n", '$', thisCompactdisk.getPrice()); // display individual price
				System.out.printf("We have %d copies in stock, making our inventory …
no1zson 24 Posting Whiz in Training

If I want to make an array that has the numbers 1,2,3,4,5 in it, that is easy.
Int arrayname[] = {"1", "2", "3", "4", "5"};

My questions are 3,
1. If I make it "String arrayname" can I put numbers in there also?
2. How can I change that 1,2,3,4,5, to variables to be input by the user?
It seems I should start with
String arrayname[] = new String [5]; (because I want to do 5 cds) ... but I do not know where the variable names go? If they do not get entered into the array, then
3. how would I put the array into the Inventory program so that it knew to store them there?

Does that help?

no1zson 24 Posting Whiz in Training

That is what I am trying to do, but my coding inadequacies keep me from putting down in a program what I know needs to be done.
I know the array should accept the information each time the loop is executed, store it, and let me manipulate it later, I just do not know how to get it to do so.
For instance, just to start the array, I will attempt to put it in my Inventory class. It has to be
String cdaname[cdname, price, itemno, nstock] = new String [5];
should create an array named cdaname, that will accept the given information for 5 cds. (I think). But not all that information is string information. Price is float, itemno is int, so will that one array accept all that information? and will it allow me to total the price later?

no1zson 24 Posting Whiz in Training

I have the compactdisk class you see above, and then the inventory class here.

import java.util.Scanner; //uses class Scanner

public class Inventory
{// begin class Inventory
	public static void main(String[] args)	
	{//begin method main
	
	Compactdisk thisCompactdisk = new Compactdisk(); //call Compactdisk class
	
	Scanner input = new Scanner(System.in);  // create scanner
	
	
			// begin display method
			System.out.print("Enter CD Name or STOP to Exit: ");
			thisCompactdisk.setCDName(input.next());  // read cd name
			
		  	while (!thisCompactdisk.getCDName().equalsIgnoreCase("STOP"))
			{// begin main While

				System.out.print("Enter Price of this CD: "); // prompt for price
				thisCompactdisk.setPrice(input.nextFloat());	// price input from user.
				while (thisCompactdisk.getPrice()<= 0)
				{// begin while
				System.out.print("Price Must Be Greater Than Zero. Enter Price: ");
				thisCompactdisk.setPrice(input.nextFloat()); // cd price loop from user.
				} // End while
		
				System.out.print("Enter CD Item Number: "); // prompt for cd item number
				thisCompactdisk.setItemno(input.nextInt()); // cds item number input from user
		
				System.out.print("Enter Number of these CDs in Stock: "); // prompt for cd stock
				thisCompactdisk.setNstock(input.nextInt()); // cds in stock input from user
				
        
				System.out.print("CD "+thisCompactdisk.getCDName()+", Item Number "+thisCompactdisk.getItemno()+","); // display name
				System.out.printf(" is worth %c%.2f.\n", '$', thisCompactdisk.getPrice()); // display individual price
				System.out.printf("We have %d copies in stock, making our inventory worth %c%.2f\n", thisCompactdisk.getNstock(), '$', thisCompactdisk.getValue()); //inventory value
		
				System.out.print("Enter CD Name or STOP to Exit: "); // internal loop prompt
				thisCompactdisk.setCDName(input.next()); //name input from user
						
			} // End main While
		System.out.print("Ending Program.");
	

	}// end method main
} // end class Payroll

This is where I start getting confused, which class should my array be defined in? Should all my get and sets be discarded as a result? If …

no1zson 24 Posting Whiz in Training

Unfortunatley for me it is called for. I must impliment an array into my code for next week's assignment.
With my limited experience (all of 5 weeks now) and even more limited understanding I am just not sure of the mechanics required to do this. i understand what an array is, how it is used, and what all it can do; I just have no real detailed knowledge on how to code it in to my program.
I feel as if I have been instructed on what a wireless access device is, and what it is used for, and then been told to properly install it in my house so that all my existing home devices will use it properly. I think I know how to use it, but implimentation is another story.

So I am stuck at stage 1, impliment an array.

I have not been instructed on if an array replaces my current variable set up, does it append to and utilize those variables, or does it even operation on its own in another class entirely, so all this is a mystery to me.

no1zson 24 Posting Whiz in Training

That was part of my misunderstanding. I was going to create an array for each variable. (I thought each variable would be a different type and require its own array).
Now I understand that I can use a single array for all field types. I just left in named cdaName because that made the most sence to me, it will be an array of cd information.
My problem now is that I do not understand where to put this array. I want it to be populated with information input from the user, so I think I need to keep all my get and set code, but where does my array tie in? Do I need to create another class completley?
I think my array should look something like

String cdaName[]= new String{cdName, price, itemno, nstock};

but I cannot find any examples of such a beast for me to learn and build off of.

no1zson 24 Posting Whiz in Training

The problem appears to be that I was trying to set up and array to take the place of cdName, and that is not what I really wanted to do.
I want an array to use cdName. So had gone through and tried to replace all my cd name variables, gets, and sets with array instances and it was just confusing itself. I put my code back the way it was, added an array and that seems to have gotten the first step done.
Code now looks like this:

public class Compactdisk
{// begin class

	// set up array
	String cdaName[]= new String[5];

	//InventoryCD class has 5 fields
	String cdName; //  cd name
	float price; // price of cd
	int itemno; // item number of cd
	int nstock; // how many units in stock	
	
	//Compact disk class constructor
	public Compactdisk()
	
		// 4 fields need to be set up
		{ 
		cdName = "";
		price = 0;
		itemno = 0;
		nstock = 0;
		}
		
		// set values
	   public void setCDName(String diskName)
	   {
	   cdName = diskName;
	   }
		public void setPrice(float cdPrice)
	   {
	   price = cdPrice;
	   }
		public void setItemno(int cdItemno)
	   {
	   itemno = cdItemno;
	   }
		 public void setNstock(int cdStock)
	   {
	   nstock = cdStock;
	   }
		
	   // return values
		public String getCDName()
		{	
		return (cdName);
		}
		public float getPrice()
		{	
		return (price);
		}
		public int getItemno()
		{	
		return (itemno);
		}
		public int getNstock()
		{	
		return (nstock);
		}
					
		// returns inventory value
	   public float getValue()
	   {
	   return(price * nstock);
	   }


}// end class

Now if I can effectivley impliment and use this array is another story altogether. We will see.

no1zson 24 Posting Whiz in Training

I had cdName = diskName when I first started implimenting this array. That line gave me an "incompatible types" error. Changing it to what it is now enabled me to move on to the next and current error.

no1zson 24 Posting Whiz in Training

I am really starting to feel dumb. I am either missing something right in front of my face, or completely do not understand the question. I see what I think is the variable name several times, through the setup, initialization and everything.

//InventoryCD class has 5 fields
String cdName[]; //  cd name array

// 4 fields need to be set up
cdName = new String [25];

// set values
public void setCDName(String diskName)
{
 cdName = cdName;

I tried diskName as well, just because I was so frustrated, but same error.

no1zson 24 Posting Whiz in Training

I did have it all in one line to begin with, (declaring and creating)

String cdName[] = new String [25]

but it is easier for me to read this way, and I get the same error either way.
Those are the only two ways I have learned to do this, unless I am just way off base right now and doing something wrong.

no1zson 24 Posting Whiz in Training

I have just been using a standard String to input and return information. I am trying to impliment an Array in to this inventory program so that I can store and view more than one item at a time.
I think I have done ok until I get to the Return part of the program. I have tried several different things but nothing seems to work.
As it is, I am getting a "cannot find symbol" error message on "cdName" in the return statment. Any help on what I am doing wrong?

public class Compactdisk
{// begin class

	//InventoryCD class has 5 fields
	String cdName[]; //  cd name array
	float price; // price of cd
	int itemno; // item number of cd
	int nstock; // how many units in stock	
	
	//Compact disk class constructor
	public Compactdisk()
	
		// 4 fields need to be set up
		{ 
		cdName = new String [25];
		price = 0;
		itemno = 0;
		nstock = 0;
		}
		
		// set values
	   public void setCDName(String diskName)
	   {
	   cdName = cdName;
	   }
		public void setPrice(float cdPrice)
	   {
	   price = cdPrice;
	   }
		public void setItemno(int cdItemno)
	   {
	   itemno = cdItemno;
	   }
		 public void setNstock(int cdStock)
	   {
	   nstock = cdStock;
	   }
		
	   // return values
		public String getCDName()
		{	
		[B]return cdName();[/B]
		}
		public float getPrice()
		{	
		return (price);
		}
		public int getItemno()
		{	
		return (itemno);
		}
		public int getNstock()
		{	
		return (nstock);
		}
					
		// returns inventory value
	   public float getValue()
	   {
	   return(price * nstock);
	   }


}// end class
no1zson 24 Posting Whiz in Training

Thanks guys. I appreciate all the help.

no1zson 24 Posting Whiz in Training

That is a good idea. I had not thought about it that way.
I am a little confused by the scanner and the setxxx() statements though. Maybe I just do not know how to set them up.
But the set statements you talk about will replace the scanner therefore I should not need that any longer?

How do I pull the statements from the other class where I set them up?
I have tried both

public void setRate(double eRate)
	   {
	   rate = eRate;
	   }

and

public double getRate()
		{	
		return (rate);
		}

written in to this class right before I use

thisEmployee.setRate(input.nextDouble() );

but they just produce more illegal start of expression errors.

no1zson 24 Posting Whiz in Training

Thank you for your patience, I do appreciate your help with this issue.
Concerning the ;, that is what I thought also, but when I remove it I then get two errors.
I still get "illegal start of expression" for that line, but I also get ";" expected at

} // end display method

If I take this whole block out and put it back in the Employee class everything works fine.
Is is possible that I have a method inside a method when I put it in Payroll?
Here is the whole class.

import java.util.Scanner; //uses class Scanner

public class Payroll
{// begin class Payroll
	public static void main(String[] args)	
	{//begin method main
	
	// create Employee object nextEmployee
	// pass employee name to constructor
	Employee nextEmployee = new Employee();
	
	nextEmployee.displayMessage(); // display message
	
		public void displayMessage()
		{// begin display method
			Scanner newEname = new Scanner(System.in);
			System.out.print("Enter Employee Name or STOP to Exit: ");
			String name = newEname.nextLine();
		
			while (!(name).equalsIgnoreCase("STOP"))
			{// begin main While
					Scanner input = new Scanner(System.in);
		
				System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
				rate = input.nextDouble(); // rate input from user.
				while (rate <= 0)
				{// begin while
				System.out.print("Rate Must Be Greater Than Zero. Enter Rate: ");
				rate = input.nextDouble(); // rate loop from user.
				} // End while
		
				System.out.print("Enter Hours Employee Worked This Week: "); // prompt for hours worked
				hours = input.nextDouble(); // hours student worked this week.
				while (hours <= 0)
				{//begin while
				System.out.print("Hours Worked
no1zson 24 Posting Whiz in Training

I am getting "illegal start of expression" for this line

public void displayMessage();

I have checked all my braces, all my semi colons, everything looks right to me. What am I doing wrong?

import java.util.Scanner; //uses class Scanner

public class Payroll
{// begin class Payroll
	public static void main(String[] args)	
	{//begin method main
	
	// create Employee object nextEmployee
	// pass employee name to constructor
	Employee nextEmployee = new Employee();
	
	nextEmployee.displayMessage(); // display message
	
		
		public void displayMessage();
		{// begin display method
			Scanner newEname = new Scanner(System.in);
			System.out.print("Enter Name: ");
			String name = newEname.nextLine();
		
			while (!(name).equalsIgnoreCase("STOP"))
			{// begin main While
					Scanner input = new Scanner(System.in);
		
				System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
				rate = input.nextDouble(); // rate input from user.
				while (rate <= 0)
				{// begin while
				System.out.print("Rate Must Be Greater Than Zero. Enter Rate: ");
				rate = input.nextDouble(); // rate loop from user.
				} // End while
		
				System.out.print("Enter Hours Employee Worked This Week: "); // prompt for hours worked
				hours = input.nextDouble(); // hours student worked this week.
				while (hours <= 0)
				{//begin while
				System.out.print("Hours Worked Must Be Greater Than Zero. Enter Hours: ");
				hours = input.nextDouble(); // Hours loop from user
				} // End while
        
				result = rate * hours; // figures students salary
        
				System.out.print(name); // display name
				System.out.printf("'s salary for the week is %c%.2f\n", '$', result); //display salary
		
				System.out.print("Enter Employee's Name or Enter STOP to Exit: "); // internal loop prompt
				name = newEname.nextLine(); //name input from user
						
			} // End main While
		System.out.print("Ending
no1zson 24 Posting Whiz in Training

I put in the other three; rate, hours, and result.
I had to comment out the first line in each one,

// 4 fields need to be set up
		// 1st is employee
		{ 
		employeeName = "";
		}
		// sets values
	   public void setEmployeeName(String eName)
	   {
	   employeeName = eName;
	   }
	   // get the employee name
		public String getEmployeeName()
		{	
		return (employeeName);
		}
		
		// 2nd is rate
		{ 
		//rate = "";
		}
		// sets values
	   public void setRate(double eRate)
	   {
	   rate = eRate;
	   }
	   // get the employee rate
		public double getRate()
		{	
		return (rate);
		}
	
		// 3rd is hours
		{ 
		//hours = "";
		}
		// sets values
	   public void setHours(double eHours)
	   {
	   hours = eHours;
	   }
	   // get the employee rate
		public double getHours()
		{	
		return (hours);
		}
		
		// 4th is result
		{ 
		//result = "";
		}
		// sets values
	   public void setResult(double eResult)
	   {
	   result = eResult;
	   }
	   // get the employee rate
		public double getResult()
		{	
		return (result);
		}

otherwise I got an incompatible type error. It wanted double in there somehwere, I do not know why or where. Why does it work with the line commented out?

no1zson 24 Posting Whiz in Training

Once again you are dead on accurate. Why do I not have to also declare eName?
I am going to try and change the rest now and see how I do.

I already have a question about changing up my displaymessage(), but that is going to be my last step, I do not want to get ahead of myself.

How long have you been doing this? Just so I can get an idea of how long I have to go before I can hope to become somewhat competent.

no1zson 24 Posting Whiz in Training

Hey guys, I am trying something different to try and clean this up, but I must be missing something. I am trying to use set and get commands in place of what I have above, so I have changed (starting with employee name) my code to this:

import java.util.Scanner; //uses class Scanner


public class Employee
{
    // Employee class has 4 fields
    public char eName;
    public double rate;
    public double hours; 
    public double result;

    // Employee class has one constructor
    public Employee()

        { // initialize name of employee
        employeeName = "";
        }
        // sets values
       public void setEmployeeName(String eName)
       {
       employeeName = eName;
       }

        // get the employee name
        public String getEmployeeName()
        {   
        return (eName);
        }

        // display message
        public void displayMessage()
        {
        Scanner newEname = new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name = newEname.nextLine();

        while (!(name).equalsIgnoreCase("STOP"))

    {
                Scanner input = new Scanner(System.in);

        System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
        rate = input.nextDouble(); // rate input from user.
        while (rate <= 0)
        {
            System.out.print("Rate Must Be Greater Than Zero. Enter Rate: ");
            rate = input.nextDouble(); // rate loop from user.
        } // End while

        System.out.print("Enter Hours Employee Worked This Week: "); // prompt for hours worked
        hours = input.nextDouble(); // hours student worked this week.
        while (hours <= 0)
        {
            System.out.print("Hours Worked Must Be Greater Than Zero. Enter Hours: ");
            hours = input.nextDouble(); // Hours loop from user
        } // End while

        result = rate * hours; // figures students salary

        System.out.print(name); // display name
        System.out.printf("'s …
no1zson 24 Posting Whiz in Training

Thank you for that explaination. You were 100% correct.
I appreciate you help.

no1zson 24 Posting Whiz in Training

Can someone explain this? It is my understand that a constructor has no return type, not even void. So in my employee class I removed the "void" from what I had labeled as a constructor, thinking in reality it was just another method
So it then looked like this:

public Employee(char newEname)
		{ // initialize name of employee
		eName = newEname;
		}

It still compiled fine so I thought I was good.
I went back to recomplie my main class just to be safe, and now it no longer works. I receive this message:

Payroll.java:7: cannot find symbol
symbol  : constructor Employee()
location: class Employee
   Employee nextEmployee = new Employee();

I do not understand. I have played with everything in this line of code I can think of, but with no void in the Employee class, the Payroll class will not run. I put void back in and everything is great.
???

no1zson 24 Posting Whiz in Training

Ok, let me give this a try. I will put my first class between these code tags

public class Payroll
{
	public static void main(String[] args)	
	{
	// create Employee object nextEmployee
	// pass employee name to constructor
	Employee nextEmployee = new Employee();
	
	nextEmployee.displayMessage(); // display message
	}
} // end class Payroll

I used that class to call the class that does all the work. I will put it between these code tags.

mport java.util.Scanner; //uses class Scanner


public class Employee
{
	// Employee class has 3 fields
	public char eName;
	public double rate;
	public double hours; 
	public double result;
	
	// Employee class has one constructor
	public void Employee(char newEname)
		{ // initialize name of employee
		eName = newEname;
		}
	     
	// Employee class has four methods
	
		// get the employee name
		public String getEmployeeName(String eName)
		{	
		return eName;
		}
		
		// display message
		public void displayMessage()
		{
		Scanner newEname = new Scanner(System.in);
		System.out.print("Enter Name: ");
		String name = newEname.nextLine();
		
		while (!(name).equalsIgnoreCase("STOP"))
		
	{
				Scanner input = new Scanner(System.in);
		
		System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
		rate = input.nextDouble(); // rate input from user.
		while (rate <= 0)
		{
			System.out.print("Rate Must Be Greater Than Zero. Enter Rate: ");
			rate = input.nextDouble(); // rate loop from user.
		} // End while
		
		System.out.print("Enter Hours Employee Worked This Week: "); // prompt for hours worked
		hours = input.nextDouble(); // hours student worked this week.
		while (hours <= 0)
		{
			System.out.print("Hours Worked Must Be Greater Than Zero. Enter Hours: ");
			hours …
no1zson 24 Posting Whiz in Training

Not sure what a "code tag" is, but I have just about every other line documented.
Does not matter, I solved it myself.
Thanks for the reply. :o)

no1zson 24 Posting Whiz in Training

Like many of the posts I see out here I have decided to learn Java. It is a bit more than I bargained for. From what I see every class in the world starts with a payroll program, mine is no different.
I have done ok with it up to this point, but I have been asked to take my current working program, and alter it.

import java.util.Scanner; //uses class Scanner


public class Payroll
{
public static void main(String[] args)
{
// create another Scanner to obtain name from command window
Scanner input2 = new Scanner(System.in);


char eName; // name of employee


// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);


double rate; // hourly rate of employee
double hours; // hours worked by employee


double result; // product of rate and hours


System.out.print("Enter Employee's Name or Enter STOP to Exit: "); // prompt for name
String name = input2.nextLine(); //name input from user


while (!(name).equalsIgnoreCase("STOP"))
{


System.out.print("Enter Employee's Hourly Pay Rate: "); // prompt for rate
rate = input.nextDouble(); // rate input from user.
while (rate <= 0)
{
System.out.print("Rate Must Be Greater Than Zero. Enter Rate: ");
rate = input.nextDouble(); // rate loop from user.
} // End while


System.out.print("Enter Hours Employee Worked This Week: "); // prompt for hours worked
hours = input.nextDouble(); // hours student worked this week.
while (hours <= 0)
{
System.out.print("Hours Worked Must Be Greater Than Zero. Enter Hours: ");
hours = input.nextDouble(); // Hours loop …