📝 Homework Hack: Phone Class

Create a Phone class that demonstrates all concepts from this lesson:

  • Libraries/Classes
  • Packages (use ArrayList from java.util)
  • Attributes
  • Behaviors

Requirements:

Attributes (4):

  • brand (String)
  • model (String)
  • batteryLevel (int) - starts at 100
  • contacts (ArrayList)

Behaviors (5 methods):

  1. Constructor - sets brand and model, initializes empty contacts list
  2. displayInfo() - prints brand, model, and battery level
  3. addContact(String name) - adds name to contacts list
  4. showContacts() - prints all contacts
  5. usePhone(int minutes) - decreases battery by minutes used

Testing:

  • Create 2 Phone objects
  • Add 3 contacts to each phone
  • Use phone for some minutes
  • Display all information

Grading:

  • Correct attributes (4 points)
  • Correct methods (5 points)
  • Proper use of ArrayList from java.util (3 points)
  • Complete testing (3 points)
  • Total: 15 points
// Homework Hack: Complete the Phone class

import java.util.ArrayList;

public class Phone {
    // TODO: Add 4 attributes
    
    // TODO: Add constructor
    
    // TODO: Add displayInfo() method
    
    // TODO: Add addContact(String name) method
    
    // TODO: Add showContacts() method
    
    // TODO: Add usePhone(int minutes) method
    
}

// Test your Phone class
public class PhoneTest {
    public static void main(String[] args) {
        // TODO: Create 2 Phone objects
        
        // TODO: Add 3 contacts to each
        
        // TODO: Use phones for some minutes
        
        // TODO: Display all information
        
    }
}

// PhoneTest.main(null);