problem 1write a java class called problem1


Problem 1

Write a Java class called Problem1. Implement the following method in your class:

public static int longestStreak(boolean[] values)

/* Purpose: computes the length of a longest streak of consecutive                   *
* true occurrences in values                                                                                 *
* Preconditions: values is a non-null array of booleans with length at least 1     *
* Postconditions: outputs the maximal number of consecutive trues found in     *
* the input array                                                                                                   */

At the bottom of your Problem1.java le, include a comment block that describes ve black box test cases for this method. Think about what it means to be an edge case, near
edge case and extreme case for this method. Your tests should include at least one of each of these tests.

Note: Do not include a main method in your class.

Problem 2


Write a Java class called Problem2. Implement the following method in your class:


public static int[] longestStreak(boolean[] values)
/* Purpose: computes the length and location of the first maximal sequence           *
* of consecutive true occurrences in values                                                               *
* Preconditions: values is a non-null array of booleans with length at least 1          *
* Postconditions: outputs an integer array with two elements                                 *
* - first element is the length of a maximal sequence of                                            *
* consecutive trues in the input array values                                                            *
* - second element is the location, in values, of the first                                           *
* occurrence of a maximal sequence of consecutive trues                                         *
* - use -1 if there are no trues in the input array                                                      */

Note: Do not include a main method in your class.

Problem 3


Write a Java class called House. The class is used for a real estate company that sells houses. Your class must have the following attributes and methods:
/* attributes */

public String address;             // where the house is located
public long askingPrice;          // asking price to sell the house
private long minSellPrice;      // minimum price that house can actually sell for
private int numOffers;          // number of offers to buy house
/* constructor */

public House(String address, long asking, long minimum);
// initializes address, askingPrice and minSellPrice to input values
// initializes numOffers to zero

/* methods */
public boolean makeOffer(long offer);
// Preconditions: offer is a non-negative long
// Postconditions: Return true if the house hasn't already been sold and if the
//                          the offer is greater than or equal to minSellPrice
//                          Return false otherwise
// Side Effects: If 5 offers have been made for an unsold house, then the
//                          minSellPrice is lowered to be 1/2 way between the original
//                          value and the highest (rejected) offer so far, provided that
//                         the highest offer is at least 60% of the minSellPrice.
//                         If this condition is met, the value is decreased by
//                          (minSellPrice-maxOffer)/2
You may add any private attributes and methods that you see t. Private attributes and methods in a House object are only accessible from methods de ned in the House class.

They cannot be accessed directly by any other class.

Note: Do not include a main method in your class.

Problem 4

Write a Java class called Student, with the following attributes:

public String name;          // student's name
public int id;                    // student's id number in range [100000000,100999999]
public byte[] grades;     // all grades of courses taken [0,100]

Add a single constructor that takes a String and int as input and initializes the name and id elds of the student. Also, override Object's toString(), hashCode() and equals()
methods in Student in the following way:

1. toString() should display the Student's name, followed by a comma, followed by their id number.

2. hashCode() should return the six least signi cant digits of their student id number.

3. equals(Object obj) should return true if obj is a Student that has the same name and id number as this. It should return false otherwise.

Create a second class called Undergrad that extends the Student class. This class has one new method in it:

public boolean eligible(int numCourses, double ave)
// Purpose: determine if the student is eligible to convocate
// Precondition: numCourses is in the range [10,40] ave is in the range [0.5, 1.0]
// Postconditions: Returns true if the student has taken more than numCourses and has
//                          an overall average at least ave
//                          Returns false otherwise

You will also need to create an appropriate constructor for this class. Use the following:

public Undergrad(String name, int id){
super(name, id);}

Include a comment in this constructor explaining why it is not simply a copy & paste of the code in the constructor for the Student class. (This is part of your correctness mark.)

Note: Do not include a main method in either of these classes.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: problem 1write a java class called problem1
Reference No:- TGS0442735

Now Priced at $30 (50% Discount)

Recommended (93%)

Rated (4.5/5)