Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) Design a class named PhoneCall with four field%u2019s: two strings that hold

ID: 3536652 • Letter: A

Question

a) Design a class named PhoneCall with four

field%u2019s: two strings that hold the 10 digit phone numbers

that originated and received the call, and two numeric fields that

hold the length of the call in minutes and the cost of the call.

Include a constructor that sets the phone numbers to Xs and

the numeric fields to 0. Include get and set methods for the phone

number and call length fields, but do not include a set methods for

the phone number and call length fields, but do the cost of the

call at three cents per minute for the first 10 minutes, and two

center per subsequent minute. Create the class diagram and

write the pseudocode that defines the class.


b) Design an application that declares three

PhoneCalls. Set the length of one PhoneCall to 10 minutes, another

to 11 minutes, and allow the third object to use the defaut value

supplied by the constructor. Then, display each PhoneCall's

value.


c) Create a child class named

InternationalPhoneCall. Overried the parent class method that sets

the call length to calculate the cost of the call at 40 cents per

minute.


d) Crete the logic for an application that

instantiates a PhoneCall object and an InternationalPhoneCall

object and displays the cost for both.

I only need C and D


Here is the answers for Part A and part B, I just need part C and D (*********** I NEED A Pseudocode********)



A...




B...


start

Declarations

PhoneCall

callOne

PhoneCall callTwo

PhoneCall callThree

callOne.setLength(10)

callTwo.setLength(11)

output

%u201C

PhoneCall

1 info:%u201D

output

%u201COriginating number = %u201D,

callOne.getOrigCall()

output

%u201CReceiving number = %u201D, callOne.getRecCall()

output

%u201CCall length = %u201D, callOne.getLength()

output %u201CCall cost = %u201D, callOne.getCost()

output

%u201C

PhoneCall

2

info:%u201D

output

%u201COriginating number = %u201D, callTwo.getOrigCall()

output

%u201CReceiving number = %u201D, callTwo.getRecCall()

output

%u201CCall length = %u201D, callTwo.getLength()

output %u201CCall cost = %u201D, callTwo.getCost()

output

%u201C

PhoneCall

3

info:%u201D

output

%u201COriginating number = %u201D,



Explanation / Answer

import java.math.BigDecimal;

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

PhoneCall call = new PhoneCall("123456");
call.setReceivedNumber("654321");
call.setDurationInMinute(1);
System.out.println(call);

call.setReceivedNumber("987654");
call.setDurationInMinute(10);
System.out.println(call);

call.setReceivedNumber("987654");
call.setDurationInMinute(11);
System.out.println(call);

System.exit(0);
}
}

class PhoneCall {
private String originatedNumber;
private String receivedNumber;
private int durationInMinute;
private BigDecimal cost;

public PhoneCall(String originatedNumber) {
this.originatedNumber = originatedNumber;
this.durationInMinute = 0;
this.cost = BigDecimal.ZERO;
}

public BigDecimal getCost() {
double result = 0;

if (durationInMinute > 10) {
cost = new BigDecimal(10 * 0.3);
cost = new BigDecimal((durationInMinute - 10) * 0.2 + cost.doubleValue());
} else {
cost = new BigDecimal(durationInMinute * 0.3);
}

return cost.setScale(2, BigDecimal.ROUND_HALF_UP);
}

public int getDurationInMinute() {
return durationInMinute;
}

public void setDurationInMinute(int durationInMinute) {
this.durationInMinute = durationInMinute;
}

public String getReceivedNumber() {
return receivedNumber;
}

public void setReceivedNumber(String receivedNumber) {
this.receivedNumber = receivedNumber;
}

@Override
public String toString() {
String message = "From: %s, To: %s, Duration: %d, Cost: %.2f";
return String.format(message, this.originatedNumber, getReceivedNumber(), getDurationInMinute(), getCost());
}