Question

a. The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class...

a. The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class named PhoneCall that includes a String field for a phone number and a double field for the price of the call. Also include a constructor that requires a phone number parameter and that sets the price to 0.0. Include a set method for the price. Also include three abstract get methods - one that returns the phone number, another that returns the price of the call, and a third that displays information about the call. Create two child classes of PhoneCall: IncomingPhoneCall and OutgoingPhoneCall. The IncomingPhoneCall constructor passes its phone number parameter to its parent's constructor and sets the price of the call to 0.02. The method that displays the phone call information displays the phone number, the rate, and the price of the call (which is the same as the rate). The OutgoingPhoneCall class includes an additional field that holds the time of the call in minutes. The constructor requires both a phone number and the time. The price is 0.04 per minute, and the display method shows the details of the call, including the phone number, the rate per minute, the number of minutes, and the total price. Write an application that demonstrates you can instantiate and display both IncomingPhoneCall and OutgoingPhoneCall objects. Save the files as PhoneCall.java, IncomingPhoneCall.java, OutgoingPhoneCall.java, and DemoPhoneCalls.java.

b. Write an application in which you assign data to a mix of 10 IncomingPhoneCall and OutgoingPhoneCall objects into an array. Use a for loop to display the data. Save the file as PhoneCallArray.java.

Homework Answers

Answer #1

Hi,

Please see below the Java classes. Please comment for any queries/feedbacks.

Thanks,

Anita

PhoneCall.java


public abstract class PhoneCall {
   protected String phoneNumber;
   protected double price;
  
   //PhoneCall constructor
   public PhoneCall(String phoneNumber){
       this.phoneNumber = phoneNumber;
       this.price = 0.0;
         
      
   }

   //abstract methods
   public abstract String getPhoneNumber();

   public abstract double getPrice();
  
   public abstract void callInfo();

   //set method for price
   public void setPrice(double price) {
       this.price = price;
   }
  

}

IncomingPhoneCall.java


public class IncomingPhoneCall extends PhoneCall {
  
   //IncomingPhoneCall COnstructor
   public IncomingPhoneCall(String phoneNumber) {
       super(phoneNumber);
       setPrice(0.02);
   }

   public String getPhoneNumber() {
       return this.phoneNumber;
   }

   public double getPrice() {
       return this.price;
   }

   //Displaying the info of IncomingPhoneCall
   public void callInfo() {
       System.out.println("Phone Number : "+this.getPhoneNumber() +" Rate: "+this.getPrice()
                   +" Price: $"+this.getPrice());
   }

}

OutgoingPhoneCall.java


public class OutgoingPhoneCall extends PhoneCall {
  
   private int timeOfCall ;

   //Constructor for OutgoingPhoneCall
   public OutgoingPhoneCall(String phoneNumber,int timeOfCall) {
       super(phoneNumber);
       this.setPrice(0.04);
       this.setTimeOfCall(timeOfCall);
       }

   public String getPhoneNumber() {
       return this.phoneNumber;
   }

   public double getPrice() {
       return this.price;
   }

  
   public int getTimeOfCall() {
       return timeOfCall;
   }

   public void setTimeOfCall(int timeOfCall) {
       this.timeOfCall = timeOfCall;
   }
  
   //Displaying the info of OutgoingPhoneCall
       public void callInfo() {
           System.out.println("Phone Number : "+this.getPhoneNumber() +" Rate Per Minute: "+this.getPrice()
                   +" No of Minutes: "+this.getTimeOfCall()+ " Total Price: $"+this.getTimeOfCall()*this.getPrice());
       }


}

DemoPhoneCalls.java


public class DemoPhoneCalls {
   public static void main(String [] args){
      
       //Creating an IncomingPhoneCall and an OutgoingPhoneCall objects
       PhoneCall incoming = new IncomingPhoneCall("61677777");
       PhoneCall outgoing = new OutgoingPhoneCall("61888888", 10);
      
       //to display the info
       incoming.callInfo();
       outgoing.callInfo();
   }

}

Sample output:

Phone Number : 61677777 Rate: 0.02 Price: $0.02
Phone Number : 61888888 Rate Per Minute: 0.04 No of Minutes: 10 Total Price: $0.4

PhoneCallArray.java


public class PhoneCallArray {
  
   public static void main(String [] args){
       //PhoneCall Array of size 10
       PhoneCall [] phoneCallArr = new PhoneCall[10];
       //creating 5 IncomingPhoneCall objects
       IncomingPhoneCall incoming1 = new IncomingPhoneCall("611111111");
       IncomingPhoneCall incoming2 = new IncomingPhoneCall("612222222");
       IncomingPhoneCall incoming3 = new IncomingPhoneCall("613333333");
       IncomingPhoneCall incoming4 = new IncomingPhoneCall("613333333");
       IncomingPhoneCall incoming5 = new IncomingPhoneCall("615555555");
      
       //creating 5 OutgoingPhoneCall objects
       OutgoingPhoneCall outgoing1 = new OutgoingPhoneCall("611111111",13);
       OutgoingPhoneCall outgoing2 = new OutgoingPhoneCall("612222222",14);
       OutgoingPhoneCall outgoing3 = new OutgoingPhoneCall("613333333",15);
       OutgoingPhoneCall outgoing4 = new OutgoingPhoneCall("613333333",16);
       OutgoingPhoneCall outgoing5 = new OutgoingPhoneCall("615555555",17);
      
       //Adding data to the array- random order
       phoneCallArr[0] = incoming1;
       phoneCallArr[1] = outgoing2;
       phoneCallArr[2] = incoming3;
       phoneCallArr[3] = outgoing4;
       phoneCallArr[4] = incoming5;
       phoneCallArr[5] = outgoing1;
       phoneCallArr[6] = incoming2;
       phoneCallArr[7] = outgoing3;
       phoneCallArr[8] = incoming4;
       phoneCallArr[9] = outgoing5;
      
      
       //Displaying the data in a loop
      
       for(int i =0; i<phoneCallArr.length; i++){
           PhoneCall phonecallObj = phoneCallArr[i];
           phonecallObj.callInfo();
       }
      
   }

}

Sample output:

Phone Number : 611111111 Rate: 0.02 Price: $0.02
Phone Number : 612222222 Rate Per Minute: 0.04 No of Minutes: 14 Total Price: $0.56
Phone Number : 613333333 Rate: 0.02 Price: $0.02
Phone Number : 613333333 Rate Per Minute: 0.04 No of Minutes: 16 Total Price: $0.64
Phone Number : 615555555 Rate: 0.02 Price: $0.02
Phone Number : 611111111 Rate Per Minute: 0.04 No of Minutes: 13 Total Price: $0.52
Phone Number : 612222222 Rate: 0.02 Price: $0.02
Phone Number : 613333333 Rate Per Minute: 0.04 No of Minutes: 15 Total Price: $0.6
Phone Number : 613333333 Rate: 0.02 Price: $0.02
Phone Number : 615555555 Rate Per Minute: 0.04 No of Minutes: 17 Total Price: $0.68

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with a Program class and write the following two methods (headers provided) as described below: - A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT