Results 1 to 14 of 14
Thread: Exeption in thread "main"....
- 09-30-2010, 08:39 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Exeption in thread "main"....
exception in thread "main" java.lang.noclassdefounderror: assign 4.
i get this error message. I'm trying to write a program that promps user for item price and with the input i sum it up and display it using system.out.println. This is what i have so far. thank you
import java.util.Scanner;
public class Assign4
{
public static void determineClassAverage()
{
Scanner input = new Scanner( System.in );
double total;
double itemCounter;
double price;
double average;
double commission;
total = 0;
itemCounter = 0;
System.out.print( "Enter grade or -1 to quit: " );
price = input.nextInt();
while ( price != -1 )
{
total = total + price;
itemCounter = itemCounter + 1;
System.out.print( "Enter item value or -1 to quit: " );
price = input.nextInt();
average = (double) total / itemCounter;
commission = total * .9;
System.out.printf( "\nItems sold: \n",
itemCounter);
System.out.printf( "\nTotal amount: \n", total );
System.out.printf( "\nCommission: \n",
commission);
System.out.printf( "Class average is %.2f\n", average );
}
}
}
- 09-30-2010, 08:57 AM #2
i just started your class replacing the code from the last printf with
Java Code:System.out.printf("Class average is %.2f\n", average); } } public static void main(String[] args) { new Assign4().determineClassAverage(); } }
and i could start the method determineClassAverage without errors.
- 09-30-2010, 09:21 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 09-30-2010, 09:26 AM #4
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
when i run it, it only promps me twice and the program ends with the information.
Also the result number of items sold doesn't appear for some reason.
And my System.out.printf( "\nEarnings: $%.2f", earnings) results in this message.
"Earnings: $310.70Enter item value or -1 to quit: "
- 09-30-2010, 09:37 AM #5
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Nevermind. I managed to fix it. Now only problem is the sum of input user doesn't add up correctly. And there is no item sold. Here's my code now
//CIS 226 Assignment 4
//Jeff Chung - September 27, 2010
import java.util.Scanner;
public class Assign4
{
public static void sales()
{
Scanner input = new Scanner( System.in );
double total;
double itemCounter;
double price;
double earnings;
double commission;
total = 0;
itemCounter = 0;
earnings = 0;
commission = 0;
System.out.print( "Enter grade or -1 to quit: " );
price = input.nextInt();
while ( price != -1 )
{
System.out.print( "Enter item value or -1 to quit: " );
price = input.nextInt();
total = price + total;
itemCounter = itemCounter + 1;
commission = total * .09;
earnings = commission + 200;
}
System.out.printf( "\nItems sold: ", itemCounter);
System.out.printf( "\nTotal amount: $%.2f", total );
System.out.printf( "\nCommission: $%.2f", commission);
System.out.printf( "\nEarnings: $%.2f", earnings);
}
public static void main(String[] args) {
new Assign4().sales();
}
}
- 09-30-2010, 01:14 PM #6
Could you copy and paste here the contents of the console window from when you execute the program that shows what it does?problem is the sum of input user doesn't add up correctly. And there is no item sold.
What does the code do with the -1 before it exits the loop?
- 09-30-2010, 09:13 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
As you can see the value of the item doesnt quite add up correctly. I think when i type -1 to quit, It takes the -1 and sums it up. I can't get the -1 to not add up correctly.
Enter grade or -1 to quit: 1
Enter item value or -1 to quit: 2
Enter item value or -1 to quit: 3
Enter item value or -1 to quit: 4
Enter item value or -1 to quit: -1
Items sold: 4
Total amount: $8.00
Commission: $0.72
Earnings: $200.72
- 09-30-2010, 09:24 PM #8
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
So the problem is when the user is asked for the first input before it is sent to the while statement, the input is lost and doesn't add up to the total amount.
- 09-30-2010, 09:32 PM #9
What does the code do with the -1 that was entered before it exits the loop?
- 09-30-2010, 09:34 PM #10
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
I think it takes -1 as a price input and adds it the total amount.
- 09-30-2010, 09:35 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
import java.util.Scanner;
public class Assign4
{
public void sales() {
Scanner input = new Scanner( System.in );
int itemCounter;
double total;
double price;
double earnings;
double commission;
total = 0;
itemCounter = 0;
earnings = 0;
commission = 0;
System.out.print( "Enter item value or -1 to quit: " );
price = input.nextInt();
total = price + total;
while ( price != -1 )
{
System.out.print( "Enter item value or -1 to quit: " );
price = input.nextInt();
total = price + total;
itemCounter = itemCounter + 1;
commission = total * .09;
earnings = commission + 200;
}
if ( itemCounter != 0)
{
System.out.printf( "Items sold: %d\n", itemCounter );
System.out.printf( "Total amount: $%.2f\n", total );
System.out.printf( "Commission: $%.2f\n", commission);
System.out.printf( "Earnings: $%.2f\n", earnings);
}
}
public static void main(String[] args) {
new Assign4().sales(); }
}
- 09-30-2010, 09:36 PM #12
Does that account for your problem?
You need to test for the -1 and exit the loop before you use it as data.
- 09-30-2010, 10:07 PM #13
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Yes precisely. Now if i can only find out how to write it haha
- 09-30-2010, 10:31 PM #14
Similar Threads
-
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks