Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:21:01+00:00 2026-06-05T02:21:01+00:00

i am writing a program in bluej which consists of several classes that get

  • 0

i am writing a program in bluej which consists of several classes that get user input and save them as String data. These Classes override each others methods and are meant to be displayed in a final class called CollegeList. However, for the class CollegeList i am not allowed in my assignment to extend these subclasses. Instead i am meant to use a bluej ‘uses relation’ and output these classes input and output in a for each loop. How can this be done? here is some of my code:

// College List
import java.util.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;


public class CollegeList 
{
    //Input Reader
    Scanner scanner = new  Scanner(System.in);
    private ArrayList<Person> people;

    //Main Public Method 
    public CollegeList()
    {
        people=new ArrayList<Person>();
    }    

    public void main()//not allowed to extend
    {
        dataEntry();    
    }

    public void getPeople(Person persons)
    {
        people.add(persons);
        System.out.println(people);;
    }

    //*** Attempting to output preceding class Person in loop - Must be done this way 
    public void dataEntry()
    {
        for(Person persons: people)
        {
            persons.dataEntry();
        }
    }
}

The Person class:

import java.util.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Person extends Student
{
    // instance variables for data types
    public ArrayList<String> firstName;
    public ArrayList<String> lastName;
    public ArrayList<String> streetAdress;
    public ArrayList<String> postCode;
    public ArrayList<String> phoneNumber;
    Scanner scanner = new Scanner(System.in); 

    /**
    * Constructor for objects personal details.
    */
    public Person()
    {
        firstName = new ArrayList<String>();
        lastName = new ArrayList <String>();
        streetAdress = new ArrayList<String>();
        postCode = new ArrayList<String>();
        phoneNumber = new ArrayList<String>();
    }    

    /**
    * Allows User to Enter Details into class Person and Displays it.
    */
    public void dataEntry ()
    {
        System.out.print("Enter First Name: ");
        firstName.add(scanner.nextLine()); 
        System.out.print("Enter Last Name: ");
        lastName.add(scanner.nextLine()); 
        System.out.print("Enter Street Adress: ");
        streetAdress.add(scanner.nextLine()); 
        System.out.print("Enter Post Code: ");
        postCode.add(scanner.nextLine()); 
        System.out.print("Enter Phone Number: ");
        phoneNumber.add(scanner.nextLine()); 
        //display persons information on single line
        System.out.println("The details are - " +
                            "Name: " +
                            firstName + "," +
                            "Surname: " +
                            lastName + "," +
                            "Street Adress: " +
                            streetAdress + "," +
                            "Post Code: " +
                            postCode + "," +
                            "Phone Number: " +
                            phoneNumber + "." );
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:21:03+00:00Added an answer on June 5, 2026 at 2:21 am

    From what I understood from your question is that you are asked to Use composition instead of inheritance.

    Additionally there are some basic things that you should correct:

    • Person class should not have List of firstName, lastName etc. It should rather have them as simple String and then you can create a List of Person as needed. You can then use for loop to iterate over this list as you want.

    • Person should not extend Student, as logically every person is not a student.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I'm writing a program that list the digits of integer input. example: Please enter
I have been writing a program which asks you to input two integers, which
Before writing this program,I thought that our is a package scope variable and my
I am writing a program that runs through pintools, to perform dynamic taint analysis
I'm writing a program that show the thread list of all opened process. With
I'm writing a program that will do image processing on a 16 bit tiff
I am writing a program and have some code inside a string. This code
I am writing a program that must register time of starting a process such
I'm writing a program which creates a large number of large arrays to store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.