![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 6
Rep Power: 0
![]() |
help out beginner with some errors (solved)
Want to help me out? I am doing this program for a class and can't seem to fix these errors. I am sooo tired.... I am using Jcreator le by the way.
Thanks by the way! pracloop.java import java.awt.*;
import java.io.*;
import java.text.DecimalFormat;
class pracloop//inheritance
{
public static void main(String args[])
{
double numofitems;
double priceitem[] = new double [2];
double markup[] = new double [2];
double lastcost[] = new double [2];
String nameitem[] = new String [2];
int choice;
menu(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return;
}
public static void menu(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass(); //constructor sets up an instance of
String Choice;
System.out.println(" ");
System.out.println("1. input data");
System.out.println("2. input markup");
System.out.println("3. calculate");
System.out.println("4. output ");
System.out.println("5. end this program");
Choice = sub.getConsoleString();
choice = Integer.parseInt(Choice);
switch(choice)
{
case 1:
inputdata(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
break;
case 2:
markup(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
break;
case 3:
calculate(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
break;
case 4:
output(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
break;
case 5:
return;
}
return;
}
public static double inputdata(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString[];
String InputString = new String [2];
int operation = 1;
System.out.print("Please enter the number of items: ");
InputString[0] = sub.getConsoleString();
numofitems = Double.parseDouble(InputString[0]);
InputString[0] = "";
int counter;
for(counter = numofitems; counter>0; counter--)
{
System.out.println("Please enter the wholesale cost of item#" + counter + ": ");
InputString[counter] = sub.getConsoleString();
priceitem[counter] = Double.parseDouble(InputString[counter]);
InputString[counter] = "";
System.out.println(" ");
System.out.println("Please enter the name of item#" + counter + ": ");
InputString[counter] = sub.getConsoleString();
nameitem[counter] = InputString[counter];
System.out.println(" ");
InputString[counter] = "";
}
menu(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return(0);
}
public static double markup(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString[];
String InputString = new String [2];
int operation = 2;
int counter;
for(counter = numofitems; counter>0; counter--)
{
System.out.println("Please enter the markup of item#" + counter + ": ");
InputString[counter] = sub.getConsoleString();
markup[counter] = Double.parseDouble(InputString[counter]);
InputString[counter] = "";
System.out.println(" ");
}
menu(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return(0);
}
public static double calculate(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString[];
String InputString = new String [2];
int operation = 3;
int counter;
for(counter = numofitems; counter>0; counter--)
{
lastcost[counter] = priceitem[counter] + markup[counter];
System.out.println(" ");
System.out.println("Please enter the markup of item#" + counter + ": ");
}
menu(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return(0);
}
public static void output(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
sub.output(choice, numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return;
}
}subclass.java
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class subclass extends pracloop
{
public static double output(int choice, double numofitems, double priceitem[], double nameitem[], double markup[], double lastcost[])
{
pracloop prac = new pracloop();
subclass sub = new subclass();
int counter;
//DecimalFormat twoDigits = new DecimalFormat("$#,000.00);
//twoDigits.format(lastcost[counter])
for(counter = numofitems; counter>0; counter--)
{
System.out.println("The price of " + nameitem[counter] + " is: " + lastcost[counter] + ".");
System.out.println(" ");
}
prac.menu(numofitems, priceitem[2], nameitem[2], markup[2], lastcost[2]);
return(0);
}
public static String getConsoleString()
{
int noMoreInput = -1;
char enterKeyHit = '\n';
int InputChar = 0;
StringBuffer InputBuffer = new StringBuffer(30);
try
{
InputChar = System.in.read();
while (InputChar != noMoreInput)
{
if ((char) InputChar != enterKeyHit)
{
InputBuffer.append((char) InputChar);
}
else
{InputBuffer.setLength(InputBuffer.length() -1);
break;
}
InputChar = System.in.read();
}
}
catch(IOException IOX)
{
System.err.println(IOX);
}
return InputBuffer.toString();
}//end of GetConsoleString()
}Thanks!!!!!!!!!!!!!!!!!!!!!!!!! ![]() |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Can you post the errors?
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Programmer
|
Hate to break it to you, but this thing is full of errors.
And those are just the compile-time errors. Forgive me if this is too presumptous, but you aren't letting JCreator make your code for you, are you? That would kinda defeat the purpose...
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose? |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
stop using jCreator would be my advice and hand code it all using notepad or soemthing similar that doesn't pre-wizard in code for you :/. Personally i prefer to use txt editors until i no the code then i go to the fancy IDE's
Also when posting please post the errors as well, this helps us to make a faster diagnosis of your code. |
|
|
|
|
|
#5 | |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Quote:
Notepad2, on the other hand, isn't bad, plus it's supposedly just as light as notepad.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
piffle piffle piffle, that is all i have to say. But i used texturizer for my PHP codeie things /
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Feb 2005
Posts: 6
Rep Power: 0
![]() |
Sorry guys that was a bad way to introduce myself. I hope this redeems myself. I battled through the program, debugging it and I fixed it...
If anyone wanted to see it, here is the end result. Thanks for all the help by the way guys. pracloop.java: import java.awt.*;
import java.io.*;
import java.text.DecimalFormat;
class pracloop//inheritance
{
public static void main(String args[])
{
int numofitems = 0;
double priceitem[] = new double [2];
double markup[] = new double [2];
double lastcost[] = new double [2];
String nameitem[] = new String [2];
int choice = 0;
menu(choice, numofitems, priceitem, nameitem, markup, lastcost);
return;
}
public static void menu(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass(); //constructor sets up an instance of
String Choice;
System.out.println(" ");
System.out.println("1. input data");
System.out.println("2. input markup");
System.out.println("3. calculate");
System.out.println("4. output ");
System.out.println("5. end this program");
Choice = sub.GetConsoleString();
choice = Integer.parseInt(Choice);
switch(choice)
{
case 1:
inputdata(choice, numofitems, priceitem, nameitem, markup, lastcost);
break;
case 2:
markup(choice, numofitems, priceitem, nameitem, markup, lastcost);
break;
case 3:
calculate(choice, numofitems, priceitem, nameitem, markup, lastcost);
break;
case 4:
output(choice, numofitems, priceitem, nameitem, markup, lastcost);
break;
case 5:
return;
}
return;
}
public static double inputdata(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString = "";
System.out.print("Please enter the number of items: ");
InputString = sub.GetConsoleString();
numofitems = Integer.parseInt(InputString);
InputString = "";
int counter;
for(counter = numofitems; counter>0; counter--)
{
System.out.println("Please enter the name of item #" + counter + ": ");
InputString = sub.GetConsoleString();
nameitem[counter - 1] = InputString;
System.out.println(" ");
InputString = "";
System.out.println("Please enter the wholesale cost of " + nameitem[counter - 1] + ": ");
priceitem[counter - 1] = Double.parseDouble(sub.GetConsoleString());
System.out.println(" ");
}
menu(choice, numofitems, priceitem, nameitem, markup, lastcost);
return(0);
}
public static double markup(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString[] = new String [2];
int operation = 2;
int counter;
for(counter = numofitems; counter>0; counter--)
{
System.out.println("Please enter the markup of " + nameitem[counter - 1] + ": ");
InputString[counter - 1] = sub.GetConsoleString();
markup[counter - 1] = Double.parseDouble(InputString[counter - 1]);
InputString[counter - 1] = "";
System.out.println(" ");
}
menu(choice, numofitems, priceitem, nameitem, markup, lastcost);
return(0);
}
public static double calculate(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
String InputString[] = new String [2];
int operation = 3;
int counter;
for(counter = numofitems; counter>0; counter--)
{
lastcost[counter - 1] = priceitem[counter - 1] + markup[counter - 1];
}
menu(choice, numofitems, priceitem, nameitem, markup, lastcost);
return(0);
}
public static double output(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
subclass sub = new subclass();
sub.output(choice, numofitems, priceitem, nameitem, markup, lastcost);
return(0);
}
}subclass.java: import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DecimalFormat;
public class subclass extends pracloop
{
public static double output(int choice, int numofitems, double priceitem[], String nameitem[], double markup[], double lastcost[])
{
pracloop prac = new pracloop();
subclass sub = new subclass();
int counter;
DecimalFormat twoDigits = new DecimalFormat("$.00");
for(counter = numofitems; counter>0; counter--)
{
System.out.println("The price of " + nameitem[counter - 1] + " is: " + twoDigits.format(lastcost[counter - 1]) + ".");
System.out.println(" ");
}
prac.menu(choice, numofitems, priceitem, nameitem, markup, lastcost);
return(0);
}
public static String GetConsoleString()
{
int noMoreInput = -1;
char enterKeyHit = '\n';
int InputChar;
StringBuffer InputBuffer = new StringBuffer(30);
try
{
InputChar = System.in.read();
while (InputChar != noMoreInput)
{
if ((char) InputChar != enterKeyHit)
{
InputBuffer.append((char) InputChar);
}
else
{
InputBuffer.setLength(InputBuffer.length() -1);
break;
}
InputChar = System.in.read();
}
}
catch(IOException IOX)
{
System.err.println(IOX);
}
return InputBuffer.toString();
}//end of method GetConsoleString()
}Thanks ![]() PS: I would add [solved] to the title, but it seems I cannot edit my first post. Last edited by monka; Mar 3rd, 2005 at 8:45 PM. |
|
|
|
|
|
#8 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I edited it for you.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Feb 2005
Posts: 6
Rep Power: 0
![]() |
Thanks
. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|