class, interface, or enum expected
DVD CLASS
^
class, interface, or enum expected
DVDINVENTORY CLASS
^
HOW DO I FIX THESE TWO ERRORS WITHOUT GETTING OTHER ERRORS???
here is my code:
DVD CLASS
public class Dvd {
private String productNumber;
private String itemName;
private int numberOfUnits;
private double pricePerUnit;
public Dvd(String prodNo, String name, int noUnits, double price) {
productNumber = prodNo;
itemName = name;
numberOfUnits = noUnits;
pricePerUnit = price;
}
public String getProductNumbe r() { return productNumber; }
public String getItemName() { return itemName; }
public int getNumberOfUnit s() { return numberOfUnits; }
public double getPricePerUnit () { return pricePerUnit; }
public double calculateInvent oryValue() {
return numberOfUnits*p ricePerUnit;
}
}
DVDINVENTORY CLASS
import java.util.Scann er;
public class DvdInventory {
public static void main(String[] args) {
int SIZE = 100;
Dvd[] myDvds = new Dvd[SIZE];
int numberOfDvds = 0;
while (numberOfDvds < SIZE) {
Dvd dvd = readDvd();
if(dvd == null) { break; }
myDvds[numberOfDvds++] = dvd;
}
for(Dvd dvd : myDvds) { System.out.prin tln(dvd); }
System.out.prin tln("Value of Inventory: $ "+calculateInve ntoryValue(myDv ds));
}
private static Dvd readDvd() {
Scanner in = new Scanner(System. in);
System.out.prin t("Enter item name or \"quit\" to stop: ");
String itemName = in.nextLine();
if(itemName.equ alsIgnoreCase(" quit")) { return null; }
System.out.prin t("Enter product number: ");
String productNumber = in.nextLine();
System.out.prin t("Enter number of units: ");
int numberOfUnits = in.nextInt();
System.out.prin t("Enter price per unit: ");
double pricePerUnit = in.nextDouble() ;
return new Dvd(productNumb er,itemName,num berOfUnits);
}
private static double calculateInvent oryValue(Dvd[] dvds) {
double result = 0;
for(Dvd dvd : dvds) { result += dvd.calculateIn ventoryValue(); }
return result;
}
}
12 3634 JosAH 11,448
Recognized Expert MVP
here is my code:
I think you should get rid of that preamble. Why did you prepend it to your source
code in the first place?
kind regards,
Jos
I think you should get rid of that preamble. Why did you prepend it to your source
code in the first place?
kind regards,
Jos
im new to java...umm i dont know what you mean??
JosAH 11,448
Recognized Expert MVP
im new to java...umm i dont know what you mean??
Remove the lines "DVD CLASS" and "DVDINVENTO RY CLASS".
kind regards,
Jos
Remove the lines "DVD CLASS" and "DVDINVENTO RY CLASS".
kind regards,
Jos
ok, so i did what you said about removing the two lines and now i get these errors:
in the build output window it says: class, interface, or enum expected
import java.util.Scann er;
^
1 error
in the general output window it says: java.lang.NoCla ssDefFoundError : DvdInventory
Exception in thread "main"
Process completed.
now how do i fix these two errors?
it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????
JosAH 11,448
Recognized Expert MVP
it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????
I don't know about 'or something' but your code is definitely not right; if the compiler
can't find the Scanner class you either have an old version of Java (older than 1.5)
of you have an installation problem. The other error is just because you wanted
to run a class that didn't even properly compile. You should check your Java
version and if needed upgrade and try again.
kind regards,
Jos
ok, so i did what you said about removing the two lines and now i get these errors:
in the build output window it says: class, interface, or enum expected
import java.util.Scann er;
^
1 error
in the general output window it says: java.lang.NoCla ssDefFoundError : DvdInventory
Exception in thread "main"
Process completed.
now how do i fix these two errors?
it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????
Out of interest, eh, where had you placed this import statement? What were the first, say, five lines of the code that gave that error?
I don't know about 'or something' but your code is definitely not right; if the compiler
can't find the Scanner class you either have an old version of Java (older than 1.5)
of you have an installation problem. The other error is just because you wanted
to run a class that didn't even properly compile. You should check your Java
version and if needed upgrade and try again.
kind regards,
Jos
its definitely not my java version or installation. i have the latest version 6.0...and the other day i had a program to run perfect.... the problem is somewhere in my code and i just cant figure it out...so i came here in hopes that someone could point me in the right direction or tell me what i have to remove for the code to work.....but it seems everything someone says to remove...anothe r error happens......i thought that providing my code someone could see where i have a few things misplaced or tell me if im missing something....si nce my code is "definitely not right"..i thought you knew what i had to do to make it "right"
Out of interest, eh, where had you placed this import statement? What were the first, say, five lines of the code that gave that error?
sorry, i dont know what you are asking. after running my code that's the error i get.....for my full code take a look at the previous posts.
sorry, i dont know what you are asking. after running my code that's the error i get.....for my full code take a look at the previous posts.
There are some characters/words in your .java file that are not part of the code that you want to execute. e.g the line with DVD CLASS.
That is not part of the code and must be removed or commented out. The compiler should see only valid Java statements.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities as a standard
portable part of the core language, the LISP package, and the java.lang
package, respectively. Both have big integers, although only...
|
by: Joachim Boomberschloss |
last post by:
Hello,
I am working on a project in Python, and I"m
currently
looking into the possibiliy of writing some of the
project"s modules in Java. Given that a large part of
the code is already written in Python, using the
standard libraries and several extension modules, I
am
trying to gauge the viability of integration with
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej and
I was wondering if anyone here would be able to give me some tips for
young players such as myself, for learning the language.
Is this the...
|
by: Rhino |
last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within
Eclipse.
I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method
in the UDF. I know that the UnsatisfiedLinkError has something to do with a
DLL that is not visible but I'm not sure why I'm having the problem given
that both db2java.zip and...
|
by: IchBin |
last post by:
I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java
The error and line of PHP code:
$system = new Java('java.lang.System');
Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3
| |
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
|
by: mwelsh1118 |
last post by:
Why doesn't C# allow incremental compilation like Java?
Specifically, in Java I can compile single .java files in isolation.
The resulting individual .class files can be grouped into .jar files.
In C#, there appears to be no analog. I have to compile all my .cs
files into a single .dll.
This has serious drawbacks in terms of...
|
by: r035198x |
last post by:
Setting up.
Getting started
To get started with java, one must download and install a version of Sun's JDK (Java Development Kit).
The newest release at the time of writting this article is JDK 6 downloadable from
http://java.sun.com/javase/downloads/index.jsp.
I will be using JDK 5(update 8)
|
by: aarklon |
last post by:
Hi all,
See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
for C vs Java in number crunching
http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |