| | |
Another Java Noob :(
![]() |
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi all I'm sure you hear this all the time but "I'm a student who sucks at Java looking for help"
My assignment is to (short version)
Task Overview: You need to write five classes – Shop, Item, CD, Game, and ElectronicGame. The Shop stores a Vector of Items. The items can be a CD, a game, or an electronic game, all of which have a lot in common in addition to slight differences - so inheritance is used. Item is an abstract class which is extended by CD and Game (CD stores the artist, Game the maximum number of players), and ElectronicGame extends Game (storing the platform the game is for such as PC, Xbox, or PS2).
You should test each of your classes and then run a system test using the Ass1Test class that has been written for you, checking your output against the expected output that is supplied.
so far I have item (mostly written out) and I'm fairly sure I wont have a problem with CD, Game and or ElectronicGame however when I try to code the vector for shop (and also when I test out code my lecturer has given us in class notes (which I will provide) I get an error message stating <identifier> expected on the line of the vector. I'm running Blue J version 2.1.3 (Java version (1.4.2_11). Here's the lecturer's code (hopefully something wrong with it
import java.util.*;
public class Library
{
private Vector<Book> mBooks = new Vector<Book>();
public Library()
{
}
public void addBook(Book newBook)
{
mBooks.add(newBook);
}
public void printAllBalances()
{
System.out.println("The library contains the following books:");
for (Book nextBook : mBooks)
{
nextBook.display();
}
}
public void getTotalBorrowings()
{
int total = 0;
for (Book nextBook : mBooks)
{
total += nextBook.getBorrowedCount();
}
System.out.println("There have been a total of " + total + " borrowings from the library");
}
}
Book (Book class included in case you needed it for de-bugging)
public class Book
{
private String mAuthor;
private String mTitle;
private boolean mBorrowed;
private int mBorrowedCount;
public Book(String author, String title)
{
mAuthor = author;
mTitle = title;
mBorrowed = false;
mBorrowedCount = 0;
}
public boolean borrowBook()
{
if (mBorrowed)
{
System.out.println("Sorry, " + mTitle + " by " + mAuthor + " is already borrowed");
return false;
}
else
{
mBorrowed = true;
mBorrowedCount++;
return true;
}
}
public void returnBook()
{
if (mBorrowed)
{
mBorrowed = false;
}
else
{
System.out.println("Error - this book was not borrowed so can't be returned");
}
}
public void display()
{
System.out.print(mTitle + " by " + mAuthor + " has been borrowed " + mBorrowedCount + " times and is currently ");
if (mBorrowed)
System.out.println("out");
else
System.out.println("in");
}
public int getBorrowedCount()
{
return mBorrowedCount;
}
}
I appologise for the novel and thank you in advance for any help you can give.
Jarell
My assignment is to (short version)
Task Overview: You need to write five classes – Shop, Item, CD, Game, and ElectronicGame. The Shop stores a Vector of Items. The items can be a CD, a game, or an electronic game, all of which have a lot in common in addition to slight differences - so inheritance is used. Item is an abstract class which is extended by CD and Game (CD stores the artist, Game the maximum number of players), and ElectronicGame extends Game (storing the platform the game is for such as PC, Xbox, or PS2).
You should test each of your classes and then run a system test using the Ass1Test class that has been written for you, checking your output against the expected output that is supplied.
so far I have item (mostly written out) and I'm fairly sure I wont have a problem with CD, Game and or ElectronicGame however when I try to code the vector for shop (and also when I test out code my lecturer has given us in class notes (which I will provide) I get an error message stating <identifier> expected on the line of the vector. I'm running Blue J version 2.1.3 (Java version (1.4.2_11). Here's the lecturer's code (hopefully something wrong with it

import java.util.*;
public class Library
{
private Vector<Book> mBooks = new Vector<Book>();
public Library()
{
}
public void addBook(Book newBook)
{
mBooks.add(newBook);
}
public void printAllBalances()
{
System.out.println("The library contains the following books:");
for (Book nextBook : mBooks)
{
nextBook.display();
}
}
public void getTotalBorrowings()
{
int total = 0;
for (Book nextBook : mBooks)
{
total += nextBook.getBorrowedCount();
}
System.out.println("There have been a total of " + total + " borrowings from the library");
}
}
Book (Book class included in case you needed it for de-bugging)
public class Book
{
private String mAuthor;
private String mTitle;
private boolean mBorrowed;
private int mBorrowedCount;
public Book(String author, String title)
{
mAuthor = author;
mTitle = title;
mBorrowed = false;
mBorrowedCount = 0;
}
public boolean borrowBook()
{
if (mBorrowed)
{
System.out.println("Sorry, " + mTitle + " by " + mAuthor + " is already borrowed");
return false;
}
else
{
mBorrowed = true;
mBorrowedCount++;
return true;
}
}
public void returnBook()
{
if (mBorrowed)
{
mBorrowed = false;
}
else
{
System.out.println("Error - this book was not borrowed so can't be returned");
}
}
public void display()
{
System.out.print(mTitle + " by " + mAuthor + " has been borrowed " + mBorrowedCount + " times and is currently ");
if (mBorrowed)
System.out.println("out");
else
System.out.println("in");
}
public int getBorrowedCount()
{
return mBorrowedCount;
}
}
I appologise for the novel and thank you in advance for any help you can give.
Jarell
Last edited by Jarell; Oct 31st, 2006 at 2:39 am.
It is because you are using Generics (which first came out in JDK 1.5.0) and are compiling with a JDK 1.4.2 compiler. You need to upgrade your JDK to a 1.5 version.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Here's the Java SE download page.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
![]() |
Similar Threads
- Java Noob Question (Java)
- Java Noob (Java)
- Type mismatch: cannot convert from int to ResultSet (JSP)
Other Threads in the Java Forum
- Previous Thread: Absolute no brainer
- Next Thread: How to execute shell command form Java servlet?
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows







you wouldn't happen to know where to do upgrade that would you?