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.:- M9716841
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Java

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 ...

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. ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

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 ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why 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