Vous êtes sur la page 1sur 15

Q1:In this question, you will implement methods for an OutLook class that stores emails.

The E-
mail class is provided below. An E-mail consists of a sender, a message, and a field that tells
whether or not the e-mail has been read.

public class Email


{
private String sender;
private String msg;
private boolean read;

public String getSender( ){

//Implementation not shown


}
public String getMsg( ){

//Implementation not shown


}
.. / /Returns whether the e-mail was read
public boolean isRead( ){

//Implementation not shown


}

An incomplete declaration for the OutLook class is shown below. The OutLook class contains
two ArrayLists: inbox and recycleBin. Each e-mail in the ArrayLists corresponds to a number
between 0 and the size of the list of e-mails minus one. For example, if there are 50 e-mails in
the inbox, the e-mails have a number between 0 and 49.

public class OutLook


{
//Contains a list of e-mails
private ArrayList <Email> inbox=new ArrayList <Email> ( );

//Contains a list of e-mails that are up for deletion


private ArrayList <Email> recycleBin=new ArrayList <Email> ( );
Task 1:
//Display the messages of each unread e-mail in the inbox

public void openEmails( )

Task 2:
//Counts the number of e-mails in the inbox that have the same sender as the provided name.

public int sameSender(String sendName)

Task #3:
//Remove the e-mail at the provided index and add it to the recycle bin for later deletion. Return
the number of e-mails in the recycle bin.

public int deleteEmail(int index)

Task #4:
//Permanently removes all e-mails from the recycle bin. Return true when emptied successfully.

public boolean emptyRecycleBin( )


Q2: In this question, you will implement methods for a class Flight that is part of an airline
reservation system. The Flight class uses the Passenger class shown below. A Passenger is made
up of a name for the passenger and the seat number of the passenger. A constructor has been
provided that creates a Passenger with a given name and seat number.

public class Passenger


{
private String name;
private int seatNum;

public Passenger(String n, int seat){


//Implementation not shown
}
public String getName( ){
//Implementation not shown
}
public String getSeat( ){
//Implementation not shown
}

An incomplete declaration for the Flight class is shown below. Each flight has seats numbered 0,
1, 2.... up to the capacity of the flight. For example, a flight with 100 seats would have room for
numbers 0 through 99.

public class Flight


{
//Each element corresponds to a passenger who has reserved a seat on the flight. The passenger’s
seat number is the index of the ArrayList where the passenger is stored.

private ArrayList<Passenger> flight=new ArrayList<Passenger> ( );

//Contains names of people who have not been assigned to a seat because the flight was full

private ArrayList<String> wait=new ArrayList<String> ( );

//Represents the maximum number of passengers that are allowed on the flight

private int capacity=0;

//Constructor to create a flight of a given capacity

public Flight (int maxCapacity)


Task # 1:
//Displays the names of all the passengers on the flight
public void showPassenger( )

Task #2:
//If there are more seats available on the flight, then create a passenger with the provided name for the next
//empty seat on the flight and add the passenger to the /flight. If there are no more seats available on the flight,
//add the person's name to the wait list. Return true if the person was able to reserve a seat on the flight and
//false otherwise.

public boolean reserveSeat (String passname)

Task #3:

//Release the seat occupied by the provided passenger. If there are names on the waiting list,
//remove the first name from the list, create a Passenger with the name and the seat number just
//released, and add this passenger to the flight. If the person from the waiting list was added to
//the flight, return true. If the waiting list is empty, return false.

public boolean cancelAndFill (Passenger pass)


Task #4:

//The airline puts all passengers whose names have four letters in the front of the flight. If the
//provided name has four letters, create a passenger and add them to the first seat of the flight. If
//the name does not have four letters, add them to the next available seat on the flight. Return
//true if the person has reserved a seat on the flight and false otherwise. You must use the
reserveSeat method previously completed assuming that the method works as intended.

public boolean reserveFour(String passName)


Q3: In this question, you will implement methods for a class BirthdayBoard that represents name
and birth date information on a balloon in Miss Brown’s classroom. A PersonInfo class is
provided below:

public class PersonInfo


{
private String name;
private int month, day, year;

public String getName()

public int getMonth()

public int getDay()

public int getYear()


}

An incomplete declaration for the BirthdayBoard class is shown below. The person information
contained in the birthday board is in no particular order.

public class BirthdayBoard


{
//List of person information that represents the birthday board
private ArrayList <PersonInfo> board=new ArrayList <PersonInfo>();
}

Task 1:

//Display the names of all the people with a birthday in the provided month.

public void monthBDays( int m)


Task #2:

//Return the name of the person who was born latest in the year.

public String bornLatest()


Task #3:

//Returns the name of the oldest person.

public String oldest()


Q4: In this question, you will implement methods for a BowlingGame class that stores frames
from the game of bowling. The Frame class is provided below. A Frame consists of two fields
that represent the two rolls of the ball along with an accessor method for the field. Two
constructors are provided as well and are detailed below.

public class Frame


{
private int roll1, roll2;

//constructor that creates an empty frame


public Frame()

//constructor that creates a frame with the score recorded


public Frame (int r1, int r2)

//accesses the value of roll1


public int getFirst()

//accesses the value of roll2


public int getSecond()

An incomplete declaration for the BowlingGame class is shown below. The BowlingGame class
contains one ArrayList called game that consists of Frames, and the name of a bowler. Each
frame in the ArrayList corresponds to a number between 0 and the size of the game list minus
one. For example, if there are 10 frames in the game, the frames have a number between 0 and 9

public class BowlingGame


{
//contains a list of frames currently unintialized, contains no Frames

private ArrayList <Frame> game;


String name=””;

//accesses the name field


public String getName()

}
Here is a sample game to use as test data:

name=”Joseph Blo”
game (with 7 frames)

Frames:
1 2 3 4 5 6 7
Rolls:
4 10 6 7 5 0 7

3 0 3 3 2 10 2

When a 10 is recorded for roll 1, then the player got a strike. When the sum of the roles is 10
and the first roll is not a 10, then the player got a spare. In the above diagrams, the second frame
represents a strike and the 4th and 6th frames are spares.

When a spare or strike is recorded in the last (10th frame) the bowler is awarded an extra (third)
roll which is added to the second roll for the purposes of simplicity.

Task #1:

//Write the Bowling Game constructor that creates a 10 frame game with all rolls initialized to 0.
//The bowler’s name should be initialized to “none”.

public BowlingGame()
Task #2: Write a constructor for the BowlingGame calls that creates a 10 frame game that uses
a random number for the first roll and a random possible complement for the second roll. The
bowler’s name should be set to parameter that is passed to the constructor. Be sure to account for
a strike or spare in the last frame by adding an extra randomly generated roll to the second roll.

To generate a random number, use the following code template:

variable= (int) ((range of numbers + 1) * Math.random()) + lowest number;

public BowlingGame(String bowlerName)

Task #3:

//Display the rolls for each frame in the game

public void DisplayGame()


Task #4:

//in bowling, if you have a “mark” on your score card, then you rolled a strike or a spare. Write
//code to count the number of marked frames in a game and return the count.

public int numMarkedFrames ()


Task #5:

//There are few rules for calculating a bowling score. If a spare is rolled in a frame, then the
frame’s score is calculated by adding 10 to the first roll of the next frame. If a strike is rolled in
a frame, then the score is calculated by adding 10 to both rolls of the next frame. If neither a
spare or strike is rolled then the total of the rolls are added to the score. Calculate and return the
score for an initialized bowling game.

public int calcScore()


In incomplete declaration for the Team class is shown below. A Team consists of an ArrayList
of BowlingGames called teamMembers. The size of the teamMembers ArrayList is 4, as there
are only 4 members on a team.

public class Team


{

private ArrayList <BowlingGame> teamMembers=new ArrayList <BowlingGame> ();

Task #6:

//Calculate and display the score of each team member. In completing the task, you must use the
//calcScore method in Task 5 assuming it works as intended.

public void calcTeamScore()


Task #7

//The team member with the highest average is the MVB (Most Valuable). Return the name of
//the team member who is the MVB. In performing the work of this function, you must use the
//calcScore method of Task 5 assuming it works as intended.

public String MVB()

Vous aimerez peut-être aussi