Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5.2, Problem 14STQ
Give preconditions and postconditions for the following method, assuming that it is in the class SpeciesFourthTry in Listing 5.11:
public void updatePopulation()
{
population = (int) (population + (growthRate / 100) *
population);
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please complete the task by yourself only in JAVA with explanation. Don't copy. Thank you.
Using quicksort to sort an array of car objects by various criteria.
Define a class Car as follows:
class Car {
public String make;
public String model;
public int mpg; // Miles per gallon
}
c) Implement a comparator called CompareCarsByMakeThenDescendingMPG that can
be passed as an argument to the quicksort method from the lecture notes.
CompareCarsByMakeThenDescendingMPG should return a value that will cause quicksort
to sort an array of cars in ascending order by make and, when two cars have the same make, in
descending order by mpg.
Provide a different implementation of ChoiceQuestion. Instead of storing the choices in an array list, the addChoice method should add the choice to the question text. For this purpose, an addLine method has been added to the Question class.
/** A question with multiple choices.*/public class ChoiceQuestion extends Question{ // Add any needed instance variables, but don't store the choices // The choices should be added to the text of the superclass /* code goes here */ /** Constructs a choice question with a given text and no choices. @param questionText the text of this question */ public ChoiceQuestion(String questionText) { /code goes here */ }
/** Adds an answer choice to this question. @param choice the choice to add @param correct true if this is the correct choice, false otherwise */ public void addChoice(String choice, boolean correct) { /* code goes here */ }
}
1.A) The median of a set of integers is the middle-most
integer in size. That is, half the integers in the set are
less than or equal to the median, and half the integers
are greater than or equal to the median. For example,
the median of {99, 1, 10, 6, 2} is 6 since 1 and 2 are
smaller than 6 and 10 and 99 are larger than 6.
Implement a method median( ) with no parameters that
finds and returns the median of the integers in a data
array. Use this keyword in
meaningfully.
Assume that the data array is an instance variable of
Data class. Write a parameterized constructor to
allocate and assign values to data array. Assume that
the array has odd length. Write main () in a separate
class
constructor
to
use
the Data class.
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 5.1 - Consider the program in Listing 5.4 . Suppose you...Ch. 5.1 - Prob. 2STQCh. 5.1 - Prob. 3STQCh. 5.1 - Suppose every species in the world has a peculiar...Ch. 5.1 - Revise the definition of the method writeOutput in...Ch. 5.1 - Revise the definition of the method readInput in...Ch. 5.1 - Revise the definition of the method...Ch. 5.1 - What is the meaning of (int) that appears in the...Ch. 5.1 - Prob. 9STQCh. 5.1 - Define a method called getDensity that could be...
Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.2 - In Listing 5.12, we set the data for the object...Ch. 5.2 - Give preconditions and postconditions for the...Ch. 5.2 - What is an accessor method? What is a mutator...Ch. 5.2 - Give the complete definition of a class called...Ch. 5.2 - Prob. 17STQCh. 5.2 - In the definition of the method in Listing 5.15,...Ch. 5.2 - What is a well-encapsulated class definition?Ch. 5.2 - When should an instance variable in a class...Ch. 5.2 - Prob. 21STQCh. 5.2 - In a class definition, is anything private ever...Ch. 5.2 - In a class definition, is the body of any method...Ch. 5.3 - What is a reference type? Are class types...Ch. 5.3 - When comparing two quantities of a class type to...Ch. 5.3 - Prob. 26STQCh. 5.3 - Write a method definition for a method called...Ch. 5.3 - Given the class Species as defined in Listing...Ch. 5.3 - After correcting the program in the previous...Ch. 5.3 - What is the biggest difference between a parameter...Ch. 5.3 - Prob. 31STQCh. 5.3 - Write an equals method for the class Person...Ch. 5.4 - Rewrite the method drawFaceSansMouth in Listing...Ch. 5 - Design a class to represent a credit card. Think...Ch. 5 - Repeat Exercise 1 for a credit card account...Ch. 5 - Repeat Exercise 1 for a coin instead of a credit...Ch. 5 - Repeat Exercise 1 for a collection of coins...Ch. 5 - Consider a Java class that you could use to get an...Ch. 5 - Consider a class that keeps track of the sales of...Ch. 5 - Consider a class MotorBoat that represents...Ch. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10ECh. 5 - Write a program to answer questions like the...Ch. 5 - Define a class called Counter. An object of this...Ch. 5 - Prob. 3PCh. 5 - Define a Trivia class that contains information...Ch. 5 - Define a Beer class that contains the following...Ch. 5 - Write a grading program for an instructor whose...Ch. 5 - Add methods to the Person class from Self-Test...Ch. 5 - Create a class that represents a grade...Ch. 5 - Write a program that uses the Purchase class in...Ch. 5 - Write a program to answer questions like the...Ch. 5 - Consider a class that could be used to play a game...Ch. 5 - Consider a class BasketballGame that represents...Ch. 5 - Consider a class ConcertPromoter that records the...Ch. 5 - Prob. 9PPCh. 5 - Consider a class Movie that contains information...Ch. 5 - Repeat Programming Project 18 from Chapter 4, but...Ch. 5 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
T F Overuse of global variables can lead to problems.
Starting Out with C++ from Control Structures to Objects (8th Edition)
Write a program that asks the user to type in two integer values at the terminal. Test these two numbers to det...
Programming in C
Convert the do-while loop in the following code to a while loop: Scanner keyboard = new Scanner(System.in); Str...
Starting Out with Java: From Control Structures through Objects (6th Edition)
When placed at the end of an IfThenElself statement, this provides default action when none of the ElseIf state...
Starting Out With Visual Basic (8th Edition)
Fill in the blanks in each of the following statements: A relation that has no partial functional dependencies ...
Modern Database Management
True or False: You cannot create an array of generic class objects.
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Complete the Course class by implementing the courseSize() method, which returns the total number of students in the course. Given classes: Class LabProgram contains the main method for testing the program. Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.) Class Student represents a classroom student, which has three fields: first name, last name, and GPA. Ex. For the following students: Henry Bendel 3.6 Johnny Min 2.9 the output is: Course size: 2 public class LabProgram { public static void main (String [] args) { Course course = new Course(); // Example students for testing course.addStudent(new Student("Henry", "Bendel", 3.6)); course.addStudent(new Student("Johnny", "Min", 2.9)); System.out.println("Course size: " + course.courseSize()); } } public class Student { private String first; // first name private String last; // last name private…arrow_forward5. Write unit testing code for the following MyStack class using JUnit5 Framework. Make sure all the methods are tested and the timeouts of all methods’ call are at most 100 milliseconds. public class MyStack { private int SIZE; private int items[]; private int top; public MyStack(int size) { SIZE = size; items = new int [SIZE]; top = 0; boolean isFull() { if(top==SIZE) return true; return false; } boolean isEmpty() { if(top==0) return true; return false; } void push(int key) { if(isFull()) System.out.println("Stack Full."); else items[top++] = key; } void pop() {arrow_forwarddefine get() method .arrow_forward
- Task 3: Implement method setup in PE1 class. The description of what is wanted is given in the starter code. TASK 1 and 2 are done in class maze. Please use PE1 class. public class PE1 { MazedogMaze; /** * This method sets up the maze using the given input argument * @param maze is a maze that is used to construct the dogMaze */ publicvoidsetup(String[][]maze){ /* insert your code here to create the dogMaze * using the input argument. */ } /** * This method returns true if the number of * gates in dogMaze >= 2. * @return it returns true, if enough gate exists (at least 2), otherwise false. */ publicbooleanenoughGate(){ // insert your code here. Change the return value to fit your purpose. if() returntrue; } /** * This method finds a path from the entrance gate to * the exit gate. * @param row is the index of the row, where the entrance is. * @param column is the index of the column, where the entrance is. * @return it returns a string that contains the…arrow_forwardImplement the Rectangle class as discussed this week. Use the class declaration below. Your job is to implement the functions. Implement the missing functions yourself. class Rectangle{ private: double width; double length; char *name; void initName(char *); public://constructorsRectangle();Rectangle(double, double, char*);//destructor ~Rectangle(); void setWidth(double); void setLength(double); void setWidth(char *); void setLength(char *); void setName(char *); double getWidth() const; double getLength() const; void printName() const { cout << name; }}; A few notes on the functions: initName(char *): this is a private member function. It should be the only function which dynamically allocates a char array to hold the name. setName(char *): this is a public member function which changes the name of the rectangle to a new name. It does not dynamically allocate memory, it only changes name. Demonstrate your class works…arrow_forwardAbstract in Java Employee Override the display method in the Person class override the toString() and equals() methods Define method earnings as abstract with a return type of double. Hourly Employee provide the setters and getters of your data members provide call to parent contructors earnings is computed by having the product of the total number of hours worked and the rate. but if the number of hours worked exceeds 40, the rate increases to 150% of the current rate. (ex. rate=200; 150% = 300) override the toString() and equals() methods Note:Class Person is already loaded in this activity. No need to add the class in your code.arrow_forward
- Exercise (Section 30/40): Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, "see the dentist") and a date. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill an array of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occur on that date. Give the user the option to add new appointments. The user must specify the type of the appointment, the description, and the date.arrow_forwardWrite the definitions of the member functions of the classes arrayListType and unorderedArrayListType that are not given in this chapter. The specific methods that need to be implemented are listed below. Implement the following methods in arrayListType.h: isEmpty isFull listSize maxListSize clearList Copy constructor Implement the following method in unorderedArrayListType.h insertAt Also, write a program (in main.cpp) to test your function.arrow_forward1. Implement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. 2. Create array of countries called Arab of 22 countries, Write a function fill that fills the arrav Arab 3. Write a method that finds the city that has the max area in a country 4. Write a method that sorts the cities in a country from the largest to the smallest area 5. Write a function that retums array of countries of the same area of Arab 6. Write a function that compares between two countries. It returns true if countryl area greater than country2 area. 7. Write a function to move a city from one country to another.arrow_forward
- *using java* Create a class AnimalCreate a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal(String name) //constructor public void makesSound()with the implementation printing out a generic animal sound. Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!)Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the common ‘name’ member of Animal. --- Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. ( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class,…arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit only one class: Date.java. Do NOT include "public static void main()" method inside all of these classes. The class would be tested, using the unit-testing framework JUnit 4.arrow_forward1. Rewrite the Sorting class so that both sorting algorithms put the values in descending order. 2. Modify the Contact class in Chapter 10 so that the sorting methods invoked in PhoneList.java keeps the Contact objects sorted by phone number.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License