Need help with adding arrays to invoice.java please willing to pay?
Using your Invoice class created in lab02, write a client program that allows the user to input three Invoice objects into an array of Invoice objects. After you have inputted all of the invoices, print a heading and then output all of the array elements (Invoice objects) by calling the method from your Invoice class that displays all of the data members on a single line using uniform field widths to insure that all Invoice objects will line up in column format (created in Lab04). At the end of the loop, display the calculated total retail value of all products entered in the proper currency format.
Example of possible program execution:
Part Number : WIDGET
Part Description : A fictitious product
Quantity : 100
Price : 19.95
(etc.)
Example of possible output
Part Number Part Description Quantity Price Amount
WIDGET A fictitious product 100 19.95 199.95
Hammer 9 pounds 10 5.00 50.00
(etc.)
Total Retail Value: 249.95
This is what i have so far Invoice Test
//Lab 2 InvoiceTest.java
//Application to test class Invoice.
//By Morris Folkes
public class InvoiceTest
public static void main( String args[] )
Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
// display invoice1
System.out.println( "Original invoice information" );
System.out.printf( "Part number: %s\n", invoice1.getPartNumber() );
System.out.printf( "Description: %s\n",
invoice1.getPartDescription() );
System.out.printf( "Quantity: %d\n", invoice1.getQuantity() );
System.out.printf( "Price: %.2f\n", invoice1.getPricePerItem() );
System.out.printf( "Invoice amount: %.2f\n",
invoice1.getInvoiceAmount() );
// change invoice1's data
invoice1.setPartNumber( "001234" );
invoice1.setPartDescription( "Blue Hammer" );
invoice1.setQuantity( 3 );
invoice1.setPricePerItem( 19.49 );
// display invoice1 with new data
System.out.println( "\nUpdated invoice information" );
System.out.printf( "Part number: %s\n", invoice1.getPartNumber() );
System.out.printf( "Description: %s\n",
invoice1.getPartDescription() );
System.out.printf( "Quantity: %d\n", invoice1.getQuantity() );
System.out.printf( "Price: %.2f\n", invoice1.getPricePerItem() );
System.out.printf( "Invoice amount: %.2f\n",
invoice1.getInvoiceAmount() );
Invoice invoice2 = new Invoice( "5678", "PaintBrush", -5, -9.99 );
// display invoice2
System.out.println( "\nOriginal invoice information" );
System.out.printf( "Part number: %s\n", invoice2.getPartNumber() );
System.out.printf( "Description: %s\n",
invoice2.getPartDescription() );
System.out.printf( "Quantity: %d\n", invoice2.getQuantity() );
System.out.printf( "Price: %.2f\n", invoice2.getPricePerItem() );
System.out.printf( "Invoice amount: %.2f\n",
invoice2.getInvoiceAmount() );
// change invoice2's data
invoice2.setQuantity( 3 );
invoice2.setPricePerItem( 9.49 );
// display invoice2 with new data
System.out.println( "\nUpdated invoice information" );
System.out.printf( "Part number: %s\n", invoice2.getPartNumber() );
System.out.printf( "Description: %s\n",
invoice2.getPartDescription() );
System.out.printf( "Quantity: %d\n", invoice2.getQuantity() );
System.out.printf( "Price: %.2f\n", invoice2.getPricePerItem() );
System.out.printf( "Invoice amount: %.2f\n",
invoice2.getInvoiceAmount() );
} // end main
} // end class InvoiceTest
i suck in java There are 2 possible reasons for this:
1. you haven't studied
2. you aren't cut out for programming
and there r hardly any tutors at my school. plus i work 2 jobs day n night. Please, I'm only want help thats allYou have the help of the ENTIRE WORLD COMMUNITY right here, right now. But you're not willing to make any effort whatsoever. You think people will help or even respect you? You may fail your class and you may fail in life!
Cheaters don't win and winners don't cheat!
Similar Messages
-
Need help with adding emoji to my hubby's phone don't see it when I click on the keyboard tab
I need help with adding emoji to my hubby's iPhone when I go to settings then the keyboard tab it's not there
I did that bad it's not there and doesn't give me to option to click on it
-
I need help with my Iphone 4 reset cause I will activate it in other country
I need help with my Iphone 4 reset cause I will activate it in other country
ThanksHelp you what?
You have provided no information about your issue or what you are trying to do. -
HT4199 I need help with getting my printer to print, PLEASE.
I need help with getting my printer to print, Please.
What have you done so far?
I suggest you connect it via a usb cable first. Once you get the printer working, move to wifi. You will have to use an existing printer usb cable or purchase a cable. Be sure to get the correct cable. Ask for help.
The warrenty indicates there is phone support. Give HP a call.
Warranty
One-year limited hardware warranty; 24-hour, 7 days a week phone support
Robert -
MOVED: need help with my k7n2 delta series motherboard please
This topic has been moved to AMD SocketA based board.
need help with my k7n2 delta series motherboard please"...the other memory ive been using is memorymaxx 512mb ddr 3200..." If I understood right, your'e actually using both memories at same time so, your'e lucky if it works. We have said thousand times that mixing dif. brand/make/speed memories is a bad idea, most with this Mobo that is very picky about ram. If you want to avoid slowdown problems, stay with only one stick ( the better one ) until you can buy at same time in same store, 2 identical memories to replace the old one.
-
I need help with this portion of my program, it's supposed to loop through the array and pull out the highest inputted score, currently it's only outputting what is in studentScoreTF[0].
private class HighScoreButtonHandler implements ActionListener
public void actionPerformed(ActionEvent e)
double highScore = 0;
int endScore = 0;
double finalScore = 0;
String tempHigh;
String tempScore;
for(int score = 0; score < studentScoreTF.length; score++)
tempHigh = studentScoreTF[score].getText();
tempScore = studentScoreTF[endScore].getText();
if(tempHigh.length() < tempScore.length())
highScore++;
finalScore = Double.parseDouble(tempScore);
JOptionPane.showMessageDialog(null, "Highest Class Score is: " + finalScore);This is another part of the program, it's supposed to loop through the student names array and pull out the the names of the students with the highest score, again it's only outputting what's in studentName[0].
private class StudentsButtonHandler implements ActionListener
public void actionPerformed(ActionEvent e)
int a = 0;
int b = 0;
int c = 0;
double fini = 0;
String name;
String score;
String finale;
String finalName = new String();
name = studentNameTF[a].getText();
score = studentScoreTF.getText();
finale = studentScoreTF[c].getText();
if(score.length() < finale.length())
fini++;
name = finalName + finale;
JOptionPane.showMessageDialog(null, "Student(s) with the highest score: " + name);
} Any help would be appreciated, this is getting frustrating and I'm starting to get a headache from it, lol.
Edited by: SammyP on Oct 29, 2009 4:18 PM
Edited by: SammyP on Oct 29, 2009 4:19 PMHeres a working example:
class Compare {
public int getHighest(int[] set) {
int high = set[0];
for(int i = 0; i < set.length; i++) {
if(set[i] > high) {
high = set;
return high; -
Hello guys need help with reverse array
Need help reversing an array, i think my code is correct but it still does not work, so im thinking it might be something else i do not see.
so far the input for the array is
6, 25 , 10 , 5
and output is still the same
6 , 25 , 10 , 5
not sure what is going on.
public class Purse
// max possible # of coins in a purse
private static final int MAX = 10;
private int contents[];
private int count; // count # of coins stored in contents[]
* Constructor for objects of class Purse
public Purse()
contents = new int[MAX];
count = 0;
* Adds a coin to the end of a purse
* @param coinType type of coin to add
public void addCoin(int coinType)
contents[count] = coinType;
count = count + 1;
* Generates a String that holds the contents of a purse
* @return the contents of the purse, nicely formatted
public String toString()
if (count == 0)
return "()";
StringBuffer s = new StringBuffer("(");
int i = 0;
for (i = 0; i < count - 1; ++i)
s.append(contents[i] + ", "); // values neatly separated by commas
s.append(contents[i] + ")");
return s.toString();
* Calculates the value of a purse
* @return value of the purse in cents
public int value()
int sum = 0; // starts sum at zero
for( int e : contents) // sets all to e
sum = sum + e; //finds sum of array
return sum; //retur
* Reverses the order of coins in a purse and returns it
public void reverse()
int countA = 0;
int x = 0;
int y = countA - 1; // 5 - 1 = 4
for (int i = contents.length - 1; i >=0 ; i--) // 4, 3 , 2, 1, 0
countA++; // count = 5
while ( x < y)
int temp = contents[x];
contents[x] = contents [y];
contents [y] = temp;
y = y- 1; // 4 , 3 , 2, 1 , 0
x = x + 1 ; // 0 , 1, 2 , 3 , 4
}ok so i went ahead and followed what you said
public void reverse()
int a = 0;
int b = contents.length - 1;
while (b > a)
int temp = contents[a];
contents[a] = contents;
contents [b] = temp;
a++;
b--;
}and its outputting { 0, 0, 0, 0}
im thinking this is because the main array is has 10 elements with only 4 in use so this is a partial array.
Example
the array is { 6, 25, 10, 5, 0, 0, 0, 0, 0, 0,}
after the swap
{0, 0 , 0 , 0, 0 , 0 , 5 , 10 , 25, 6}
i need it to be just
{ 5, 10, 25, 6}
so it is swapping the begining and end but only with zeroes the thing is i need to reverse the array without the zeroes -
I need help with setting up my Sun Java Studio Creator
Hello all, i need help with setting up the Studio Creator, i"m new to all that staff so is there anyone to help me just a little with all that if yes email me at [email protected] or get me on AOL Instant Messanger with the screen name: wretch17
thanks :-)Hi,
Welcome to the Creator community! Thanks for your interst in Sun Java Studio Creator. Please feel free to post any question related to creator on this forum .
Take a look the creator website at
http://developers.sun.com/prodtech/javatools/jscreator/
CreatorTeam -
Need Help with simple array program!
Hi, I have just recently started how to use arrays[] in Java and I'm a bit confused and need help designing a program.
What this program does, it reads in a range of letters specified by the user. The user then enters the letters (a, b or c) and stores these characters into an array, which the array's length is equal to the input range the user would enter at the start of the program. The program is then meant to find how many times (a,b and c) appears in the array and the Index it first appears at, then prints these results.
Here is my Code for the program, hopefully this would make sense of what my program is suppose to do.
import B102.*;
class Letters
static int GetSize()
int size = 0;
boolean err = true;
while(err == true)
Screen.out.println("How Many Letters would you like to read in?");
size = Keybd.in.readInt();
err = Keybd.in.fail();
Keybd.in.clearError();
if(size <= 0)
err = true;
Screen.out.println("Invalid Input");
return(size);
static char[] ReadInput(int size)
char input;
char[] letter = new char[size];
for(int start = 1; start <= size; start++)
System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
input = Keybd.in.readChar();
while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#'))
Screen.out.println("Invalid Input");
System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
input = Keybd.in.readChar();
while(input == '#')
start == size;
break;
for(int i = 0; i < letter.length; i++)
letter[i] = input;
return(letter);
static int CountA(char[] letter)
int acount = 0;
for(int i = 0; i < letter.length; i++)
if(letter[i] == 'a')
acount++;
return(acount);
static int CountB(char[] letter)
int bcount = 0;
for(int i = 0; i < letter.length; i++)
if(letter[i] == 'b')
bcount++;
return(bcount);
static int CountC(char[] letter)
int ccount = 0;
for(int i = 0; i < letter.length; i++)
if(letter[i] == 'c')
ccount++;
return(ccount);
static int SearchA(char[] letter)
int ia;
for(ia = 0; ia < letter.length; ia++)
if(letter[ia] == 'a')
return(ia);
return(ia);
static int SearchB(char[] letter)
int ib;
for(ib = 0; ib < letter.length; ib++)
if(letter[ib] == 'b')
return(ib);
return(ib);
static int SearchC(char[] letter)
int ic;
for(ic = 0; ic < letter.length; ic++)
if(letter[ic] == 'c')
return(ic);
return(ic);
static void PrintResult(char[] letter, int acount, int bcount, int ccount, int ia, int ib, int ic)
if(ia <= 1)
System.out.println("There are "+acount+" a's found, first appearing at index "+ia);
else
System.out.println("There are no a's found");
if(ib <= 1)
System.out.println("There are "+bcount+" b's found, first appearing at index "+ib);
else
System.out.println("There are no b's found");
if(ic <= 1)
System.out.println("There are "+ccount+" c's found, first appearing at index "+ic);
else
System.out.println("There are no c's found");
return;
public static void main(String args[])
int size;
char[] letter;
int acount;
int bcount;
int ccount;
int ia;
int ib;
int ic;
size = GetSize();
letter = ReadInput(size);
acount = CountA(letter);
bcount = CountB(letter);
ccount = CountC(letter);
ia = SearchA(letter);
ib = SearchB(letter);
ic = SearchC(letter);
PrintResult(letter, acount, bcount, ccount, ia, ib, ic);
return;
} Some errors i get with my program are:
When reading in the letters to store into the array, I get the last letter I entered placed into the entire array. Also I believe my code to find the Index is incorrect.
Example Testing: How many letters would you like to read? 3
Enter letter (a, b or c) (# to quit): a
Enter letter (a, b or c) (# to quit): b
Enter letter (a, b or c) (# to quit): c
It prints "There are no a's'" (there should be 1 a at index 0)
"There are no b's" (there should be 1 b at index 1)
and "There are 3 c's, first appearing at index 0" ( there should be 1 c at index 2)
The last thing is that my code for when the user enters "#" that the input of letters would stop and the program would then continue over to the counting and searching part for the letters, my I believe is correct but I get the same problem as stated above where the program takes the character "#" and stores it into the entire array.
Example Testing:How many letters would you like to read? 3
Enter letter (a, b or c) (# to quit): a
Enter letter (a, b or c) (# to quit): #
It prints "There are no a's'" (should have been 1 a at index 0)
"There are no b's"
and "There are no c's"
Can someone please help me??? or does anyone have a program simular to this they have done and would'nt mind showing me how it works?
Thanks
lou87.Without thinking too much...something like this
for(int start = 0; start < size; start++) {
System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
input = Keybd.in.readChar();
while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#')) {
Screen.out.println("Invalid Input");
System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
input = Keybd.in.readChar();
if(input == '#') {
break;
letter[start] = input;
}you dont even need to do start = size; coz with the break you go out of the for loop. -
Need help with an array function
I'm using the array index function and i would like to be able to control what elements go out on it. For example, if i wanted only the first element to go out, i don't want the second element to send out zero. Is there any way i can control what elements leave the array index function. I also don't understand what the index inputs do on that function either. If anyone has any advice on the application or can modify it in any way, please help.
Attachments:
Array and for loop.vi 1190 KBThe index inputs determine what elements are retrieved. For example of you would wire a 10 and a 20 to your two index inputs, you would bet element #10 and element #20 of your array. You can resize it to get any desired number of elements.
If you don't wire the index inputs, you'll get the first two elements.
If you only wire the top index input (e.g a 10), you'll get element #10 and #11.
LabVIEW Champion . Do more with less code and in less time . -
Need help with adding a second pc to my account
Hi guys. I was using an MacBook when first downloaded digital add and purchased a book, I have since moved to a windows 8 machaine and tried to autorise it so I could view my books
I now get a E ADPET REQUEST EXPIERED
How can I view my bought books on my new device?
Thanks[snip]
I have this so far, and it works as a good high low
game, could someone please help me add in the
following?:
-Player wins $2 with first correct guess, and amount
won doubles with every correct guess.
-Player can opt out and keep his money.You will need another option to your play menu to support the user bailing and keeping his money. You will also need an variable to hold the player's accumlated winnings.
-Player is given the option to play again at the end
of the game.You'll need another loop around the whole thing and you will need to prompt the user for continued play.
-Winnings are accumulated across multiple games.And you'll need to put the aforementioned accumulator outside the loops.
>
Any help would be greatly appreciated.Good Luck
Lee -
Need help with adding images option
I was using the add images option a few weeks ago just fine.. using my tablet and uploading the images via usb. then all of the sudden it stopped working.
please help with this issue.
DannyA few questions. What result are you experiencing? Did PS Touch crash? Have you tried to force quit-and restart PS Touch? -Guido
-
Need help with completion and debugging...please
import java.io.*;
public class DeleteSpaces3
public static void main (String[] args)
FileReader inputFile = new File("Omerta.txt");
FileReader outputFile = new File("omertaEdited.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
public static void Spaces()
try
BufferedReader in = new BufferedReader(new FileReader("Omerta.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("OmertaEdited.txt"));
String str;
while ((str=in.readLine()) != null)
while(line.indexOf(" ") > -1)
line = line.replaceAll(" ", " ");
out.println(line);
in.close();
out.close();
catch (IOException e)
System.err.println(e);
System.exit(1);
thats my code and the program is supposed to open a text file called "Omerta" and edit it so that it takes out all the double spaces between the words in the text file...ive been told that this should work.......yet i still am unsucessful in compiling the code....all help will be greatfully appreciatedive been told that this should workThe replies to your earlier posting here:
http://forum.java.sun.com/thread.jspa?threadID=573173&messageID=2844611#2844611
did not tell you that, they told you what was wrong - and is still wrong. And, in addition, you have introduced another error in your curly braces.
You need to understand how to construct a Java class; see this tutorial:
http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html -
Need help with adding buttons.
I thought I could do this without help but I was wrong. I had to add buttons to my program and before it ran fine with the first four buttons I added but know there are many errors and I believe I messed up the whole thing now. Any advice would be greatly appreciated. Here is my code:
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame.*;
import java.io.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.awt.image.*;
public class DVDInventory6
public static void main(String[] args)
Scanner input = new Scanner( System.in );
int j;
DVD_Genre [] inventory = new DVD_Genre[5]; // Size of the array
// create DVD object
inventory [ 0 ] = new DVD_Genre( "Rocky", "Action/Drama", 01, 15, 9.95 );
inventory [ 1 ] = new DVD_Genre( "RockyII", "Action/Drama", 02, 13, 14.95 );
inventory [ 2 ] = new DVD_Genre( "Matrix", "Action/Sci-Fi", 03, 23, 14.95 );
inventory [ 3 ] = new DVD_Genre( "MatrixII", "Action/Sci-Fi", 04, 17, 19.95 );
inventory [ 4 ] = new DVD_Genre( "Bambi", "Family", 05, 33, 12.95 );
// Print out a screen title
System.out.println();
System.out.printf("Welcome to DVD Inventory:\n\n");
GUI gui = new GUI();
for(j=0; j<5; ++j)
gui.add(inventory[j]);
double total = 0;
for ( j=0; j<inventory.length; j++ )
total += inventory[j].getvalueofdvds ();
} // end for
gui.setTotal(total);
gui.display();
public static void sortDVD(DVD[] inventory)
//DVD_Genre temp[] = new DVD_Genre[1];
int i, j;
for (i=1; i <inventory.length; i++)
for (j=0; j < inventory.length-i; j++)
if (inventory[j].getdvdName().compareTo(inventory[j+1].getdvdName())>0)
// exchange elements
DVD temp = inventory[j]; //new DVD_Genre [1];
inventory[j] = inventory[j+1];
inventory[j+1] = temp; //temp [0];
}//end method main
}//end DVDInventory6
class DVD
protected String dvdName; // DVD title
protected String dvdGenre; // DVD genre
protected int productnumber; // DVD product number
protected int numberofproducts; // the number of products in stock
protected double price; // the price of the products in stock
public DVD (String name, String genre, int productnumber, int numberofproducts,
double price ) // class dvd constructor
this.dvdName = name;
this.productnumber = productnumber;
this.numberofproducts = numberofproducts;
this.price = price;
this.dvdGenre = genre;
public DVD( String name, int productnumber, int numberofproducts, double price ) //
class dvd constructor
this.dvdName = name;
this.productnumber = productnumber;
this.numberofproducts = numberofproducts;
this.price = price;
public void setdvdName( String name ) // method to set dvd name
this.dvdName = name; // store the dvd name
public String getdvdName()// method to get dvd name
return dvdName;
public void setproductnumber( int productnumber ) // method to set productnumber
this.productnumber = productnumber; // store productnumber
public int getproductnumber()// method to get productnumber
return productnumber;
public void setnumberofproducts( int numberofproducts )// method to set
numberofproducts
this.numberofproducts = numberofproducts; // store numberofproducts
public int getnumberofproducts()// method to get numberofproducts
return numberofproducts;
public void setprice( double price )// method to set price
this.price = price; // price of the products in stock
public double getprice()// method to get price
return price;
public double getvalueofdvds()// method to get valueofdvds
return numberofproducts * price;
} // end class DVD
class DVD_Genre extends DVD
private String genre; // genre of DVD
private double restockingFee; // percentage added to inventory value
//constructor
public DVD_Genre(String name, String genre, int productnumber, int numberofproducts, double
price)
super(name, genre, productnumber, numberofproducts, price);
this.genre = genre;
this.restockingFee = restockingFee;
public void setdvdGenre( String genre ) // method to set dvd genre
this.dvdGenre = genre; // store the dvd genre
public String getdvdGenre()// method to get dvd genre
return dvdGenre;
// Calculates restocking fee based on previous data.
public double restockFee() {
double total = 0;
double restock = 0;
total = numberofproducts * price;
restock = total * .05;
return restock;
public String toString()
DecimalFormat Currency = new DecimalFormat("$0.00");
return "\nDVD Title: " + dvdName + "\nDVD Genre: " + dvdGenre + "\nProduct number: " +
productnumber +
"\nNumber of products: " + numberofproducts + "\nPrice: " + price + "\nValue of
DVD's: " + Currency.format(numberofproducts * price) + "\nRestock Fee: " +
Currency.format(numberofproducts * price * .05);
}// End class DVD_Genre
class GUI {
private DVD[] dvds;
private int nCount;
private double total;
// Creates array DVD[]
GUI() {
dvds = new DVD[5];
nCount = 0;
public void add(DVD dvd) {
dvds[nCount] = dvd;
++nCount;
public void setTotal(double total)
this.total = total;
DecimalFormat Currency = new DecimalFormat("$0.00");
//Displays the arrays contents element by element into a GUI pane
public void display() {
GUIDisplay(dvds, 5);
public void GUIDisplay(DVD[] products, int numOfProducts)
PanelFrame frame = new PanelFrame(products, numOfProducts);
frame.pack();
frame.setVisible(true);
frame.setSize(600, 450);
} // end class GUI
class PanelFrame extends JFrame
private JButton first;
private JButton next;
private JButton previous;
private JButton last;
private JButton add;
private JButton delete;
private JButton modify;
private JButton search;
private JButton save;
JTextField dvdName;
JTextField productnumber;
JTextField numberofproducts;
JTextField price;
private DVD[] products;
private int numOfProducts;
private int currentIndex = 0;
/** Creates a new instance of PanelFrame */
public PanelFrame(DVD[] products, int numOfProducts)
super("Welcome to the DVD Inventory");
this.products = products;
this.numOfProducts = numOfProducts;
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setLayout(new GridLayout(6,1,5,5));
showLogo();
showLabels();
showInputFields();
showButtons();
public class MovieGraphics extends Component
private BufferedImage image;
private boolean imageFound = true;
public MovieGraphics()
super();
try
image = ImageIO.read(new File("logo.jpg"));
catch (IOException x)
x.printStackTrace();
imageFound = false;
public void paint(Graphics g)
if (imageFound)
g.drawImage(image,
0, 0, 200, 100,
0, 0, image.getWidth(null), image.getHeight(null),
null);
else
g.drawString("Gary's DVD Krypt", 30, 30);
} // end of class MovieGraphics
public void showLogo()
MovieGraphics myLogo = new MovieGraphics();
this.add(myLogo);
public void showLabels()
JPanel panel = new JPanel();
panel.add(new JLabel("DVD Title"));
panel.add(new JLabel("Product number"));
panel.add(new JLabel("Number of products"));
panel.add(new JLabel("Price"));
this.add(panel);
public void showInputFields()
JPanel panel = new JPanel();
dvdName = new JTextField(10);
productnumber = new JTextField(10);
numberofproducts = new JTextField(10);
price = new JTextField(10);
dvdName.setEditable(false);
productnumber .setEditable(false);
numberofproducts.setEditable(false);
price.setEditable(false);
panel.add(dvdName);
panel.add(productnumber );
panel.add(numberofproducts);
panel.add(price);
this.add(panel);
public void showButtons()
JPanel panel = new JPanel();
first = new JButton("First");
next = new JButton("Next");
previous = new JButton("Previous");
last = new JButton("Last");
add = new JButton("Add");
delete = new JButton("Delete");
modify = new JButton("Modify");
search = new JButton("Search");
save = new JButton("Save");
panel.add(first);
panel.add(next);
panel.add(previous);
panel.add(last);
panel.add(add);
panel.add(delete);
panel.add(modify);
panel.add(search);
panel.add(save);
ButtonActionHandler handler = new ButtonActionHandler();
first.addActionListener(handler);
next.addActionListener(handler);
previous.addActionListener(handler);
last.addActionListener(handler);
add.addActionListener(handler);
delete.addActionListener(handler);
modify.addActionListener(handler);
search.addActionListener(handler);
save.addActionListener(handler);
this.add(panel);
setFields(0);
protected void paintComponent(Graphics g)
public void setFields(int i)
setdvdName(i);
setproductnumber(i);
setnumberofproducts(i);
setPrice(i);
public void setdvdName(int i)
dvdName.setText(products.getdvdName());
public void setproductnumber(int i)
productnumber.setText(String.valueOf(products[i].getproductnumber()));
public void setnumberofproducts(int i)
numberofproducts.setText(String.valueOf(products[i].getnumberofproducts()));
public void setPrice(int i)
price.setText(String.valueOf(products[i].getprice()));
private class ButtonActionHandler implements ActionListener
public void actionPerformed(ActionEvent event)
if (event.getSource() == first)
addClicked = false;
currentIndex = 0;
setFields(currentIndex);
makeFieldsEditable(false);
else if (event.getSource() == next)
addClicked = false;
currentIndex++;
if (currentIndex == numOfProducts)
currentIndex --;
setFields(currentIndex);
makeFieldsEditable(false);
else if (event.getSource() == previous)
addClicked = false;
currentIndex--;
if (currentIndex < 0)
currentIndex = 0;
setFields(currentIndex);
makeFieldsEditable(false);
else if (event.getSource() == last)
addClicked = false;
currentIndex = numOfProducts - 1;
if (currentIndex < 0)
currentIndex = 0;
setFields(currentIndex);
makeFieldsEditable(false);
else if(event.getSource() ==add)
//add actions for add here
if (!addClicked)
resetFields();
makeFieldsEditable(true);
int itemNum = incrementItemNumber();
System.out.println(itemNum);
itemNumber.setText(String.valueOf(itemNum));
currentIndex = numOfProducts;
addClicked = true;
else if(event.getSource() ==save)
//add actions for save here
//we need to call SaveToFile.java
// SaveToFile.save;
addClicked = false;
System.out.println(currentIndex);
if (!updateProduct(currentIndex))
JOptionPane.showMessageDialog(null, "You have reached maximum number of products!");
currentIndex --;
setFields(currentIndex);
else
saveProduct();
makeFieldsEditable(false);
else if(event.getSource() == edit)
//add actions for edit here
// Inventory.edit;
addClicked = false;
makeFieldsEditable(true);
else if(event.getSource() == search)
//add actions for search here
// Inventory.findIndex;
addClicked = false;
String name = JOptionPane.showInputDialog("Enter Product Name: ");
int index = searchName(name);
System.out.println(index);
if (index == -1)
JOptionPane.showMessageDialog(null, "No matching product found! ");
else
currentIndex = index;
setFields(index);
Here are my errors:
C:\java>javac DVDInventory6.java
DVDInventory6.java:460: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:463: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(false);
^
DVDInventory6.java:467: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:474: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(false);
^
DVDInventory6.java:478: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:485: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(false);
^
DVDInventory6.java:489: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:496: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(false);
^
DVDInventory6.java:501: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
if (!addClicked)
^
DVDInventory6.java:503: cannot find symbol
symbol : method resetFields()
location: class PanelFrame.ButtonActionHandler
resetFields();
^
DVDInventory6.java:504: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(true);
^
DVDInventory6.java:505: cannot find symbol
symbol : method incrementItemNumber()
location: class PanelFrame.ButtonActionHandler
int itemNum = incrementItemNumber();
^
DVDInventory6.java:507: cannot find symbol
symbol : variable itemNumber
location: class PanelFrame.ButtonActionHandler
itemNumber.setText(String.valueOf(itemNum));
^
DVDInventory6.java:510: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = true;
^
DVDInventory6.java:517: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:519: cannot find symbol
symbol : method updateProduct(int)
location: class PanelFrame.ButtonActionHandler
if (!updateProduct(currentIndex))
^
DVDInventory6.java:527: cannot find symbol
symbol : method saveProduct()
location: class PanelFrame.ButtonActionHandler
saveProduct();
^
DVDInventory6.java:529: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(false);
^
DVDInventory6.java:531: cannot find symbol
symbol : variable edit
location: class PanelFrame.ButtonActionHandler
else if(event.getSource() == edit)
^
DVDInventory6.java:535: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:536: cannot find symbol
symbol : method makeFieldsEditable(boolean)
location: class PanelFrame.ButtonActionHandler
makeFieldsEditable(true);
^
DVDInventory6.java:542: cannot find symbol
symbol : variable addClicked
location: class PanelFrame.ButtonActionHandler
addClicked = false;
^
DVDInventory6.java:544: cannot find symbol
symbol : method searchName(java.lang.String)
location: class PanelFrame.ButtonActionHandler
int index = searchName(name);
^
23 errorsand many more errors
such as;
* you need to declare a method called makeFieldsEditable that takes a boolean value
eg private void makeFieldsEditable(boolean editable){
// add your implememntation
}* you need to declare a method called resetFields
eg private void resetFields(){
// add your implememntation
}* you need to declare a method called updateProduct
eg private void updateProduct(int index){
// add your implememntation
}etc -
I'm working on creating an array that is basically a deck of cards, this is the problem.
I'm getting this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
void main()
final int ARRAY_SIZE = 52;
String[] deck = new String[ARRAY_SIZE];
String[] cardValue = new String[]{"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
String[] cardSuit = new String[]{"C","H","D","S"};
for (int count = 0; count < ARRAY_SIZE; count++)
deck[count]= cardValue[count] + cardSuit[count];
}I Know that this is because cardSuit is reaching the end of the array, but how do I keep this from happening and make it start from the beginning until i reach the end of the cardValue array?By the way thanks for the help guys, I'm in a pinch for this assignment and I appreciate all of the help.
void main()
final int ARRAY_SIZE = 52;
String[] deck = new String[ARRAY_SIZE];
String[] cardValue = new String[]{"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
String[] cardSuit = new String[]{"C","H","D","S"};
for (int count = 0; count < ARRAY_SIZE; count++)
deck[count]= cardValue[count % 13] + cardSuit[count % 4];
showCards(deck);
void showCards(String [] list)
String cards = ("card");
for (int count = 0; count < list.length; count++)
print (cards);
This is what I'm talking about. I need to be able to call the showCards method and have it display whatever cards are currently in the players hand regardless of how many cards there are. I believe that I'm right when I used the void declaration because I don't want it the method to return anything to itself.
Right now with the code as is, i get "card" typed out 52 times.
First how do I go about having it print out the complete deck and the order that they are in?
Is there a way to create the deck in pre-sorted like I have below?
This was the assignment:
Write a ConsoleProgram to create a deck of playing cards, shuffle them, and deal out 5 cards to the player. To do this:
� You will need an array of 52 cards. In the basic version of this program, each card is a string in the form �XY�, where X is the rank (A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A) and Y is a letter designating the suite (C, H, D, S).
� You will need to shuffle the cards by swapping the positions of two randomly selected cards in the array. For this, you should write and use three methods:
o randRange � a method which takes 2 parameters: a minimum integer and a maximum integer. It creates a random integer in this range and returns it.
o swap � a method which takes 3 parameters: an array of cards and two subscripts. It swaps the array elements with the given subscripts and returns nothing in its name.
o shuffle � a method which takes 2 parameters: an array of cards and a number of times to swap cards. It shuffles by swapping two randomly selected cards the desired number of times (a possibly different pair each time). It returns nothing in its name (so it is a void method).
� You will need an array of 5 cards for the player�s hand. After shuffling the deck, you will fill this array with the first 5 cards from the deck.
� Display the unshuffled deck, then the shuffled deck, and finally the player�s hand. Indicate which is which in the output. For example, the output of one program run might look like this: Unshuffled: 2C, 3C, 4C, 5C, 6C, 7C, 8C, 9C, TC, JC, QC, KC, AC, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 9D, TD, JD, QD, KD, AD, 2H, 3H, 4H, 5H, 6H, 7H, 8H, 9H, TH, JH, QH, KH, AH, 2S, 3S, 4S, 5S, 6S, 7S, 8S, 9S, TS, JS, QS, KS, AS Shuffled: 2C, QC, 3S, 9C, 9S, 6C, 6H, 3C, QH, 2H, 8C, 9H, AH, 4S, AS, TH, 6D, 3D, 2S, 8S, 5C, TC, 4C, 4D, 7C, AD, 9D, JD, 4H, 5S, KH, 7H, JS, 8D, TD, KC, 3H, 2D, KD, AC, KS, JC, 5H, JH, 8H, 5D, 7S, TS, QD, 7D, 6S, QS Your Hand: 2C, QC, 3S, 9C, 9S
Maybe you are looking for
-
Hi there I have a form on a webpage that I have altered that works fine when submitted ..however there are 2 fields that don't show up in the received email ..The boy/girl radio button selection and the Related Radio button group (6 selections) Can a
-
Office 365 ProPlus will not install
Hi, I have tried many attempts at manually installing Office 365 ProPlus using the deployment toolkit but so far nothing has worked. I downloaded the bits first and I'm now trying to install Office using the deployment toolkit. This test is in prepar
-
JSP: attributes for body ?
I never used JSPs all that much and mostly worked with servlets. I just wonder (because it's hard to find anything about it): how would I e.g. add an ununload event handler to a <body> tag? Whatever I do, the JSP generates header and body itself and
-
Import CinemaDNG (Blackmagic) into AE @ wrong FPS
Hi There, When I import a clip (Cinema DNG sequence) After Effects interprets the footage at 30fps instead of the 23.976 that it was shot at. I have to manually change each clip's fps. Am I doing something wrong or is this a bug? Also, I've filed a
-
HT3737 how do you cut and paste on an iMac
how do you cut and paste on an imac