7.17.5. Arrange code to provide a property with methods for getting and setting the number of seats. A passenger van can be configured with different seating capacities, up to a maximum capacity (the default). Provide a "seats" property with methods for getting and setting the currently configured number of seats. Reject efforts to set an improper number of seats. Not all lines are useful maximumCapacity maxPassengers; maxPassengers maximumCapacity; ACTIVITY return maximumCapacity; return seats; seats maximumCapacity; seats = 0; if (0 <= newValue && newValue < maximumCapacity) if (newValue <= maximumCapacity) if (newValue <- 6) seats newValue; newValue - seats; import java.util.Scanner; public class van private int maximusCapacity; private int seats; public Van(int maxPassengers) public int getseats() public void setseats(int newValue) public static void main(String[] args) Scanner in new Scanner(System.in); int maxCapacity in.nextInt(); int overMaxCapacity in.nextInt(); int underMaxCapacity in.nextInt (); Van myVan neu Van (maxCapacity) System.out.println(myvan.getSeats())) myVan.setSeats (overMaxCapacity); System.out.println(myVan.getSeats()); myVan.setSeats (underMaxCapacity); System.out.println(nyVan.getSeats()))
7.17.5. Arrange code to provide a property with methods for getting and setting the number of seats. A passenger van can be configured with different seating capacities, up to a maximum capacity (the default). Provide a "seats" property with methods for getting and setting the currently configured number of seats. Reject efforts to set an improper number of seats. Not all lines are useful maximumCapacity maxPassengers; maxPassengers maximumCapacity; ACTIVITY return maximumCapacity; return seats; seats maximumCapacity; seats = 0; if (0 <= newValue && newValue < maximumCapacity) if (newValue <= maximumCapacity) if (newValue <- 6) seats newValue; newValue - seats; import java.util.Scanner; public class van private int maximusCapacity; private int seats; public Van(int maxPassengers) public int getseats() public void setseats(int newValue) public static void main(String[] args) Scanner in new Scanner(System.in); int maxCapacity in.nextInt(); int overMaxCapacity in.nextInt(); int underMaxCapacity in.nextInt (); Van myVan neu Van (maxCapacity) System.out.println(myvan.getSeats())) myVan.setSeats (overMaxCapacity); System.out.println(myVan.getSeats()); myVan.setSeats (underMaxCapacity); System.out.println(nyVan.getSeats()))
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
JAVA

Transcribed Image Text:**Title: Arranging Code for Managing Van Seating Capacity**
**Description:**
In this exercise, we task students with arranging Java code to correctly implement a property with methods for getting and setting the number of seats in a van. The van can have various seating configurations, but it cannot exceed a predefined maximum capacity. The goal is to ensure only valid operations are performed when setting the seat configuration.
**Code Block Breakdown:**
1. **Variables & Constructor Initialization:**
- `maximumCapacity = maxPassengers;`
- Assigns the provided maximum passenger count to `maximumCapacity`.
- `maxPassengers = maximumCapacity;`
- Sets `maxPassengers` to `maximumCapacity` (not logically meaningful, likely a distractor).
- `public Van(int maxPassengers) { ... }`
- Constructor takes `maxPassengers` and initializes the van object.
2. **Getter Method:**
- `public int getSeats() { ... }`
- Method to return the current number of seats configured in the van.
3. **Setter Method:**
- `public void setSeats(int newValue) { ... }`
- Method to set a new seat count with validation.
- `if (0 <= newValue && newValue <= maximumCapacity) { ... }`
- Condition ensures `newValue` is within a valid range from 0 to `maximumCapacity`.
4. **Return Statements:**
- `return maximumCapacity;`
- `return seats;`
- These lines are used to return current values in methods as required.
5. **Variable Operations:**
- `seats = maximumCapacity;`
- Sets number of seats to the maximum capacity.
- `seats = 0;`
- Initializes or resets seats to zero.
- `seats = newValue;`
- Updates seats to a new validated value.
- `newValue = seats;`
- Assigns current seats to `newValue` (for temporary operations).
6. **Main Method:**
- Demonstrates practical implementation.
- Creates a `Van` object with input values for `maxCapacity` and `maxPassengers`.
- Sets and gets seat configurations using the defined methods.
**Learning Objectives:**
- Understand how to properly structure and arrange code for initialization, getters, and setters.
- Learn validation logic to ensure safe state changes within a class.
- Practice
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY