Click here to Skip to main content
15,887,135 members
Home / Discussions / Java
   

Java

 
AnswerRe: Solving symmetric tree problem by recursive solution Pin
Richard MacCutchan6-May-18 21:44
mveRichard MacCutchan6-May-18 21:44 
QuestionAsk a Question All Questions All Unanswered Mine FAQ I need to compare one file each line with other file all lines which separated by two colon separate .if matches with names I need print matched one in java Pin
Member 138094092-May-18 23:07
Member 138094092-May-18 23:07 
AnswerRe: Ask a Question All Questions All Unanswered Mine FAQ I need to compare one file each line with other file all lines which separated by two colon separate .if matches with names I need print matched one in java Pin
Richard MacCutchan3-May-18 0:44
mveRichard MacCutchan3-May-18 0:44 
QuestionDeep copy of List<> without knowing specific list type Pin
jackbrownii30-Apr-18 10:55
professionaljackbrownii30-Apr-18 10:55 
AnswerRe: Deep copy of List<> without knowing specific list type Pin
Manish K. Agarwal27-May-18 21:32
Manish K. Agarwal27-May-18 21:32 
QuestionStudent needing assistance while loop Pin
Victor McNeal21-Apr-18 9:15
Victor McNeal21-Apr-18 9:15 
AnswerRe: Student needing assistance while loop Pin
Richard MacCutchan21-Apr-18 20:56
mveRichard MacCutchan21-Apr-18 20:56 
QuestionJava JUnit test error Pin
CHUCHU YAO20-Apr-18 13:23
CHUCHU YAO20-Apr-18 13:23 
Hi all! I build a JUnit BookTestCase to test the minPrice() method in the BookApp class. The method is to find and return the minimum price of an array of book objects. But the test fails, and it shows "AssertionFailedError: expected: <34.99> but was: <0.0>". I don't know where the problem is, and where the 0.0 comes from. Thanks in advance!


The BookTestCase:
Java
class BookTestCase {
	
	private BookApp obj;
	private Book[] book = new Book[5];

	@BeforeEach
	void setUp() throws Exception {
		this.obj = new BookApp();
		book[0] = new Book(1, "HTLM", 56.0);
		book[1] = new Book(2, "Java", 128.0);
		book[2] = new Book(3, "Python", 34.99);
		book[3] = new Book(4, "C#", 40.0);
		book[4] = new Book(5, "C", 115.5);
	}

	@Test 
	void testPopulateBooks() {
		Assertions.assertThrows(IllegalArgumentException.class, () -> obj.populateBooks(6));
	}
	
	@Test
	void testMinPrice() {
		assertEquals(34.99, BookApp.minPrice(book), 0.0001);
	}
}



The minPrice() in BookApp class:
Java
public class BookApp {
     /**
	 * this method calculate the minimum price of books
	 * @param b
	 * @return the minimum price
	 */
	public static double minPrice(Book[] b) {
		double min = b[0].getPrice();
		for (int i = 1; i < b.length; i++) {
			if (b[i].getPrice() < min)
				min = b[i].getPrice();
		}
		return min;
	}
}

AnswerRe: Java JUnit test error Pin
Richard MacCutchan20-Apr-18 20:43
mveRichard MacCutchan20-Apr-18 20:43 
AnswerRe: Java JUnit test error Pin
jschell21-Apr-18 6:31
jschell21-Apr-18 6:31 
GeneralRe: Java JUnit test error Pin
Richard MacCutchan21-Apr-18 20:58
mveRichard MacCutchan21-Apr-18 20:58 
QuestionJAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Member 1378720218-Apr-18 20:59
Member 1378720218-Apr-18 20:59 
QuestionRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Richard MacCutchan18-Apr-18 21:51
mveRichard MacCutchan18-Apr-18 21:51 
AnswerRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Member 1378720219-Apr-18 0:54
Member 1378720219-Apr-18 0:54 
GeneralRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Richard MacCutchan19-Apr-18 1:02
mveRichard MacCutchan19-Apr-18 1:02 
AnswerRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
snoopy1118-Apr-18 23:17
snoopy1118-Apr-18 23:17 
JokeRe: JAVA Swing GUI Invoice - problem with correct actionPerformed Pin
Peter_in_278019-Apr-18 0:39
professionalPeter_in_278019-Apr-18 0:39 
Questiondesign a class Pin
Member 1365742917-Apr-18 21:18
professionalMember 1365742917-Apr-18 21:18 
GeneralRe: design a class Pin
Richard MacCutchan17-Apr-18 22:41
mveRichard MacCutchan17-Apr-18 22:41 
Questionjdbc connection Pin
Member 137686618-Apr-18 7:26
Member 137686618-Apr-18 7:26 
AnswerRe: jdbc connection Pin
Richard MacCutchan8-Apr-18 21:51
mveRichard MacCutchan8-Apr-18 21:51 
Questioni need help fast.i have only 2 days left Pin
Member 137677117-Apr-18 11:35
Member 137677117-Apr-18 11:35 
Questionhow to protect jar file from decompilation Pin
Renu Meena15-Mar-18 18:44
Renu Meena15-Mar-18 18:44 
AnswerRe: how to protect jar file from decompilation Pin
Richard MacCutchan15-Mar-18 22:09
mveRichard MacCutchan15-Mar-18 22:09 
GeneralRe: how to protect jar file from decompilation Pin
Renu Meena15-Mar-18 23:02
Renu Meena15-Mar-18 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.