I have to assignment which includes the following: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output
should display the value of the entire inventory.
· Create a method to calculate the value of the entire inventory.
· Create another method to sort the array items by the name of the product.
I have tried so far this is what I have; -
-
1. import java.text.NumberFormat;
-
2.
-
3. public class Produce {
-
4.
-
5. //initialize and load array with values
-
6.
-
7. private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024};
-
8.
-
9.
-
10. private static String[] produceName = new String[] {"carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"};
-
11.
-
12.
-
13. private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8};
-
14.
-
15.
-
16.
-
17. private static double[] producePrice = new double[] {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48};
-
18.
-
19.
-
20. public static void DisplayOutput()
-
21.
-
22. { //Displays inventory and totals
-
23.
-
24. System.out.println("Item Number\tProduce Name\tStock\tPrice\tTotal Price\n");
-
25.
-
26. NumberFormat numForm = NumberFormat.getCurrencyInstance();//Displays double values as currency
-
27.
-
28. double totalValue = 0;
-
29.
-
30. for (int i=0; i<10; i++){
-
31.
-
32. // String price = numform.format(producePrice[i]);
-
33.
-
34. System.out.println(produceNumber[i]+"\t\t"+ produceName[i]+"\t\t"+produceStock[i]+"\t"+numForm.format(producePrice[i])+
-
35.
-
36. "\t"+(numForm.format(produceStock[i]*producePrice[i])));
-
37.
-
38. totalValue=totalValue+(produceStock[i]*producePrice[i]);
-
}
-
39. System.out.println("\n\nTotal Stock Value: "+numForm.format(totalValue));
-
40.}
-
41.}
-
42.
-
43.// Inventory Part 2 July 17, 2008
-
44.
-
45. function setObject (produceName, produceNumber, produceStock, producePrice){
-
46. myObjectArray[objectArrayIndex++] = new ownObject (produceName, produceNumber, produceStock, producePrice);
-
47.
-
48. }
-
49.
-
50.
-
51.
-
52. var objectArrayIndex =0;
-
53. var myObjectArray = new Array();
-
54.
-
55. SetObject ("carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery");
-
56. SetObject (2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024);
-
57. SetObject (20, 50, 12, 15, 10, 30, 40, 6, 75, 8);
-
58. SetObject (.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48);
-
59.
-
60. function showArray (produceName, produceNumber, produceStock, producePrice) {
-
61.
-
62. document.write (produceName + ':');
-
16 6006 Laharl 849
Recognized Expert Contributor
What is your actual question? Are you not getting the desired output, are there compilation/runtime errors?
I received 24 compile errors
Produce.java:53 : class, interface, or enum expected
}
^
Produce.java:58 : class, interface, or enum expected
var myObjectArray = new Array();
^
Produce.java:60 : class, interface, or enum expected
SetObject ( "carrots", "potatoe",. ..)
I have 24 errors consisting of above
BigDaddyLH 1,216
Recognized Expert Top Contributor
var?! Is this Java or JavaScript? Seems an ungodly mix of the two.
var?! Is this Java or JavaScript? Seems an ungodly mix of the two.
The beginning is surely java, but at line 41, javascript starts
("document.writ e", "function", "new Array()" etc.)
This forum entry should be splitted and the bottom should be moved to the javascript forum.
my codes are wrong it was java script and it should be java, the main thing is I need help sorting arrays that hold multiple data, displaying the data one at a time like orange, 00215, 24, $5.00. Can someone please help me do this I have found another sort code and changed it, but now I'm getting the error duplicate class. -
-
1. import java.util.Arrays;
-
2. import java.text.NumberFormat;
-
3.
-
4. public class Produce {
-
5.
-
6. //initialize and load array with values
-
7.
-
8. private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024};
-
9.
-
10. private static String[] produceName = new String[] {"carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"};
-
11.
-
12. private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8};
-
13.
-
14. private static double[] producePrice = new double[] {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48};
-
15.
-
16.
-
17. public static void DisplayOutput()
-
18.
-
19. { //Displays inventory and totals
-
20.
-
21. System.out.println("Item Number\tProduce Name\tStock\tPrice\tTotal Price\n");
-
22.
-
23. NumberFormat numForm = NumberFormat.getCurrencyInstance();//Displays double values as currency
-
24.
-
25. double totalValue = 0;
-
26.
-
27. for (int i=0; i<10; i++){
-
28.
-
29. // String price = numform.format(producePrice[i]);
-
30.
-
31. System.out.println(produceNumber[i]+"\t\t"+ produceName[i]+"\t\t"+produceStock[i]+"\t"+numForm.format(producePrice[i])+ "\t"+(numForm.format(produceStock[i]*producePrice[i])));
-
32.
-
33. totalValue=totalValue+(produceStock[i]*producePrice[i]);
-
34. }
-
35. System.out.println("\n\nTotal Stock Value: "+numForm.format(totalValue));
-
36. }
-
37. }
-
38.
-
39. // Inventory Part 2 July 17, 2008
-
40.
-
41. public class Produce {
-
42.
-
43. public static void main(String[] args) {
-
44.
-
45.
-
46. double[] lengths = {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48};
-
47. Arrays.sort(lengths);
-
48.
-
49. }
-
50. }
-
Laharl 849
Recognized Expert Contributor
Right. You declare 'public class Produce' twice within the file.
how would I start the sort at first I had public class Sort and I was getting the error "Class Sort is public, should be in a file called Sort.java
Laharl 849
Recognized Expert Contributor
You can only have one class declared public per file. Just declare the other as 'class Sort', rather than 'public class Sort' and the compiler will shut up.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: zaidalin79 |
last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments...
4. CheckPoint: Inventory Program Part 1
• Resource: Java: How to Program
• Due Date: Day 5 forum
• Choose a product that lends itself to an inventory (for example, products at your
workplace, office supplies, music CDs, DVD...
|
by: begum |
last post by:
hello everyone!
my program is not working properly,
it is not summing the values that i entered.
It should take the double values and add them and also take strings and
makes the * as a multiplacation .
thanks !!!
begum
|
by: south622 |
last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment.
Here is the assignment:
Modify the Inventory program by adding a button to the GUI that allows the user to move...
|
by: xxplod |
last post by:
I am suppose to modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
• Create a method to calculate...
|
by: cblank |
last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory program that I have built so far with no problem. But I cannot figure out how to turn it into a GUI application.
This is what I'm trying to get it to do.
Modify the Inventory Program to use a GUI. The GUI should display the information one product...
| |
by: pinkf24 |
last post by:
I cannot figure out how to add the following:
Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.
Add a Save button to the GUI that saves the...
|
by: jcato77 |
last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created.
Assignment:
Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method...
|
by: 100grand |
last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one
product at a time, including the item number, the name of the product, the number of
units in stock, the price of each unit, and the value of the inventory of that product. In
addition, the GUI should display the value of the entire inventory, the additional attribute,
and the restocking fee.
Here is my Inventory program from 1 to 3:
package...
|
by: blitz1989 |
last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the reading has very little in it that helps can someone take a look at this code and point me in the right direction please. Thanks for any help that is offered.
//Modify the Inventory Program to use a GUI. The GUI should display the
//informationone...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |