macosxnerd101, on 19 September 2014 - 09:25 AM, said:
So I got super mixed up and I was mixing my Book and Trilogy Class the whole time.
A book (for this Java course), consists of 3 variables: Title, Author and Publisher.
A Trilogy, consists of 4 variables: 3 Books, 3 Titles, 3 Authors and 3 Publishers.
Now here is what I have implemented:
public class Book {
//variables
private String Title;
private String Author;
private String Publisher;
//constructor
public Book(String Title, String Author, String Publisher) {
this.Title = Title;
this.Author = Author;
this.Publisher = Publisher;
}
// setters and getters
public void setBook(String Title, String Author, String Publisher) {
this.Title = Title;
this.Author = Author;
this.Publisher = Publisher;
}
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String Author) {
this.Author = Author;
}
public String getPublisher() {
return Publisher;
}
public void setPublisher(String Publisher) {
this.Publisher = Publisher;
}
}
public class Trilogy {
public static void main(String[] args) {
}
// variables
private String Book1, Book2, Book3;
private String Title;
private String Author;
private String Publisher;
// constructor
public Trilogy(String Book1, String Book2, String Book3, String Title,
String Author, String Publisher) {
this.Book1 = Book1;
this.Book2 = Book2;
this.Book3 = Book3;
this.Title = Title;
this.Author = Author;
this.Publisher = Publisher;
}
// setters and getters
public void setTrilogy(String Book1, String Book2, String Book3,
String Title, String Author, String Publisher) {
this.Book1 = Book1;
this.Book2 = Book2;
this.Book3 = Book3;
this.Title = Title;
this.Author = Author;
this.Publisher = Publisher;
}
public String getBook1() {
return Book1;
}
public String getBook2() {
return Book2;
}
public String getBook3() {
return Book3;
}
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String Author) {
this.Author = Author;
}
public String getPublisher() {
return Publisher;
}
public void setPublisher(String Publisher) {
this.Publisher = Publisher;
}
}
This last bit of code is my homework tester (this is not part of my code):
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class Hw3Tester {
@Test
public void testBookConstructor() {
Book book = new Book("Fellowship of the Ring", "J.R.R. Tolkien",
"George Allen && Unwin");
Assert.assertEquals("Fellowship of the Ring", book.getTitle());
Assert.assertEquals("J.R.R. Tolkien", book.getAuthor());
Assert.assertEquals("George Allen && Unwin", book.getPublisher());
score = score + 1;
}
@Test
public void testSetTitle() {
Book book = new Book("Fellowship of the Ring", "J.R.R. Tolkien",
"George Allen && Unwin");
book.setTitle("The Hobbit");
Assert.assertEquals("The Hobbit", book.getTitle());
score = score + 1;
}
@Test
public void testSetAuthor() {
Book book = new Book("Fellowship of the Ring", "J.R.R. Tolkien",
"George Allen && Unwin");
book.setAuthor("David Gowans");
Assert.assertEquals("David Gowans", book.getAuthor());
score = score + 1;
}
@Test
public void testSetPublisher() {
Book book = new Book("Fellowship of the Ring", "J.R.R. Tolkien",
"George Allen && Unwin");
book.setPublisher("David Gowans");
Assert.assertEquals("David Gowans", book.getPublisher());
score = score + 1;
}
@Test
public void testSetTrilogyName() {
Trilogy trilogy = new Trilogy();
trilogy.setName("The Lord of the Rings");
Assert.assertEquals("The Lord of the Rings", trilogy.getName());
score = score + 1;
}
@Test
public void testSetBook1() {
Book book1 = new Book("Fellowship of the Ring", "J.R.R. Tolkien",
"George Allen && Unwin");
Trilogy trilogy = new Trilogy();
trilogy.setBook1(book1);
trilogy.setName("The Lord of the Rings");
Book actualBook = trilogy.getBook1();
Assert.assertEquals(book1.getTitle(), actualBook.getTitle());
Assert.assertEquals(book1.getAuthor(), actualBook.getAuthor());
Assert.assertEquals(book1.getPublisher(), actualBook.getPublisher());
score = score + 1;
}
@Test
public void testSetBook2() {
Book book2 = new Book("The Two Towers", "J.R.R. Tolkien",
"George Allen && Unwin");
Trilogy trilogy = new Trilogy();
trilogy.setBook2(book2);
trilogy.setName("The Lord of the Rings");
Book actualBook = trilogy.getBook2();
Assert.assertEquals(book2.getTitle(), actualBook.getTitle());
Assert.assertEquals(book2.getAuthor(), actualBook.getAuthor());
Assert.assertEquals(book2.getPublisher(), actualBook.getPublisher());
score = score + 1;
}
@Test
public void testSetBook3() {
Book book3 = new Book("The Return of the King", "J.R.R. Tolkien",
"George Allen && Unwin");
Trilogy trilogy = new Trilogy();
trilogy.setBook3(book3);
trilogy.setName("The Lord of the Rings");
Book actualBook = trilogy.getBook3();
Assert.assertEquals(book3.getTitle(), actualBook.getTitle());
Assert.assertEquals(book3.getAuthor(), actualBook.getAuthor());
Assert.assertEquals(book3.getPublisher(), actualBook.getPublisher());
score = score + 1;
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
score = 0;
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("Test Score = " + score + "/8");
System.out
.println("The final 2 points for the assignment will be graded manually.");
System.out
.println("1 point for comments. Your code must always be commented");
System.out
.println("1 point for your nouns and verbs list. Be sure to include this in your eclipse project that you zip and submit.");
}
private static int score;
}
A lot of errors got resolves on the homework tester, but I am still getting errors on tests 5, 6, 7 and 8 which lead me to believe that there is something wrong with my code that is creating these errors.
I feel like I am a lot closer, but I am confused to what is creating these errors.

New Topic/Question
Reply




MultiQuote




|