Another Java Noob :(

Reply

Join Date: Oct 2006
Posts: 3
Reputation: Jarell is an unknown quantity at this point 
Solved Threads: 0
Jarell Jarell is offline Offline
Newbie Poster

Another Java Noob :(

 
0
  #1
Oct 31st, 2006
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
Last edited by Jarell; Oct 31st, 2006 at 2:39 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,277
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 242
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Another Java Noob :(

 
0
  #2
Oct 31st, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: Jarell is an unknown quantity at this point 
Solved Threads: 0
Jarell Jarell is offline Offline
Newbie Poster

Re: Another Java Noob :(

 
0
  #3
Oct 31st, 2006
Cool, thank you!!! you wouldn't happen to know where to do upgrade that would you?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Another Java Noob :(

 
0
  #4
Oct 31st, 2006
Here's the Java SE download page.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: Jarell is an unknown quantity at this point 
Solved Threads: 0
Jarell Jarell is offline Offline
Newbie Poster

Re: Another Java Noob :(

 
0
  #5
Nov 6th, 2006
Thank you very much and now to fail my assignment yay
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC