Click here to Skip to main content
15,923,910 members
Home / Discussions / Java
   

Java

 
AnswerRe: Java Tutorials??? Pin
ajaysud955-Oct-09 2:04
ajaysud955-Oct-09 2:04 
AnswerRe: Java Tutorials??? Pin
Richard MacCutchan5-Oct-09 6:47
mveRichard MacCutchan5-Oct-09 6:47 
AnswerRe: Java Tutorials??? Pin
Reagan Conservative5-Oct-09 11:34
Reagan Conservative5-Oct-09 11:34 
GeneralRe: Java Tutorials??? Pin
TGeist5-Oct-09 17:32
TGeist5-Oct-09 17:32 
GeneralRe: Java Tutorials??? Pin
Nagy Vilmos6-Oct-09 6:18
professionalNagy Vilmos6-Oct-09 6:18 
Questionhelp regarding J2EE books. Pin
madhu91244-Oct-09 7:16
madhu91244-Oct-09 7:16 
AnswerRe: help regarding J2EE books. Pin
42774804-Oct-09 9:38
42774804-Oct-09 9:38 
Questionplz help me Pin
arifihsan3-Oct-09 7:06
arifihsan3-Oct-09 7:06 
hello
sir help me in this regards,i vl waiting for ur positive reply.




Your task is to create a programming system for a ferry. The ferry transports passengers and vehicles (cars, busses, lorries and bicycles). The ferry has space for 200 passengers and 40 cars. A lorry need as much space as two busses or 8 cars. A car need as much space as 5 bicycles. There are different fees for different vehicles and an extra fee might be added for passengers. Use the following fees:

1. Passenger without vehicle, 20 kr.
2. Bicycle 40 kr (passenger included).
3. Car 100 kr + 15 kr/passenger. (maximum 4 passengers)
4. Bus 200 kr + 10 kr/ passenger. (maximum 20 passengers)
5. Lorry 300 kr + 15 kr/ passenger. (maximum 2 passengers)

Every type of vehicle (car, bus, lorry, bicycle) will inherit from the class Vehicle. The functionality of the ferry is given by the interface Ferry :

public interface Ferry {
int countPassengers(); // Number of passengers on board
int countVehicleSpace(); // Used vehicle space. One car is 1.
int countMoney(); // Earned money
Iterator iterator(); // Vehicle iterator
void embark(Vehicle v); // Embark vehicle, warning if not enough space
void embark(Passenger p); // Embark passenger, warning if not enough room
void disembark(); // Clear (empty) ferry. The money earned remains,
// i.e., is not reset to zero
boolean hasSpaceFor(Vehicle v); // true if we can embark vehicle v
boolean hasRoomFor(Passenger p); // true if we can embark passenger p
String toString(); // Nice looking ferry status print out

}

A vehicle cannot leave the ferry until the ferry has been disembarked and the same vehicle cannot embark twice. The ferry iterator should iterate over all vehicles embarked (not the passengers). Also write a test program FerryMain.java, embarking a number of vehicles and passengers, showing the functionality of the methods.

# Exercise 2 (Getting Started with JUnit)

In this exercise we provide you with two classes. DataNetwork is a utility class, used in a real life project, to convert sequences of bytes (comming from the network) into Java data types. DataNetworkTest contains the tests for the previous class. Your task is:

1. Create a new project in Eclipse.
2. Configure the project to use JUnit 4 (see above).
3. Copy this two file (you will need to create the package da2222 first).
4. Execute the test and see the green bar. Smile | :)
5. Uncomment the second assertEquals and see the red bar. :'(
6. Make it green! Big Grin | :-D
7. Append a small comment in the getShort() javadoc explaining what happened.


DataNetwork.java

package da2222;

/**
* Utility class to retrieve data from a byte array (in network format).
*/
public class DataNetwork {

/**
* Get the byte in the specific offset.
*/
public static byte get(byte[] data, int offset) {
return data[offset];
}

/**
* Get the short in the specific offset. Big endian
*/
public static short getShort(byte[] data, int offset) {
return (short) (get(data, offset) << 8 | get(data, offset + 1));
}
}



DataNetworkTest.java

package da2222;

import static org.junit.Assert.*;
import org.junit.*;

public class DataNetworkTest {

@Test
public void testGetShort() {
byte[] data = new byte[] {(byte) 0x00, (byte) 0x20, (byte) 0x84};
assertEquals(0x0020, DataNetwork.getShort(data, 0));
//assertEquals(0x2084, DataNetwork.getShort(data, 1));
}
}


# Exercise 3 (Writing JUnit Tests)
In your first assignment, Exercise 7, you implemented a class Arrays.java containing a number of methods that manipulated integer arrays. The task is now to implement a JUnit test (ArraysTest.java) for the class, verifying the correctness of each method.

# Exercise 4 (Generics and JUnit)
In your first assignment, Exercise 12, you provided a class that implemented a simple Queue interface.

1. Convert your implementation (both the interface and the class implementing it) to a generic Queue.
2. Write a JUnit test (QueueTest.java) for the generic Queue implementation that verifies the correctness of each method in the interface. Remember to test also the "extreme cases" (operations on an empty Queue, add a huge amount of elements...).
AnswerRe: plz help me Pin
42774803-Oct-09 8:50
42774803-Oct-09 8:50 
QuestionImplementing a Dictionary Pin
pinkett2-Oct-09 23:40
pinkett2-Oct-09 23:40 
AnswerRe: Implementing a Dictionary Pin
42774803-Oct-09 0:34
42774803-Oct-09 0:34 
QuestionJAVA Swing Tooltips Pin
simondopickup2-Oct-09 6:23
simondopickup2-Oct-09 6:23 
AnswerRe: JAVA Swing Tooltips Pin
42774802-Oct-09 22:07
42774802-Oct-09 22:07 
AnswerRe: JAVA Swing Tooltips Pin
simondopickup3-Oct-09 5:19
simondopickup3-Oct-09 5:19 
GeneralRe: JAVA Swing Tooltips Pin
42774803-Oct-09 8:52
42774803-Oct-09 8:52 
QuestionProblem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
pohcb_sonic1-Oct-09 19:17
pohcb_sonic1-Oct-09 19:17 
AnswerRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
David Skelly1-Oct-09 22:20
David Skelly1-Oct-09 22:20 
AnswerRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
42774802-Oct-09 22:12
42774802-Oct-09 22:12 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
pohcb_sonic3-Oct-09 4:44
pohcb_sonic3-Oct-09 4:44 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
pohcb_sonic3-Oct-09 4:44
pohcb_sonic3-Oct-09 4:44 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
Richard MacCutchan3-Oct-09 5:39
mveRichard MacCutchan3-Oct-09 5:39 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
42774803-Oct-09 8:53
42774803-Oct-09 8:53 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
Richard MacCutchan3-Oct-09 21:38
mveRichard MacCutchan3-Oct-09 21:38 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
42774804-Oct-09 0:10
42774804-Oct-09 0:10 
GeneralRe: Problem : Reading and Writing of Byte[] Array Messages to Serial Comm (Serial Port RS232) Pin
Richard MacCutchan4-Oct-09 1:15
mveRichard MacCutchan4-Oct-09 1:15 

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.