Question

Design MyWeek class: (1) Data members: the class contains one private data field weekList. weekList has datatype of Array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, here is the complete class in Java

==============================================================
import java.util.ArrayList;

public class MyWeek {

    private ArrayList<String> weekList;

    public MyWeek() {
        weekList = new ArrayList<>();

    }

    public MyWeek(String weekName) {
        if (weekName == null) {
            throw new IllegalArgumentException();
        }
        weekList = new ArrayList<>();
        weekList.add(weekName);
    }

    public MyWeek(ArrayList<String> weeks) {
        if (weeks == null) {
            throw new IllegalArgumentException();
        }
        weekList = new ArrayList<>();
        for (String name : weeks) {
            if (weekList.contains(name)) {
                continue;
            } else {
                weekList.add(name);
            }
        }
    }

    public void insert(String week) {
        weekList.add(week);
    }

    public void insert(ArrayList<String> weeks) {
        if (weeks == null) {
            throw new IllegalArgumentException();
        }
        for (String week : weeks) {
            if (weekList.contains(week)) {
                continue;
            } else {
                weekList.add(week);
            }
        }
    }

    public boolean search(String week) {
        if (week == null) {
            throw new IllegalArgumentException();
        }
        for (String weekName : weekList) {
            if (weekName.equalsIgnoreCase(week)) {
                return true;
            }
        }
        return false;
    }

    public void delete(String name) {
        if (name == null) {
            throw new IllegalArgumentException();
        }
        if (weekList.contains(name)) {
            weekList.remove(name);


        }
    }

    public void delete(ArrayList<String> names) {
        if (names == null) {
            throw new IllegalArgumentException();
        }
        for (String name : names) {
            if (weekList.contains(name)) {
                weekList.remove(name);
            }
        }
    }

    @Override
    public String toString() {
        return weekList.toString();
    }

    @Override
    public boolean equals(Object obj) {

        if (obj != null && obj instanceof MyWeek) {

            MyWeek anotherWeek = (MyWeek) obj;
            if (anotherWeek.weekList.size() != weekList.size()) {
                return false;
            }
            return weekList.containsAll(anotherWeek.weekList);

        }
        return false;
    }

}
Add a comment
Know the answer?
Add Answer to:
Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "wee...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Overloading Design a UML diagram for a TimeClock class with the following private data members: •...

    Overloading Design a UML diagram for a TimeClock class with the following private data members: • float days • float hours The class should also have the following public member methods: • Constructor with a default that sets the data values to 0 • getDays to return the private data member days • getHours to return the private data member hours • setDays to set the private data member days • setHours to set the private data member hours •...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

  • Create a class called CarNode which has fields for the data (a Car) and next (CarNode)...

    Create a class called CarNode which has fields for the data (a Car) and next (CarNode) instance variables. Include a one-argument constructor which takes a Car as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CarNode (Car c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CarList. This should be a...

  • You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must c...

    You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...

  • Write a class that analyzes data you have stored in a text file. Your data represents...

    Write a class that analyzes data you have stored in a text file. Your data represents the ages of the individuals in your fictitious community. The data is stored, one per line, in a text file. For example, File name: myData.txt Contents: 45 18 6.5 3 5 sdtypo# 18 10 The number of lines in your text file must fall somewhere between 20 and 100 lines. Some of the lines must hold character strings that are not convertible to integers,...

  • Language: C++ (Please show output) Part 1 - LIST Create an unsorted LIST class. Each list...

    Language: C++ (Please show output) Part 1 - LIST Create an unsorted LIST class. Each list should be able to store 100 names. Part 2 - Create a Class ArrayListClass It will contain an array of 27 "list" classes. Next, create a Class in which is composed a array of 27 list classes. Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name. Again - ignore index 0. index 1 is names starting with A, index...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

  • Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the followi...

    Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the following classes Node.java: This class represents a vertex in the graph. It has only a single instance variable of type int which is set in the constructor. Implement hashCode() and equals(..) methods which are both based on the number instance variable Node - int number +Node(int number); +int getNumberO; +int hashCode() +boolean equals(Object o) +String toString0) Edge.java: This class represents a...

  • PART B: DATE BOOK A classic computer application is the electronic date book: a list of...

    PART B: DATE BOOK A classic computer application is the electronic date book: a list of daily events stored in a calendar. Write a Java program that can be used as a simple date book. The date book will use a separate array for each month of the year, with one array entry for each day in the month (0 = first day of the month, 1 = second day of the month, etc.). The date book is "simple" because...

  • An array of class objects is similar to an array of some other data type. To...

    An array of class objects is similar to an array of some other data type. To create an array of Points, we write Point parray [4]; To access the object at position i of the array, we write parray [i] and to call a method on that object method, we write parray [i]. methodName (arg1 , arg2 , ...) ; To initialize an array of objects whose values are known at compile time, we can write Point parray [4] =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT