Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 8th, 2005, 10:35 PM   #1
monka
Newbie
 
Join Date: Feb 2005
Posts: 6
Rep Power: 0 monka is on a distinguished road
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!!!!!!!!!!!!!!!!!!!!!!!!!
monka is offline   Reply With Quote
Old Feb 8th, 2005, 10:48 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Feb 9th, 2005, 1:50 AM   #3
EdSalamander
Programmer
 
EdSalamander's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ, USA
Posts: 80
Rep Power: 4 EdSalamander is on a distinguished road
Send a message via AIM to EdSalamander
Hate to break it to you, but this thing is full of errors.
  • In your parameters for menu(), nameItem is a double, but you're passing a String from nameItem[]. That, and nearly all your parameters are asking for arrays but you're only passing in single array elements. I.E. turn all those array parameters into single parameter elements.
  • InputString can't be both a String and a String array at the same time.
  • The counter in the for loop in inputData() was declared as an int, but then you try to set it equal to a double. You can't do that without casting the double to an int first.
  • Output() in subclass is set to return a double but you have it returning an int. Hell, for that matter, why is it returning anything at all? The value never changes. Why not just take out the return statement and set the return type to void?

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?
EdSalamander is offline   Reply With Quote
Old Feb 9th, 2005, 5:43 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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.
Berto is offline   Reply With Quote
Old Feb 9th, 2005, 6:40 AM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Originally Posted by Berto
pre-wizard in code for you :/.
JCreator prewizards in code for you? Eh, I think JCreator is fine. That's what I've been using since I started Java. I don't like plain old notepad. If I'm working on something that's non-trivial, I like some syntax highlighting, and something that'll automatically tab for me at least.

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
Mjordan2nd is offline   Reply With Quote
Old Feb 9th, 2005, 7:41 AM   #6
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
piffle piffle piffle, that is all i have to say. But i used texturizer for my PHP codeie things /
Berto is offline   Reply With Quote
Old Mar 3rd, 2005, 8:41 PM   #7
monka
Newbie
 
Join Date: Feb 2005
Posts: 6
Rep Power: 0 monka is on a distinguished road
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.
monka is offline   Reply With Quote
Old Mar 3rd, 2005, 8:49 PM   #8
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Mar 3rd, 2005, 8:50 PM   #9
monka
Newbie
 
Join Date: Feb 2005
Posts: 6
Rep Power: 0 monka is on a distinguished road
Thanks .
monka is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC