...

View Full Version : HELP! error



stumpz
12-13-2004, 08:09 PM
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.lang.reflect.*;
import java.applet.*;
import javax.swing.JProgressBar;

public class hw62 extends JApplet
{
Part partarray[] = new Part[100]; //Wow, an array of Parts!!

public void init()
{
Container c = getContentPane();
JButton button = new JButton("Homework #5");

button.addActionListener //anonymous class to handle opening button
(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
hw6();
}
}//end anonymous inner class
);
c.add(button);
}

private void hw6()
{
String option = "";
int optionint;

//Creates 3 Parts (NOTE: This code is extremely helpful to understand!!)
partarray[Part.getPartCount()] = new Part("Mouse", 5, 12, 88);
partarray[Part.getPartCount()] = new Part("Keyboard", 10, 23, 103);
partarray[Part.getPartCount()] = new Part("Monitor", 45, 123, 145);

if(Password())
{
do
{
option = JOptionPane.showInputDialog(null,
"Please Choose Your Option: " +"\n 1 = Read Inventory\n" +
" 2 = Create Part\n 3 = Update Part\n"
+" 4 = Delete Part\n 5 = Quit" ,
"WELCOME TO THE PART INVENTORY SYSTEM!!",
JOptionPane.QUESTION_MESSAGE );

try
{
optionint = Integer.parseInt(option);
}
catch( NumberFormatException e)
{
optionint = 6;
}

switch (optionint)
{
case 1:
{
Read();
break;
}
case 2:
{
Create();
break;
}
case 3:
{
Update();
break;
}
case 4:
{
Delete();
break;
}
case 5:
{
Quit();
break;
}
default:
JOptionPane.showMessageDialog(null,
"Incorrect Choice.\nRead The Freaking Directions!!",
"INCORRECT OPTION", JOptionPane.ERROR_MESSAGE );
}//end switch
}while (Integer.parseInt(option) != 5);
}
else
JOptionPane.showMessageDialog(null,
"Your Chances are UP!!\n Get out!!!",
"INCORRECT PASSWORD", JOptionPane.ERROR_MESSAGE );

}

//You know what this does by now
boolean Password()
{
String passwordwindow="",chances="";

for(int i=3; i>=1; i--)
{
if(i==3)
chances = "\nNOTE: You get 3 chances.";
if(i==2)
chances = "\nNOTE: You get 2 more chances.";
if(i==1)
chances = "\nNOTE: You get 1 more chance!!";

passwordwindow = JOptionPane.showInputDialog( "Please enter the"
+" correct password" + chances );

if(passwordwindow.equals("hw6"))
return true;
}
return false;
}

//Prints out all parts in Part Array and accounts for parts that are deleted
void Read()
{

JTextArea x = new JTextArea();
x.setText("Part Number\tPartName\t\tWholesale\tRetail\tQuantity\tProfit\n");

for(int a = 0; a < 19; a++)
x.append("--------");

for(int b = 0; b < Part.getPartCount(); b++)
if(partarray[b] == null)
x.append("\n-----PART DELETED-----");
else
x.append("\n" + partarray[b].getPartNumber() + "\t" + partarray[b].getPartName() + "\t\t$" + partarray[b].getWholeSalePrice() + "\t$" + partarray[b].getRetailPrice() + "\t" + partarray[b].getQuantity() + "\t$" + partarray[b].getProfit());

x.append("\n");

for(int c = 0; c < 19; c++)
x.append("--------");

JOptionPane.showMessageDialog(null, x, "Read Inventory", 1);

}

//Allows the creation of a new Part
void Create()
{

int i;
int j;
int k;

String s = JOptionPane.showInputDialog(null, "Please enter a part name!\n(Must be more than three characters)", "Create Part", 3);
String create1 = JOptionPane.showInputDialog(null, "Please enter a wholesale price!", "Create Part", 3);
String create2 = JOptionPane.showInputDialog(null, "Please enter a retail price!", "Create Part", 3);
String create3 = JOptionPane.showInputDialog(null, "Please enter a quantity!", "Create Part", 3);


try
{
i = Integer.parseInt(create1);
}
catch(NumberFormatException numberformatexception)
{
i = 0;
}

try
{
j = Integer.parseInt(create2);
}
catch(NumberFormatException numberformatexception1)
{
j = 0;
}
try
{
k = Integer.parseInt(create3);
}
catch(NumberFormatException numberformatexception2)
{
k = 0;
}

partarray[Part.getPartCount()] = new Part(s, i, j, k);

JOptionPane.showMessageDialog(null, "Part Created!", "Create Part", 1);

}
//Allows a Part to be Updated
void Update()
{

JTextArea x = new JTextArea();
x.setText("Part#\tPartName\t\tWholesale\tRetail\tQuantity\tProfit\n");

for(int a = 0; a < 19; a++)
x.append("--------");

for(int b = 0; b < Part.getPartCount(); b++)
if(partarray[b] == null)
x.append("\n-----PART DELETED-----");
else
x.append("\n" + partarray[b].getPartNumber() + "\t" + partarray[b].getPartName() + "\t\t$" + partarray[b].getWholeSalePrice() + "\t$" + partarray[b].getRetailPrice() + "\t" + partarray[b].getQuantity() + "\t$" + partarray[b].getProfit());

x.append("\n");

for(int c = 0; c < 19; c++)
x.append("--------");

x.append("\n\nPlease enter the part number to be updated...");

String update = JOptionPane.showInputDialog(null, x, "Update Part", 3);

int d;
try
{
d = Integer.parseInt(update);
}
catch(NumberFormatException numberformatexception)
{
d = -400;
}
if(d == -400)
JOptionPane.showMessageDialog(null, "Part not updated..", "Update Part", 0);
else if(d < 1 || d > Part.getPartCount())
JOptionPane.showMessageDialog(null, "That wasn't a part..", "Update Part", 0);
else if(partarray[d - 1] == null)
JOptionPane.showMessageDialog(null, "That wasn't a part..", "Update Part", 0);
else
{
String update3 = JOptionPane.showInputDialog(null, "What do you want to change?\n1. Part Name\n2. Wholesale Price\n3. Retail Price\n4. Quantity", "Update Part", 3);
String update1 = " wasn't updated";
int d1;

try
{
d1 = Integer.parseInt(update);
}
catch(NumberFormatException numberformatexception1)
{
d1 = -400;
}
if(d1 < 1 || d1 > 4)
{
JOptionPane.showMessageDialog(null, "You are an idiot!!", "Update Part", 0);
return;
}
switch(d1)
{
default:
break;

case 1:
String create1 = JOptionPane.showInputDialog(null, "Enter a new part name\nOld name was " + partarray[d - 1].getPartName(), "Update Part", 3);
partarray[d - 1].setPartName(create1);
update3 = "name was changed";
break;

case 2:
String create2 = JOptionPane.showInputDialog(null, "Enter a new wholesale price\nOld prce was $" + partarray[d - 1].getWholeSalePrice(), "Update Part", 3);

int g1;

try
{
g1 = Integer.parseInt(create2);
}

catch(NumberFormatException numberformatexception2)
{
g1 = -400;
}

if(g1 != -400)
{
partarray[d - 1].setWholeSalePrice(g1);
update3 = "Wholesale price was changed";
}
break;

case 3:
String create3 = JOptionPane.showInputDialog(null, "Enter new retail price\nOld price was $" + partarray[d - 1].getRetailPrice(), "Update Part", 3);
int e1;

try
{
e1 = Integer.parseInt(create3);
}
catch(NumberFormatException numberformatexception3)
{
e1 = -400;
}
if(e1 != -400)
{
partarray[d - 1].setRetailPrice(e1);
update3 = "Retail price was changed";
}
break;

case 4:
String update2 = JOptionPane.showInputDialog(null, "Enter new quantity\nOld quantity was " + partarray[d - 1].getQuantity(), "Update Part", 3);
int f1;

try
{
f1 = Integer.parseInt(update2);
}
catch(NumberFormatException numberformatexception4)
{
f1 = -400;
}
if(f1 != -400)
{
partarray[d - 1].setQuantity(f1);
update3 = "Quantity was changed";
}
break;
}
JOptionPane.showMessageDialog(null, "Part " + update1, "Update Part", 1);
}


}

//Allows a Part to be Deleted by setting partarray[i] = null;
//Also accounts for bad data entry
void Delete()
{

JTextArea x = new JTextArea();
x.setText("Part#\tPartName\t\tWholesale\tRetail\tQuantity\tProfit\n");

for(int i = 0; i < 19; i++)
x.append("--------");

for(int j = 0; j < Part.getPartCount(); j++)
if(partarray[j] == null)
x.append("\n-----PART DELETED-----");
else
x.append("\n" + partarray[j].getPartNumber() + "\t" + partarray[j].getPartName() + "\t\t$" + partarray[j].getWholeSalePrice() + "\t$" + partarray[j].getRetailPrice() + "\t" + partarray[j].getQuantity() + "\t$" + partarray[j].getProfit());

x.append("\n");

for(int k = 0; k < 19; k++)
x.append("--------");

x.append("\n\nEnter part number to be deleted");

String delete = JOptionPane.showInputDialog(null, x, "Delete Part", 3);
int d;
try
{
d = Integer.parseInt(delete);
}
catch(NumberFormatException numberformatexception)
{
d = -400;
}
if(d == -400)
JOptionPane.showMessageDialog(null, "No part deleted..", "Delete Part", 0);
else
if(d < 1 || d > Part.getPartCount())
JOptionPane.showMessageDialog(null, "That wasn't a part..", "Delete Part", 0);
else
if(partarray[d - 1] == null)
{
JOptionPane.showMessageDialog(null, "That wasn't a part..", "Delete Part", 0);
} else
{
JOptionPane.showMessageDialog(null, partarray[d - 1].getPartName() + " was DELETED from Inventory", "Delete Part", 1);
partarray[d - 1] = null;
}

}

void Quit()
{
for(int i = 0; i < Part.getPartCount(); i++)
partarray[i] = null;

JOptionPane.showMessageDialog(null,
"Thanks for Using the Parts Inventory System!",
"SEE YA!!", JOptionPane.INFORMATION_MESSAGE );
}
}

//See Website for specifics
class Part
{

private String PartName;
private int WholeSalePrice, RetailPrice, Profit, Quantity, PartNumber;
private static int PartCount;

public Part(String s, int i, int j, int k)
{

super(s, k);
setWholeSalePrice(i);
setRetailPrice(j);
Update_Profit();

}

public void setPartName(String s)
{



}

public void setWholeSalePrice(int i)
{

if(i < 0)
WholeSalePrice = 0;
else
WholeSalePrice = i;
Update_Profit();

}

public void setRetailPrice(int j)
{

if(j < 0)
RetailPrice = 0;
else
RetailPrice = j;
Update_Profit();

}

public void setQuantity(int k)
{

if(k < 0)
Quantity = 0;
else
Quantity = k;
Update_Profit();

}

private void Update_Profit()
{

Profit = Quantity * (RetailPrice - WholeSalePrice);

}

public String getPartName() {return PartName;}
public int getWholeSalePrice() {return WholeSalePrice;}
public int getRetailPrice() {return RetailPrice;}
public int getQuantity() {return Quantity;}
public int getPartNumber() {return PartNumber;}
public int getProfit() {return Profit;}
public static int getPartCount() {return PartCount;}

}



i'm so confused right now...i'm getting the Object() in java.lang.Object cannot be applied to (java.lang.String,int) compile error and i know it's because of the super(s, k) but i cannot figure out why..I believe this is causing my whole program to not function correctly..i need to figure out how to get it to read the inventory, because it's not at all.. :/

stumpz
12-13-2004, 08:57 PM
k, i've figured it out as far as i know

Brandoe85
12-13-2004, 09:29 PM
Did you figure out that this is the javascript forum and not java? :eek:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum