Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M9131588
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Java

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As