How To Make Array For Products And Quantities
May 3, 2014
My Code:
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
[Code] .....
It's suppose to store the products and how many you type in there (the quanitity).
View Replies
ADVERTISEMENT
Sep 13, 2014
I am trying to update and delete products from a JSP page but am having a hard time getting the code to work. I keep getting errors and my program won't run. My Index.jsp page works, but everything else is messed up. Below is my code.
index.jsp
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
[code]....
View Replies
View Related
Feb 11, 2015
Write a program called ProductCatalog that prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution must use a for loop repetition structure and should use the Product class included in labfiles05.zip to keep track of the product with the highest price. Here is sample output:
Enter the number of products: 3
Enter the name of product 1: iPod
Enter the price of product 1: 158.99Enter the name of product 2: iPad
Enter the price of product 2: 518.99
Enter the name of product 3: iPadMini
Enter the price of product 3: 304.49
Most Expensive: Product [name=iPad, price=518.99]
Your solution should not use an array to keep track of all the product information entered.
I am having trouble with my code, with the For loop and then calling the methods from the Product class into the ProductCatalog. How should I approach this program.
Here is the Product program.
public class Product
{
private String name;
private double price;
public Product(String theName, double thePrice) {
name = theName;
price = thePrice;
[Code]...
Here is the ProductCatalog class where I call the methods from Product class. The For loop is what I am having trouble with as well.
import java.util.Scanner;
public class ProductCatalog
{
public static void main(String[] args) {
double number;
String product = " ";
double productCount = 0;
[Code]...
View Replies
View Related
Dec 3, 2014
We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:
1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png
2. Receipt - at the end of every transaction.
3. Daily Sales Report where it shows all receipts then grand total like:
Transaction 1
-subtotal
Transaction 2
-subtotal
and so on then,
GRAND TOTAL
4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.
Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.
int userQty1 = Integer.parseInt(JOptionPane.showInputDialog(
"Product ID Product Name Product Quantity Product Price"
+prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 "
"
+ and so on until prod5));
[code].....
View Replies
View Related
Jul 11, 2014
I'm trying to write data for three products to a random access file, but I have a problem. Each product has a code and a price. After writing them to my file, I want to get to the second field or product. I do this by getting the length for each record, and multiplying it by the field number I want to go to. I use the result for the seek() method of the RandomAccessFile object. It is giving me an EOFException, but when I use 0 for the seek method i get the data for the first poduct or field.
Java Code:
public static void main(String[] args) {
final int RECORD_LENGTH = 16;
try(RandomAccessFile productsOutput = new RandomAccessFile("C:UsersalfonsoDesktopBinaryTestRandom.ran", "rw")) {
String[] codes = {"java", "jsps", "txtp"};
double[] prices = {49.5, 19.9, 29.9};
for(int i = 0; i < codes.length; i++) {
[Code] .....
View Replies
View Related
Jan 22, 2015
When I insert: title, category, year, artist in 4 Strings And when I press "enter" i put those 4 in a array "large", and then when I can start a new music insert with 4 new string elements and add those in the large array..So: I have an array "large" with the length 19 (or so..)(max ~100 or so)Then I what to: get,in a new array "title",the elements:0,4,8,12,16 (from the large array) and put them in a scrollable list. And when I select one element in the title array I then whant to get 3 remaining elements from this. And put it in a array called selection.
So the "large" and the "title" arrays must be dynamically sizes... or be copied to a larger sized..
1 can it be done with arrays?
2 how do dynamically change the size of for example the array "title"?
3 how do I receive the elements 0,4,8,12,16 and so on, (to (
large.length-3) and add it to the title array?
View Replies
View Related
May 17, 2014
public class ThreeStackArray
{
static int row = 10;
static int col = 2;
int[][] stack = new int[row][col];
//place numbers into the first row of array
public void push(int num)
[Code] .....
I found this program idea online. Make a array with three stacks. Either I jump out of bounds if I use "continue" instead of "break" in my loop in the push method. If I use break the output looks like:
12900
0000
0000
0000
0000
if I use continue the output looks like:
An error has occured java.lang.ArrayIndexOutOfBoundsException: 2
1212
1212
1212
1212
1210
View Replies
View Related
Aug 6, 2014
How to build an array that calls methods if i understand it correctly .... if this is possible a simple example of this.
View Replies
View Related
Dec 5, 2014
I made a method which takes values from a data set and finds out which one is the highest value. When it finds the highest value, it returns the country which is associated with the value. Here's the data set.
"Country""Total CO2 2005 (million tonnes)""Road CO2 (million tonnes)""Road CO2 per person (tonnes)""Cars per 1000 people"
10
USA5951.131530.35.16777
UK2573.4119.681.99470
Italy476.08116.862592
Germany841.78150.211.82550
Canada553.02123.423.82562
France414.03128.132.04477
Russia1575.44114.690.8178
Japan1254.47224.241.76447
China5100.6228.020.317
India1147.4691.060.18
So if the number was 5951.13 then the program would return USA. How do I do that? I've already started on trying to get this code to work but it doesn't seem to compiler so what's wrong with it?
public static CO2Data highest (CO2Data [] arr2){
Scanner sc = new Scanner(System.in);
CO2Data highestindex = arr2[0];
CO2Data currentcountry = arr2[0].getCountry(sc.nextLine());
[Code] ....
Also the array is a CO2Data array which is part of the following class:
public class CO2Data { //The CO2Data class will be called in other methods
private String country; //A private variable will prevent other users from accessing and changing these variables.
private double totalCO2;
private double roadCO2;
private double CO2PerPerson;
private int carsPerPerson;
public CO2Data() {
country = "";//this sets the initial values for the different variables
[code].....
View Replies
View Related
Jun 25, 2014
I can now call the DB on the query I want and return results. What I know want to do is build an array of the data, forward it to the JSP page and display the bits individually.
So THis is the Servlet I havce:
package com.journaldev.jdbc.datasource;
import java.awt.List;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
[code]...
I think It is to do either with the way I am adding the values to User or its the forward:
getServletConfig().getServletContext().getRequestDispatcher("/test.jsp").forward(request, response);
View Replies
View Related
Jan 16, 2014
I'm studying about arrays and I have some questions:
First, is there any difference between these two?
Java Code:
int x[] = new int[3];
int[] x = new int[3]; mh_sh_highlight_all('java');
It seems to me when I try them they do exactly the same, is that correct?
Second, more important question. If I want to make an int variable that refers to the index number of an array, how do I write? For example if we have
Java Code: String[] string = new String[10]; mh_sh_highlight_all('java');
And I want to have a variable "int n" that refers to an index number, so that if I set n = 5 then string[5] is selected. Note that the int n is NOT an array, but just a regular integer variable. How can I do that?
View Replies
View Related
Feb 25, 2015
How do I put this code in a way that it works because I know it is probably something obvious but I cant find how to make the array readable without error. It is supposed to intake two values and output what day of the week it is.
Testing Program
Initial day: Monday
Next day: Tuesday
Next day again: Wednesday
Previous day: Tuesday
Next week: Tuesday
Add 4 days from initial day: Friday
[Code] ....
ERROR ; Days.java:5: error: class, interface, or enum expected
String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
^
1 error
View Replies
View Related
Jun 8, 2014
im trying to make a linear search method to check if a number 'n' is included in an array.
PHP Code:
package test;
public class Recursion {
public static void main(String[] args) {
}
static int linearSearch(int n, int[] array)
[code]....
Im getting the following error: this method must have a result type of type int ?? i already have a return type of type int...
View Replies
View Related
May 8, 2014
We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)
These are our instructions:
Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:
[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);
[code]....
View Replies
View Related
Aug 16, 2014
I want to ask how to make Palindrome in Java with 2 methods //Output is Like this
Input a word
Hey
Not a Palindrome
Reverse
yeH
View Replies
View Related
Aug 22, 2014
I am stuck. I was trying to make my own Color to use with awt.
I used the statement :
public static final Color purple = new Color(255,0,255);
When I try to use Color.purple it says it cannot reference purple.
View Replies
View Related
Nov 3, 2014
I first learned how to program with BYOB. In BYOB there were variables and lists. Variables worked the same as Java and lists were groups of variables. To create a list, I would give it a name. I could then add variables to this list as items throughout the program. Here's an example of what a list would look like:
[[List]]
item 1: Hello
item 2: world
I could then call upon item 1 or item 2 and delete them if needed. In Java, I want to have 3 lists of variables into which I put user input as variables. The code would look something like the following: (stuff with "//" at the end is detailing what I want to do, not actual working code)
import java.util.*;
public class Archives {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
Feb 3, 2014
I do not know how to make the loop end. I think there is an issue with my second and thrid algorithms..Also its a commission calculator
--- Update ---
//Start Program
package commission;
import java.util.Scanner;
public class Commission
{
private static boolean saleTargetrange;
[code]....
View Replies
View Related
Oct 17, 2014
Do I want to make something like this:
*****
*.....*
*.....*
*.....*
*****
I am stuck, I have made a code that creates this and don't know how to complete it.
*****
* *
* *
* *
*****
Code:
class Main {
public static void main( String args[] ) {
System.out.print("#Enter number of stars :");
int stars = BIO.getInt();
[Code] ....
View Replies
View Related
Apr 16, 2015
I am currently in the progress of making a GUI for a project. I am trying to make a maze and I need it displayed in a GUI. So, I thought I would be able to do that with a text file that I created. The code I have for it so far runs and compiles but it is not displaying my text file as a GUI, even though it reads the file. All I get are a bunch of green rectangles. I am using Netbeans to code this
package rectangles;
import java.awt.Color;
import java.awt.Graphics;//this will draw the maze
import java.awt.Graphics2D;//
import java.io.BufferedReader;
import java.io.FileNotFoundException;//handles file
[code]....
View Replies
View Related
Oct 30, 2014
public static final String NAME="JAVATAR";
"final" makes sure the constant has the same value and prevents it from being changed. So why add "static" to make it a constant. I figured the reason a few weeks back but don't remember it now.
View Replies
View Related
Feb 18, 2015
I've been learning Java in school for lika a year now. Our teacher wanted us to make a game called "Game of Life" .Now it's not very optimized because the only type of GUI we know how to make it with JButtons so if I want a 100x100 grid that means the program has to load 10000 buttons and change text and color on them which I can imagen cause lags and so on but if we ignore that lagg our teacher wanted us to make it loop-able and well I kinda succeeded but the only problem is that I can't get it to wait between every loop so if I tell the program to loop 100 times, the program processes that and that takes forever and then updates the board and sometimes it takes forever and sometimes you cant even see the "cells" moving. Is it possible to get my program to loop and if so how? Here is the code:
//------------------------------------------------------------------------------------------------------------------------
// Hamta standardpaket
//------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[code]....
View Replies
View Related
Jan 9, 2015
I needed to make a switch with a string ,but eclipse told met there was an error and that the fix was to switch to 1.7 compliant. I did so and now when i run my program errors come back.
Here are the errors :
Exception in thread "main" java.lang.UnsupportedClassVersionerror: start : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
[code]....
View Replies
View Related
Sep 25, 2014
I want to know how can I make a JPanel slide to to another JPanel (Slowly move to the next). I've made multiple JPanels so when I click on next it will take me to the next panel. Now I just need to add a nice transition to make my program look nicer. Is there an easy way to do it? or any way is fine I just want to add a transition ....
View Replies
View Related
Oct 27, 2014
I am having trouble making my image move to a certain position in a certain amount of time which is set inside a text file. I was wondering what I'm doing wrong and what I'm missing.
import java.io.*;
import java.util.*;
import java.io.FileReader;
public class Animator {
EZImage HP;
[code]....
View Replies
View Related
Jan 23, 2014
First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?
Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?
Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.
Fourth, I want to set an icon for the game, the code is running, but not doing anything.
Java Code: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("/Users/MW/Downloads/petericon.jpg")); mh_sh_highlight_all('java');
View Replies
View Related