Compilation and Execution - JAVA problem

Assignment Help JAVA Programming
Reference no: EM131143

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: EM131143

Questions Cloud

Judgment in p j mccarthy & sons pty ltd v q paint pty ltd : Find and read the Judgment in P J McCarthy & Sons Pty Ltd v Q Paint Pty Ltd.
Prepare a capstone report : Prepare a capstone report for designing of steel building using AISC 14 edition manual.
Product and engineering design review : Product and Engineering Design Review
Advanced stress analysis assignment : Advanced Stress Analysis Assignment
Compilation and Execution - JAVA problem : Style marks are based on how your submitted code looks. Remember that good code is easily readable (and understandable) by someone who did not write it. For assignments, you should also include your name, student number, what course this is, what ass..
Time conversion : Write a C++ program that takes an Eastern standard time in hours, minutes, and seconds,and prints it out in Central time, Mountain time, or Pacific time.
Cwsi project : Project Template for CWSI Project
Java project : Prompt the user for an int between lower and upper boundary.
Case study and research paper : Google Case and Chipotle Case

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Write a recursive instance method

Write a recursive instance method

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  Cascading style sheet to a website

Compare and contrast the process of adding JavaScript and a Cascading Style Sheet to a Website. Determine if they can be used simultaneously in a page.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

  Java program to create a tree

Java program to create a tree, generate class - BottomUpTwoThreeFourTree, BottomUpTwoThreeFourTree,

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

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