查找Java invetory值 [英] Finding a Java invetory value

查看:70
本文介绍了查找Java invetory值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助查找java分配的整个库存值。这就是我到目前为止所拥有的。我是Java的新手并且正在努力。需要帮助,谢谢


import java.util.Scanner; //程序使用类扫描器


公共类ProductInventory1


{//主要方法开始java应用程序


public static void main(String args [])

{



产品invProducts [] =新产品[3]; //设置新产品名称


//构建数组

invProducts [0] = new Product();

invProducts [0] .setItemName(" Tape");

invProducts [0 ] .setItemQuantity(100);

invProducts [0] .setItemPrice(4.99);

invProducts [0] .setItemNumber(101);


invProducts [1] = new Product();

invProducts [1] .setItemName(" knife");

invProducts [1] .setItemQuantity (50);

invProducts [1] .setItemPrice(2.99);

invProducts [1] .setItemNumber(102);


invProducts [2] = new Product();

invProducts [2] .setItemNa me(" box");

invProducts [2] .setItemQuantity(200);

invProducts [2] .setItemPrice(1.99);

invProducts [2] .setItemNumber(103);


System.out.print(" ItemNumber \t productname \t UnitPrice \t quantity \t total value \ n");

System.out.print(" ========== \ t =========== \ t = ======== \t ======== \ t =========== \ n");


int counter = 0; // set counter

while(counter< 3)// set while while

{


//输出每个数组元素值

System.out.print(invProducts [counter] .getItemNumber()+" \t\t" + invProducts [counter]。 getItemName()+" \t\t" + invProducts [counter] .getItemPrice()+" \t\t" + invProducts [counter] .getItemQuantity()+" \t\t" ; + invProducts [counter] .itemTotalValue()+" \ n" );

counter = counter + 1;




}



} //结束主


} //结束WorkEquipment

I need help with finding an entire inventory value for a java assignment. This is what I have so far. I am new to Java and am struggling. In need of help, thanks


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

public class ProductInventory1

{//main method begins java application

public static void main (String args[])
{


Product invProducts[] = new Product[3];// set new product name

//build array
invProducts[0] = new Product();
invProducts[0].setItemName("Tape");
invProducts[0].setItemQuantity(100);
invProducts[0].setItemPrice(4.99);
invProducts[0].setItemNumber(101);

invProducts[1] = new Product();
invProducts[1].setItemName("knife");
invProducts[1].setItemQuantity(50);
invProducts[1].setItemPrice(2.99);
invProducts[1].setItemNumber(102);

invProducts[2] = new Product();
invProducts[2].setItemName("box");
invProducts[2].setItemQuantity(200);
invProducts[2].setItemPrice(1.99);
invProducts[2].setItemNumber(103);

System.out.print ( "ItemNumber \t productname \t UnitPrice \t quantity\t total value\n");
System.out.print ( "========== \t =========== \t ========= \t ========\t ===========\n");


int counter = 0;//set counter
while (counter <3)//set while loop
{

//output each array elements value
System.out.print ( invProducts[counter].getItemNumber()+ "\t\t"+ invProducts[counter].getItemName()+ "\t\t"+ invProducts[counter].getItemPrice()+ "\t\t"+ invProducts[counter].getItemQuantity()+"\t\t"+ invProducts[counter].itemTotalValue()+"\n" );
counter = counter + 1;




}


}//end main

}//end WorkEquipment

推荐答案


我需要帮助查找java分配的整个库存值。这就是我到目前为止所拥有的。我是Java的新手并且正在努力。需要帮助,谢谢


import java.util.Scanner; //程序使用类扫描器


公共类ProductInventory1


{//主要方法开始java应用程序


public static void main(String args [])

{



产品invProducts [] =新产品[3]; //设置新产品名称


//构建数组

invProducts [0] = new Product();

invProducts [0] .setItemName(" Tape");

invProducts [0 ] .setItemQuantity(100);

invProducts [0] .setItemPrice(4.99);

invProducts [0] .setItemNumber(101);


invProducts [1] = new Product();

invProducts [1] .setItemName(" knife");

invProducts [1] .setItemQuantity (50);

invProducts [1] .setItemPrice(2.99);

invProducts [1] .setItemNumber(102);


invProducts [2] = new Product();

invProducts [2] .setItemNa me(" box");

invProducts [2] .setItemQuantity(200);

invProducts [2] .setItemPrice(1.99);

invProducts [2] .setItemNumber(103);


System.out.print(" ItemNumber \t productname \t UnitPrice \t quantity \t total value \ n");

System.out.print(" ========== \ t =========== \ t = ======== \t ======== \ t =========== \ n");


int counter = 0; // set counter

while(counter< 3)// set while while

{


//输出每个数组元素值

System.out.print(invProducts [counter] .getItemNumber()+" \t\t" + invProducts [counter]。 getItemName()+" \t\t" + invProducts [counter] .getItemPrice()+" \t\t" + invProducts [counter] .getItemQuantity()+" \t\t" ; + invProducts [counter] .itemTotalValue()+" \ n" );

counter = counter + 1;




}



} //结束主


} //结束WorkEquipment
I need help with finding an entire inventory value for a java assignment. This is what I have so far. I am new to Java and am struggling. In need of help, thanks


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

public class ProductInventory1

{//main method begins java application

public static void main (String args[])
{


Product invProducts[] = new Product[3];// set new product name

//build array
invProducts[0] = new Product();
invProducts[0].setItemName("Tape");
invProducts[0].setItemQuantity(100);
invProducts[0].setItemPrice(4.99);
invProducts[0].setItemNumber(101);

invProducts[1] = new Product();
invProducts[1].setItemName("knife");
invProducts[1].setItemQuantity(50);
invProducts[1].setItemPrice(2.99);
invProducts[1].setItemNumber(102);

invProducts[2] = new Product();
invProducts[2].setItemName("box");
invProducts[2].setItemQuantity(200);
invProducts[2].setItemPrice(1.99);
invProducts[2].setItemNumber(103);

System.out.print ( "ItemNumber \t productname \t UnitPrice \t quantity\t total value\n");
System.out.print ( "========== \t =========== \t ========= \t ========\t ===========\n");


int counter = 0;//set counter
while (counter <3)//set while loop
{

//output each array elements value
System.out.print ( invProducts[counter].getItemNumber()+ "\t\t"+ invProducts[counter].getItemName()+ "\t\t"+ invProducts[counter].getItemPrice()+ "\t\t"+ invProducts[counter].getItemQuantity()+"\t\t"+ invProducts[counter].itemTotalValue()+"\n" );
counter = counter + 1;




}


}//end main

}//end WorkEquipment



欢迎来到TSDN。

请记住只使用代码标签才能分析代码。

阅读指南。

OK。


现在问题是什么。

似乎一切都很好。

任何逻辑问题或语法问题。

具体。

缺少源代码,产品类的源代码。

告诉我们你面临的具体问题。

那么最好解决你的问题。

好​​的。


亲切的问候,

Dmjpro。


Welcome to TSDN.
Remember to use code tag only then it would be better to analyze your code.
Read the guidelines.
OK.

Now what''s the problem with that.
It seems everything fine.
Any logical problem or syntactical problem.
Be specific.
And a source code is missing, the source code of product class.
Tell us the specific problem you r facing.
Then it would be better to solve your problem.
OK.

Kind regards,
Dmjpro.


1。)发布代码时请使用代码标签。

2.)要获得库存的价值,您需要将数量*值的总和相加库存中的每件商品。你可以在那里使用while循环。

3.)当在Java中循环遍历数组时,更常见的是使用for循环而不是while循环,因为你(通常)知道你要预先循环的次数(即数组的大小)。
1.) Please use code tags when posting code.
2.) To get the value of the inventory, you need to sum the values of quantity * price for each product in your inventory. You do that in that while loop you have there.
3.) When looping through arrays in Java, it is more common to use a for loop instead of a while loop because you (usually) know the number of times you''re going to loop before hand (i.e the size of the array).


嗨spics?

你的意思是,你想要做一些像 invProducts.get(" Tape")的事情?如果是这样,使用HashMap而不是数组怎么样?

这里是如何做到的:
Hi spicster!
Do you mean, you want to do something like invProducts.get("Tape")? If so, how about using a HashMap instead of an Array?
Here''s how to do so:
展开 | 选择 | 换行 | 行号


这篇关于查找Java invetory值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆