Easy variable issue...

I have an easy question but am having a mental block. How can I assign the value of 0.05 to restock? What I need to do is return a 5% restocking value added onto the item. Make sense?

//Type.java

publicclass Typeextends Office// Start of public subclass Itemtype that stores office items color.

{

private String color;//get string name

privatefloat restock;//get float value of restock

privatefloat item;//get float value of total items

public Type(String color,float restock,float item)

{// constructor to initialize the fields

this.color = color;

this.restock = restock;

this.item = item;

}

publicfloat getRestock()

{

return (this.item * this.restock) + (this.item);

}

}//end public subclass Type

[1663 byte] By [Jack1971a] at [2007-10-3 3:47:51]
# 1

When you construct an object of the class Type, you pass it arguments don't you? From the code you posted, the 2nd argument you pass to that object should be 0.05 (or (float) 0.05, or some other expression that evaluates to 0.05 as a float).

I don't understand your question completely.

warnerjaa at 2007-7-14 21:44:50 > top of Java-index,Java Essentials,Java Programming...
# 2
please clarify.Do you want to increase the value of item by 5%?Do you want to store 0.05 as restock after that?Message was edited by: r035198x
r035198xa at 2007-7-14 21:44:50 > top of Java-index,Java Essentials,Java Programming...
# 3
float constants have an "f" on the end as in:0.05f
malcolmmca at 2007-7-14 21:44:50 > top of Java-index,Java Essentials,Java Programming...
# 4

Ok here is what I have, an inventory program called Office.....see below

//Inventory.java

import java.util.*; //imports java utilities to include Array.sort function.

public class Office

{ //start of main

public static void main( String args[] )

{ //start of class

int array[] = { 1, 2, 3, 4, 5, }; //creates number array

String item[] = {"Pencil" , "Pen" , "Toner" , "Ink" , "Paper"}; //creates item array

int stock[] = { 5, 8, 6, 5, 4}; // creates stock array

int price[] = { 1, 2, 33, 12, 4}; //creates price array

System.out.printf( "0%s%8s%8s%8s\n", "Number", "Item", "Stock", "Price"); //displays columns

double itemInv = 0.00; //item's value variable

double totalInv = 0.00;//total inventories variable

double restock = 0.05;

for ( int counter = 0; counter < item.length; counter++ ) //start of for loop

{

Arrays.sort(item); //sorts array according to item name alphabetically

itemInv = (stock [ counter ] * price [ counter ]); //method to calculate items inventory value

System.out.printf( "%5d%8s%8d%8d\n", counter, item [ counter ], stock [ counter ], price [ counter ]);//display lists of items

totalInv += (stock [ counter ] * price [ counter ]);//method to calculate inventories total value

System.out.println("Total value = $" + totalInv);//displays inventories total value

} //end of class

} //end main

} //end of main

And I need to use a subclass to store a unique feature and return a 5% restocking value to each items inventory. This is the subclass I created.... I could be way off, this stuff is very new to me. :) Please forgive..lol

[code]

//Type.java

public class Type extends Office // Start of public subclass Itemtype that stores office items color.

{

private String color; //get string name

private float restock;//get float value of restock

private float item;//get float value of total items

public Type(String color,float restock, float item)

{ // constructor to initialize the fields

this.color = color;

this.restock = restock;

this.item = item;

}

public float getRestock()

{

return (this.item * this.restock) + (this.item);}

{System.out.println("Restock Value = $" + restock);

}

} //end public subclass Type

Jack1971a at 2007-7-14 21:44:50 > top of Java-index,Java Essentials,Java Programming...
# 5

1) You need to learn how to properly comment your code. Most of your comments are unneccessary and even misleading (Do not put a comment for obvious things)

2)Why are you extending Office if you are not reusing anything from office in Type? You have to make sure that your inheritance relationship makes sense.

3) How are you going to be using the Type class. You have not accessed it in the main method of your program

4)I still do not understand what you want to do

r035198xa at 2007-7-14 21:44:50 > top of Java-index,Java Essentials,Java Programming...