Problem 1write a java class called problem1 implement the

Assignment Help JAVA Programming
Reference no: EM13347224

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.

Reference no: EM13347224

Questions Cloud

Case studyfind and read the judgment in p j mccarthy amp : case studyfind and read the judgment in p j mccarthy amp sons pty ltd v q paint pty ltd 2013 qsc 39 and answer the
Prepare a capstone report for designing of steel building : prepare a capstone report for designing of steel building using aisc 14 edition manual. the capstone report contents
Advanceddesignmethodologies : advanceddesignmethodologies productandengineeringdesignreview
In all but a very few vehicles today crush or crumple zones : in all but a very few vehicles today crush or crumple zones are employed as a method to reduce energy transfer to the
Problem 1write a java class called problem1 implement the : problem 1write a java class called problem1. implement the following method in your classpublic static int
1 write a c program that takes an eastern standard time : 1. write a c program that takes an eastern standard time in hours minutes and secondsand prints it out in central
Cwsi project health industry in uk mobile device management : cwsi project health industry in uk mobile device management enterprise management marketcwsi is a small organisation
Write a class named java1306cmis141c801 that performs the : write a class named java1306cmis141c801 that performs the following actions.prompt the user for an int between lower
Part-1case study there will be two assigned comprehensive : part-1case study there will be two assigned comprehensive case studies that will be required in the course. the purpose

Reviews

Write a Review

JAVA Programming Questions & Answers

  Approximate the volume of cheese in a rectangular hunk

You will create a program that will approximate the volume of cheese in a rectangular hunk of Swiss cheese. For this approximation you will assume that the holes in the Swiss cheese are of two types: spherical bubbles (all of the same size) or cyl..

  Create the look for two gui applications

Create the look for two GUI applications. You WILL NOT be getting the applications to do anything. We are only interested in seeing how well you can arrange the GUI components onto the window

  Multiple choice java programming questions

Determine which of the following may be a violation of information hiding if inserted for the comment above?

  Implement a class called reversewords

Implement a class called ReverseWords that uses a stack to output a set of elements input by the user in reverse order.

  Executing stringed musical instrument class

Create and execute a stringed musical instrument class.

  Create file lab7.java with a main method.

Create file Lab7.java with a main method. Inside your main method, write a segment of code which instantiates an object of the Student class (This class has been created for you in the  Student.java  file that is provided as part of this lab).

  Consider an array of integers

Consider an array of integers as below: int[] a = {5, 2, -4, 3, 0, -5, 7, 11, 6, 13} Complete the method named count(int[] a) in the class Count. The method should return the number of positive numbers in the array

  Tracer for java

Implementation of a tracer of Java objects and the tracer can be invoked from any point of a Java program, accepting an object as argument.

  Write an application that enables users to enter student ID

Write an application that enables users to enter student ID and three exam scores. Provide a method to compute and returnthe overall exam average.  Provide another method that prints all scores and the average value formatted with no digits to the ri..

  Write a script and verify an logi by reading a file from xl

write a script and verify an logi by reading a file from xl sheet, first time only give the password and get an error message, second time give the email only and get an error message and third time give both email and correct password and get "Signe..

  Write down the java code for the bank

Write down the java code for the bank of Fraud. User is presented with menu which looks something like this: 1. Deposit 2. Withdrawal 3. Check Balance 4. Exit.

  Write a recursive public method

Write a recursive public method in our BST class that returns a reference to the information in the node containing the smallest value in the tree. The signature of the method is

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd