Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do part B and C in java, a paymentAmount that holds the amount paid paymentType (cash, creditcard) that holds the payment type. 2. Create

Please do part B and C in java,

a paymentAmount that holds the amount paid

paymentType (cash, creditcard) that holds the payment type.

2. Create a default constructor that set the paymentType to creditCard and amount to 0.

3. Create setter methods setType and setAmount.

4. Create 2 getter methods, getType and getAmount, to get the value of each of the instance variable.

5. Create a method total that uses 2 inputs bill1 and bill2. The method adds the absolute value of bill1 and the absolute value of bill2 to amount and return the sum as |bill1|+ |bill2|. Use math class for absolute value.

6. Create a to string for the payment class that display amount (2 decimal format) and type.

7. Create an equal method

Part C (0.4 points) Create a client class PostOffice. A client class includes the public void main method. program that tests your classes as follows:

  • Create a Package object p1 with the following data: Amy Johnson, Edward Johnes (TrackingID, sender, recipient respectively)
  • Call the setPackageInfo method to set p1s value to 75 and weight to 10
  • Display p1s details: tracking ID, sender, recipient, and cost
  • Create a Package overnightPackage with the following data: Mary Palmer, Dennis Garcia
  • Call the setPackageInfo method to set overnightPackages value to 100 and weight to 20.1
  • Call the shipmentCost method to get overnightPackages cost
  • Display overnightPackagess details: tracking ID, sender, recipient, and cost
  • Create a Package object insuredPackage with the following data: James Didier, Amy Bryan, 10, 200, true
  • Call the setPackageInfo function to set insuredPackages 100 and weight to 10
  • Display insuredPackages details: tracking ID, sender, recipient, and cost
  • Create a Payment payment3 for payment of insuredPackage, payment3 amount is the cost of the package and insurance, and is paid by a creditcard

This is the part A coding

class Package { static double costPerOz; static int tracker; int trackingID; String sender; String recipent; double weight; double value; boolean isInsured;

Package(boolean isInsured,String sender, String recipent) { this.isInsured=isInsured; this.sender=sender; this.recipent=recipent; this.trackingID=this.tracker; this.tracker++; }

Package(boolean isInsured,String sender, String recipent,double weight,double value) { this(isInsured,sender,recipent); this.weight=weight; this.value=value; }

public void setPackageInfo(double weigh,double value) { if(weigh>=0 && value>=0) { this.weight=weight; this.value=value; System.out.println("Package info set"); } else

System.out.println("Package info can't be set weight and value both should be non negative"); }

public void setWeight(double weight) { if(weight>=0) this.weight=weight; else System.out.println("Try again with positive weight"); } public void setValue(double value) { if(value>=0) this.value=value; else System.out.println("Try again with positive value"); } public void setSender(String sender) { if(sender!="") this.sender=sender; else System.out.println("Sender name cannot be empty"); } public void setRecipient(String recipent) { if(recipent!="") this.recipent=recipent; else System.out.println("Recipient name cannot be empty"); }

public String senderName() { return this.sender; } public String recipentName() { return this.recipent; } public int getTrackingID() { return this.trackingID; } public double getWeight() { return this.weight; } public double value() { return this.value; } public boolean isPackageInsured() { return this.isInsured; }

public String shippingLabel() { return this.trackingID+" "+this.sender+" "+this.recipent; }

public double ShipmentCost() { return this.weight*costPerOz; }

public double insuranceCost() { if(this.value<=1000) return 5.25; else if(this.value<=5000) return 7.5; else return 10; } }

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago