Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This exercise has two classes. The first class is named ObjectsToArrayList . The second class is called just Objects . Your responsibility is to create

This exercise has two classes. The first class is named ObjectsToArrayList. The second class is called just Objects. Your responsibility is to create the Object class and become familiar with how the ObjectsToArrayList class works. Requirements for the Object Class. 2 data fields: int obj_id, String obj_name. 2 Constructors: No-Arg and one that takes both values and assigns them to the data field. Gets and sets for both data fields A toString() method that returns output like: The object ID is 22 and the name is Andrea The ObjectsToArraylist class will create an ArrayList of objects. It will ask for and populate the data fields of an Object, then add it to the ArrayList. This can be done for as many instances of the Object that the user wants to enter. Again, this code is already supplied. Example Output The object ID is 22 and the name is Andrea The object ID is 45 and the name is Rabini The object ID is 21 and the name is Anderson The object ID is 56 and the name is Thomas

What I have so far:

import java.util.*; /** * * @author Student */ public class ObjectsToArrayList {

public static void main(String[] args) { Scanner input = new Scanner(System.in); ArrayList objectList = new ArrayList(); System.out.println("Please enter information for your favorite object!"); do { // collect an indicator to determine the method to call Object object = new Object(); System.out.println("Enter a whole number for the ID of your object: " + "or enter 99 to quit."); int tmpInt = input.nextInt(); // if 99 is entered exit the loop. if (tmpInt == 99) { break; } object.setObj_id(tmpInt); input.nextLine(); // ask for the Object Name System.out.println("Please enter the name of the Object:"); object.setObj_name(input.nextLine()); objectList.add(object);

} while (true); // this is a contineous loop if the break isn't included. for(Object object:objectList) { System.out.println(object.toString()); } } }

//**************************************************** //**** Objects Class is below this block ** //****************************************************

class Object {

// enter object code here }

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_2

Step: 3

blur-text-image_3

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

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago