Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, i am stuck on this problem in Java i was given this code and i had to modify it i am not sure exactly

image text in transcribed

Hi, i am stuck on this problem in Java i was given this code and i had to modify it i am not sure exactly how to modify it.

AutoPolicy code

public class AutoPolicy {

private int accountNumber; // policy account number private String makeAndModel; // car that the policy applies to private String state; // two-letter state abbreviation

// constructor public AutoPolicy(int accountNumber, String makeAndModel, String state) { this.accountNumber = accountNumber; this.makeAndModel = makeAndModel; this.state = state; }

// sets the accountNumber public void setAccountNumber(int accountNumber) { this.accountNumber = accountNumber; }

// returns the accountNumber public int getAccountNumber() { return accountNumber; }

// sets the makeAndModel public void setMakeAndModel(String makeAndModel) { this.makeAndModel = makeAndModel; }

// returns the makeAndModel public String getMakeAndModel() { return makeAndModel; }

// sets the state public void setState(String state) { this.state = state; }

Also here is the test file

public class AutoPolicyTest { public static void main(String[] args) {

// create two AutoPolicy objects AutoPolicy policy1 = new AutoPolicy(11111111, "Toyota Camry", "NJ"); AutoPolicy policy2 = new AutoPolicy(22222222, "Ford Fusion", "ME");

// display whether each policy is in a no-fault state policyInNoFaultState(policy1); policyInNoFaultState(policy2); }

// method that displays whether an AutoPolicy // is in a state with no-fault auto insurance

public static void policyInNoFaultState(AutoPolicy policy) { System.out.println("The auto policy:");

System.out.printf( "Account #: %d; Car: %s;%nState %s %s a no-fault state%n%n", policy.getAccountNumber(), policy.getMakeAndModel(), policy.getState(), (policy.isNoFaultState() ? "is": "is not")); } }

6.28 (Modified AutoPolicy Class) Modify class AutoPolicy in Fig. 6.11 to validate the two-letter state codes for the northeast states. The codes are: CT for Connecticut, MA for Massachusetts, ME for Maine, NH for New Hampshire, NJ for New Jersey, NY for New York, PA for Pennsylvania and VT for Vermont. In the State property's set accessor, use the logical OR (11) operator (Section 6.11.2) to create a compound condition in an if...else statement that compares the meth- od's argument with each two-letter code. If the code is incorrect, the else part of the if...else state- ment should display an error message. In later chapters, you'll learn how to use exception handling to indicate that a method received an invalid value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

Explain how to reward individual and team performance.

Answered: 1 week ago