Numbering Array Items Numerically?

Mar 11, 2015

I tried implementing the bubble sort algorithm into my code, but now my output for the second array (in my code) is giving me a ton of zeros. How I can fix it so the zeros are removed and the only thing that remains in the output for my second array are the fixed numerically?

The first array is the original list of items, and the second array is a copy of the first array, but numerically adjusted.

public static void main(String[] args) {
System.out.println("Input up to '10' numbers for current array: ");
int[] array1 = new int[10];
int i;
Scanner scan = new Scanner(System.in);

[code]...

View Replies


ADVERTISEMENT

Shopping Cart Using Array Of Items

Nov 5, 2014

I am working on a project. It is a shopping cart java program that should be setup with an array size of 5 and increased at increments of 3 if you go over 5 items. When I go over 5 items in increases however it changes the item names to null. See output below.

Here is the actual assignment:

In this exercise you will complete a class that implements a shopping cart as an array of items. The file Item.java contains the definition of a class named Item that models an item one would purchase. An item has a name, price, and quantity (the quantity purchased). The file ShoppingCart.java implements the shopping cart as an array of Item objects.

1.Complete the ShoppingCart class by doing the following:

a.Declare an instance variable cart to be an array of Items and instantiate cart in the constructor to be an array holding 5 Items.
b.Fill in the code for the increaseSize method. Your code should be similar to that in the CDCollection class handout but instead of doubling the size just increase it by 3 elements.
c.Fill in the code for the addToCart method. This method should add the item to the cart and update the totalPrice instance variable (note this variable takes into account the quantity).
d. Add a getTotalPrice() method to return the totalPrice.
e..Compile your class.

2.Write a program that simulates shopping. The program should have a loop that continues as long as the user wants to shop. Each time through the loop read in the name, price, and quantity of the item the user wants to add to the cart. After adding an item to the cart, the cart contents should be printed along with a subtotal. After the loop, print a "Please pay ..." message with the total price of the items in the cart. Compile and run this class.

OUTPUT

Enter the name of the item: Apples
Enter the unit price: .5
Enter the quantity: 1

Shopping Cart

ItemUnit PriceQuantityTotal
Apples$0.501$0.50
Total Price: $0.50
Continue shoppping (y/n)?
y
Enter the name of the item: Oranges
Enter the unit price: .5
Enter the quantity: 1

[Code] .....

View Replies View Related

Why Sections Not Sorting Numerically

Jan 9, 2015

I'm trying to troubleshoot on some existing code that is causing some confusion for me. The code is a snippet from a navigation display that displays Sections of an image. Each section is actually a total of 75 pages and I have an image that is being returned with over 3000 pages. Depending on other images being returned, I won't always know how many total pages or total sections will be returned.

The issue is that when the section numbers are being returned on the screen (strSectionURL = "Section "+ strSectionNumber; ) they are not in numeric order on the display. For example, instead of being 1 - 10 as they are returned (the XML response shows me the section numbers are being retrieved in numerical order), they come back "Section 4, Section 1, Section 10, etc when the URLs are displayed.

Why do they not show in numerical order on the navigation display?

Copy of the class:
NavDisplay.txt

String strInvocationId = null;
 String strStatusString = ImageDisplayHelperBean.IMG_STAT_ERROR;
 StringBuffer sbfStatus = new StringBuffer();
String strStatus = null;
String strCSSClass = "IMAGE_ERROR";
String strSectionURL = null;
 
[Code] ....

View Replies View Related

Adding Array Of Items To Linked List

Sep 21, 2014

I'm having trouble completing my homework. The problem:

>Suppose that you want an operation for the ADT list that adds an array of items to the end of the list. The header of the method could be as follows:
public void addAll(T[] items)

>Write an implementation of this method for the class LinearLinkedList

At first this seemed like an easy problem to me. This is the solution I came up with:

public void addAll(T[] items) {
int length = items.length;
for(int i = 0 ; i < length; i++){
this.addLast(items[index]);
}
}

However, one of the requirements for the assignment is that we're not allowed to use the addLast method. how else to insert items to the Linked List without this method. These are the user-defined LinearLinkedList and ListNode classes we made during class:

**LinearLinkedList**
// Linear linked list class
import java.util.NoSuchElementException;
public class LinearLinkedList {

[code]....

View Replies View Related

Numerically Computing Binomial Coefficient

Jan 29, 2015

So I was given the program that calculates N!/[R!(N-R)!] and it has an overflow error after it passes N=18 and then starts spiting out incorrect answer. I'm supposed to figure out a way to protect the user from getting erroneous results when computing the formula (i.e. N!/[R!(N-R)!]).

HERE IS THE PROGRAM:

public class Combination {
private static final int defaultNMax = 30;
public Combination() {}
int compute(int N, int R) {
int i;
int numerator;
int denominator;
numerator = 1;

[Code] .....

HERE ARE THE RESULTS IF YOU WANT TO SEE THEM:

N=1C(1,0)=1
N=2C(2,1)=2
N=3C(3,1)=3
N=4C(4,2)=6
N=5C(5,2)=10
N=6C(6,3)=20
N=7C(7,3)=35

[Code] .....

View Replies View Related

Using Private ArrayList Of Items?

Apr 29, 2014

It isn't messing up it just keeps making me make my arraylist static and i'm not sure why.

public class driver
{
private static ArrayList<AddItems> items;
public driver()

[Code]....

View Replies View Related

EJB / EE :: How To Search Items In ArrayList

Jan 26, 2015

I try to create a jsf project within ejb which is add new car with entering attributes listing attributes and search by make.

Add and list methods working well , but have problem of list method. I tryed many combinations (using enhanced loop, iterative loop) but i cant provide working well. Always outputText returns nothing ,when i enter attributes.

Here is ejb code for adding ,getting and listing car items :

@Stateful
public class CarsBusiness implements CarsBusinessLocal {
List<Car> cars;
public CarsBusiness() {
cars = new ArrayList<Car>();

[Code] .....

View Replies View Related

JSP :: How To Iterate Over Supplied Items

Mar 11, 2014

I facing issue with nested <c:forEach in my jsp page.I am using jstl.jar..Here is my code

in JAVA I have -->
List<ProductDefViewBean> productList = new ArrayList<ProductDefViewBean>();
productList.add(objProductDefViewBean);
request.setAttribute("ProductList", productList);
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

[code]...

javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>

View Replies View Related

Adding Items To The Game

Jan 4, 2015

I made my items class and I am storing my item as a String array to list them all and what I want to be able to do is type pickup, have the game read my location and display the items that are avaible to pickup at current location then type the item and store it in my playerInventory. Then, have it check the slot if it is doesn't equal null go to next.

Use a boolean value of 0 = false and 1 = true. then, have it check if the inv array = 1 or 0. if 1 go to next inv. If all are full then, ask player if they would like to replace an item. Use a 2d array for storage for slots and true or false value.

Here is my code

Player.java
package com.PenguinGaming;
import java.util.Random;
import java.util.Scanner;
public class Player {
public void User(){
Commands commands = new Commands();
Map map = new Map();

[Code] .....

View Replies View Related

How Can Items Be Added To List

Feb 13, 2014

I have the following code. how can items be added to that list?

private List<IComponentNode> comp;
interface IAAAView {
  // returns component with given code or null
  IComponentNode findComp(String a);
  // returns component with given renderer or null

[Code] .....

View Replies View Related

Changing Items On The Main Mac Menu

Apr 17, 2014

How would I change items in the main menu (top of screen) that has the app's name on it (e.g. Firefox)? I've used :

System.setProperty("apple.laf.useScreenMenuBar", "true");

And it works, but how would I change things like "About [thisapp]" and make it execute a certain method?

View Replies View Related

Compare Selected Items From Two Arrays

Nov 16, 2014

I need to somehow compare the random color chosen from the color array and the random name selected from the name array. I know how to compare to entire arrays of the same type such as integers. How to go about this with two different arrays. I thought maybe I could parse the color array selection to a string but had no luck with that either.

Problem #1: Design and implement an Applet that plays a simple game to teach a child to read. The game displays a picture on the left hand side of the Applet and a word on the right hand side. Below the pictures are two buttons for the child to click--one if the word matches the picture, the second of the word doesn't match the picture. Display an error message if the child is incorrect (or play a sound). Display (or play a sound) display words of encouragement if the child chooses correctly. Add a loop so the child can keep playing.

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Random;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Limit Items Per Row For JScrollPane?

Mar 3, 2014

When I add to a JScrollPane (I'm adding to a JPanel then putting that in the scroll pane) it displays as many items in one row as possible. How can I make it so that it only displays one per row?

View Replies View Related

Deleting A Block Of Items From ArrayList

Jan 7, 2015

My current lesson in Java is about ArrayLists and I'm having a tough time to understand this bit of code: This exercise is concerned with the problem of deleting a block of items from an ArrayList.

public static void deleteBlock( ArrayList<String> strings, int n )
{
for ( int i = 0; i < n; i++ )
{
if ( strings.size() > 0 )
strings.remove( i );

[Code] ....

This is the output: [rosion, sion, on, n]

View Replies View Related

Swing/AWT/SWT :: Possible To Use Items In ComboBox To Prefix File Name?

Oct 8, 2014

If I have a comboBox full of id's - is it possible that when I choose said id (click it) it will then transfer over into my textField where I can use that as a prefix for my filename ...

(The file can be created just by having a name in the text field it doesn't need to already exists) ...

View Replies View Related

JSP :: How To Add New Checkbox Activate Selected Items On Page

Jul 16, 2014

I am working on a web application for store file maintenance. Need to add a new Check Box "Activate Selected Menu items" on the page.

what code i should write to add a Check Box.

View Replies View Related

Using Arraylist Index And Items As Hashmap Key And Values?

Apr 6, 2014

I am working on the Kevin Bacon - 6 degrees of bacon problem. I want to take my Array List and use the index and Values that I have saved in it as the Key and Value of a Hashmap. Below is my code.

HashMap<Integer, ArrayList<String>> actors =
new HashMap<Integer, ArrayList<String>>();
ArrayList array = new ArrayList();
try (BufferedReader br = new BufferedReader(
new FileReader("actors.txt"));)

[code]...

saving each one in it's own spot. I want to use the index of each one as the key to find it in the Hashmap....

View Replies View Related

ArrayList Only Adding 1 Item When There Are Multiple Items

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");
method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
if(files.hasReadData) {

[Code] ....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[Code] ....

View Replies View Related

Text Based Game Adding Items

Apr 11, 2014

I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns :

java.lang.NullPointerException
at Room.addItem(Room.java:107)
at Game.createRooms(Game.java:133)
at Game.<init>(Game.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

[Code] .....

Here are the classes that matter for this particular situation

import java.util.HashMap;
public class Item
{
private HashMap<String, Item> itemList;
private String name;
private String itemDescription;

[Code] ....

I know that it is the line

itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));

In the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly....

View Replies View Related

Opening New Forms Related To Items In List

Oct 3, 2014

I want to create a program which contains a list with 5 items and a button on the first display. The desired option is chosen from from the list and the button is pressed. On pressing the button it must open a new form which corresponds to the chosen item from the list.

View Replies View Related

GUI Program - Process That Will Record All Ordered Items

Oct 11, 2014

I can't finish my project in my OOP subject,Ordering System Program,but i am finished with the layout and some processes.

I have complication in which i don't know how to code a process that will record all the ordered items.

i have items like [MS1]Taro Milk Tea.. and there's this textbox that will will get the inputted text and get the quantity of it by JOptionPane.

There's this another JOptionPane that will show the order(s) when "Show Order" button is clicked.

My main problem is i can't record additional items if i want to add more . and my variables are all stored in an array.

Any different way of getting the order,quantity,price of it and Sum all of it and Display the Ordered items...

My professor required that we used inheritance so i have 2 subclasses..

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MilkteaGUI extends JFrame implements ActionListener,WindowListener {
MtGUIProcess mg = new MtGUIProcess();
Label cardNo = new Label("Card Number:");

[Code] ....

View Replies View Related

Display Inventory In Console - Retail Items

Apr 7, 2014

Why does it keep giving me the error saying that RetailItem[] inventory not found(from the parameter) if its stated above?

RetailItem[] inventory = {jacket, jeans, shirt};
//Display the inventory in the console
display(inventory)
//Process a series of RetailItem sales
processSales(inventory);

//Display the updated inventory of Retailitems
display(inventory);

[Code] .....

View Replies View Related

How To Get Past Loading In Items From Text File

Oct 2, 2014

I am not sure why I am getting this error. The code is not finished at all, but I am stumped on how to get past loading in the things from the text file. Here is my code:

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Hurricanes2
{
public static void main(String[] args)throws IOException
{
//declare and initialize variables
 
[code]...

It compiles fine, but when I execute it I get this.

View Replies View Related

GUI Database Output - League Of Legends Items

Jan 29, 2015

I'm making a small database GUI program in Java where the user is able to choose 1 out of 4 options they would want to know. i.e. They click the "League of Legends Items" button and will be prompted with an option pane for input. The files containing these items are already constructed but when input is entered into the option dialog box no output is received. I figured I would need some sort of while loop that gets a line from the text file and checks up to a substring in order to make sure it is the same as the input and then outputs what the user requested. I figured it would also have to be the same for the options except with pictures and other text to follow through. For example, the user clicks the "Champions"button where it runs through the file of champions till it finds the one requested and then displays the associated picture with it. As of now, no button displays an output after user enters an input

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.io.IOException;
import java.util.Scanner;
public class LoLDatabase extends JFrame implements ActionListener{

JButton summoner;
JButton guides;

[Code] ....

View Replies View Related

Get Certain Number Of Items And Then Calculate How Much Every Item Cost

Jan 4, 2015

This is supposed to get a certain number of items, and then calculate how much every item costs. It adds up the sum of those prices and checks if it is over 150$, if it is, it returns true, if it's not, it returns false.

import java.util.*;
class Cust
{
public static boolean DelPay (int a) {
Scanner reader=new Scanner (System.in);
int b,s=0;
for (int i=1;i<=a;i++) {
b=reader.nextInt();
s=s+b;
}
if (s>150)
return true;
return false;
}
}

View Replies View Related

JavaFX 2.0 :: Binding ListView Selected Items

Oct 19, 2014

I want to synchronize a List<String> with the selected items of a ListView. In the real project, I want to synchronize the selected items of a TreeView and the selected images of a galery (custom control).
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;

[Code] ....
 
In most cases, the program works as expected but sometimes there are some issues.
 
- For example, when I launch the application and select all the items with Ctrl-A, the event { [One, Two, Three] added at 0,  } is fired so the list of strings contains incorrectly 4 elements [One, Two, Three, One].
 
- Another example, when selecting all the items (with Shift+End), two events are fired { [One] removed at 0,  } and { [One, Two, Three] added at 0,  }, that's correct. But when I remove the last element with Shift-Up, 3 events are fired  { [Two] removed at 1,  },  { [Three] removed at 2,  } and { [Two] added at 1,  } and an exception is thrown:

java.lang.IndexOutOfBoundsException: toIndex = 3
    at java.util.ArrayList.subListRangeCheck(ArrayList.java:1004)
    at java.util.ArrayList.subList(ArrayList.java:996)
    at com.sun.javafx.binding.ContentBinding$ListContentBinding.onChanged(ContentBinding.java:111)

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved