Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (20 points) The first problem includes the following: (a) Write a class encapsulating the concept of an address, called Address, having a streetAddress, city,
1. (20 points) The first problem includes the following: (a) Write a class encapsulating the concept of an address, called Address, having a streetAddress, city, state, and zip Code as string instance variables. The Address class contains a constructor that accepts parameters for initializing the object's instance variables, a toString() method for returning a string of formatted multiple lines of an address, and equals method that returns true if two Address objects are the same and false otherwise. Two addresses are considered equal if both has the same zip code. (b) Write a class encapsulating the concept of a package, called Package, which contains instance variables for TrackingID, Weight (in ounces), Cost, Discount, shipMethod, and Destination. shipMethod is a variable of an enumerated type called Shipping which defines the following constants for a shipping method {Air, Ground, Sea}. Destination is a reference to an object of the Address class. Discount is a boolean variable set to true if the package cost includes a discount as explained below and false otherwise. The Package class includes the following methods: A constructor that accepts arguments for the weight and shipping method. The constructor generates a random integer number of 6 digits as tracking ID, and calls a method called calculateCost() to determine the shipping cost. The calculateCost() method computes the cost of a package delivery based on the method of shipping. The shipping cost is determined based on the following table: . Weight (ounces) 1-8 9-16 17 and Air ($) 4.00 6.00 9.00 Ground ($) 1.80 2.80 4.00 Sea ($) 0.55 1.50 2.00 over However, all packages destined to the same address and using the same shipping method will get a 10% discount. Include accessesor and mutator methods for the Weight, shipMethod, and Destination instance variables. The mutator methods for the Weight and shipMethod should call the calculateCost() method in order to recalculate the package cost. Include a method, called applyDiscount(), for applying a discount of 10% on the cost of a package that has not been discounted before. toString() method that returns a nicely formatted string of the package information. (c) Write a program that allows the user to create any number of packages as needed. Each created Package is stored in a packageList as an ArralyList object of Package objects. The program should prompt the user for the required fields for the package weight, shipping method, and destination address. With each new entry of a package, the program should check the current list for whether the new package to be added is destined to the same address of an already existing one in the list. The program should apply a discount of 10%, if two or more packages are destined to the same place and using the same shipping method. Finally, the program should display the contents of the packageList object on the screen. For an example, see the dialogue shown at the end. 1. (20 points) The first problem includes the following: (a) Write a class encapsulating the concept of an address, called Address, having a streetAddress, city, state, and zip Code as string instance variables. The Address class contains a constructor that accepts parameters for initializing the object's instance variables, a toString() method for returning a string of formatted multiple lines of an address, and equals method that returns true if two Address objects are the same and false otherwise. Two addresses are considered equal if both has the same zip code. (b) Write a class encapsulating the concept of a package, called Package, which contains instance variables for TrackingID, Weight (in ounces), Cost, Discount, shipMethod, and Destination. shipMethod is a variable of an enumerated type called Shipping which defines the following constants for a shipping method {Air, Ground, Sea}. Destination is a reference to an object of the Address class. Discount is a boolean variable set to true if the package cost includes a discount as explained below and false otherwise. The Package class includes the following methods: A constructor that accepts arguments for the weight and shipping method. The constructor generates a random integer number of 6 digits as tracking ID, and calls a method called calculateCost() to determine the shipping cost. The calculateCost() method computes the cost of a package delivery based on the method of shipping. The shipping cost is determined based on the following table: . Weight (ounces) 1-8 9-16 17 and Air ($) 4.00 6.00 9.00 Ground ($) 1.80 2.80 4.00 Sea ($) 0.55 1.50 2.00 over However, all packages destined to the same address and using the same shipping method will get a 10% discount. Include accessesor and mutator methods for the Weight, shipMethod, and Destination instance variables. The mutator methods for the Weight and shipMethod should call the calculateCost() method in order to recalculate the package cost. Include a method, called applyDiscount(), for applying a discount of 10% on the cost of a package that has not been discounted before. toString() method that returns a nicely formatted string of the package information. (c) Write a program that allows the user to create any number of packages as needed. Each created Package is stored in a packageList as an ArralyList object of Package objects. The program should prompt the user for the required fields for the package weight, shipping method, and destination address. With each new entry of a package, the program should check the current list for whether the new package to be added is destined to the same address of an already existing one in the list. The program should apply a discount of 10%, if two or more packages are destined to the same place and using the same shipping method. Finally, the program should display the contents of the packageList object on the screen. For an example, see the dialogue shown at the end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started