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 8714823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:41:35+00:00 2026-06-13T05:41:35+00:00

I have two of the following java classes (listed below) Class BookInfo declares static

  • 0

I have two of the following java classes (listed below) Class BookInfo declares static block of arrays

     public class BookInfo {

    // Global arrays accessible by all methods

    public static String[] isbnInfo;
    public static String[] bookTitleInfo;
    public static String[] authorInfo;
    public static String[] publisherInfo;
    public static String[] dateAddedInfo;;
    public static int[] qtyOnHandInfo;
    public static double[] wholesaleInfo;
    public static double[] retailInfo;

    static {

        isbnInfo = new String[] {

                                "978-0060014018",
                                "978-0449221431",
                                "978-0545132060",
                                "978-0312474881",
                                "978-0547745527"

                                };

        bookTitleInfo = new String[] {

                                "The Greatest Stories",
                                "The Novel",
                                "Smile",
                                "The Bedford Introduction to Drama",
                                "AWOL on the Appalachian Trail"

                                };

        authorInfo = new String[]  {

                                 "Rick Beyer",
                                 "James A. Michener",
                                 "Raina Telgemeier",
                                 "Lee A. Jacobus",
                                 "David Miller"

                                };

        publisherInfo = new String[] {

                                "HerperResource",
                                "Fawcett",
                                "Graphix",
                                "Bedford St. Martins",
                                "Mariner Books"

                                };

        dateAddedInfo = new String[] {

            "05/18/2003", 
            "07/07/1992", 
            "02/01/2010", 
            "09/05/2008", 
            "11/01/2011"

            };

        qtyOnHandInfo = new int[] {7, 5, 10, 2, 8};

        wholesaleInfo = new double[] {12.91, 7.99, 6.09, 54.99, 10.17};

        retailInfo = new double[] {18.99, 3.84, 4.90, 88.30, 14.95};

    }

    public static void BookInfo() {

        System.out.println("             Serendipity Booksellers");
        System.out.println("                Book Information\n");       


        for(int i = 0; i < isbnInfo.length; i++){

            System.out.println("ISBN: " + isbnInfo[i]);
            System.out.println("Title: " + bookTitleInfo[i]);
            System.out.println("Author: " + authorInfo[i]);
            System.out.println("Publisher: " + publisherInfo[i]);
            System.out.println("Date Added: " + dateAddedInfo[i]);
            System.out.println("Quantity-On-Hand: " + qtyOnHandInfo[i]);
            System.out.println("Wholesale Cost: $ " + wholesaleInfo[i]);
            System.out.println("Retail Price: $ " + retailInfo[i]);
            System.out.println();

        }
    }
    }

How do I access array list from this class? Only the following is working so far but how do I modify (add, delete, edit, etc) from this class (there is no main main in this class) BookInfo bookinfo = new BookInfo(); bookinfo.BookInfo(); System.out.println(bookinfo.isbnInfo[0]); how do I modify (add, delete, edit, etc) from the main menu

    import java.util.Scanner;

     public class InvMenu {
     public static void addBook(){

      System.out.println("\nYou selected Add a Book\n");
       BookInfo bookinfo = new BookInfo();
      bookinfo.BookInfo(); // only these two are working but I cannot modify arrays at all
      System.out.println(bookinfo.isbnInfo[0]);

        }

       public static void editBook(){

     System.out.println("\nYou selected Edit a Book's Record\n"); 

     }

     public static void deleteBook(){

      System.out.println("\nYou selected Delete a Book\n");

    }

    public static void printInvMenu(){

    String choice;
    int x = 0;
    boolean b;
    char letter;
    boolean menu = true;

    Scanner keyboard = new Scanner(System.in);

    System.out.println("Serendipity Booksellers");
    System.out.println("Inventory Database\n");
    System.out.println("       1. Look Up a Book");
    System.out.println("       2. Add a Book");
    System.out.println("       3. Edit a Book's Record");
    System.out.println("       4. Delete a Book");
    System.out.println("       5. Return to the Main Menu\n");

    do{

    System.out.print("Enter your choice: ");
    choice = keyboard.nextLine();
    b = true;

    try {
        x = Integer.parseInt(choice);
        System.out.println(x);

    }

    catch(NumberFormatException nFE) {

        b = false;
        System.out.println("You did not enter a valid choice. Try again!\n");

    }

       }while(b == false);

    do{

    else if(x == 1){

        addBook();

    }

    else if(x == 2){

        editBook();

    }

    else if(x == 3){

        deleteBook();

    }

    else if(x == 4){

        System.out.println("Returning to the Main Menu\n");
        break;

    }

    else{

        System.out.println("\nYou did not enter a valid choice. Try again!\n");

    }

     printInvMenu();

    }while(x == 5);

      }
     }

I can easily access some of the functionality from the other class main menu: BookInfo bookinfo = new BookInfo(); bookinfo.BookInfo(); System.out.println(bookinfo.isbnInfo[0]); How do I modify (add, delete, edit, etc) from the main menu? Any ideas, suggestions are greatly appreciated!

  • 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-13T05:41:37+00:00Added an answer on June 13, 2026 at 5:41 am

    You simply can not “add” a new element to an Array after you have created it. From oracle tutorials page:

    An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

    Thus, if you want to add and remove elements from a List I recommend you to use an ArrayList object, which can be defined as a

    Resizable-array implementation of the List interface.

    You could for example replace your line of code

    private static String[] isbnInfo;
    

    for

    private static ArrayList<String> isbnInfo;
    

    and initialize it like:

    isbnInfo = new ArrayList<String>()
    isbnInfo.add("978-0060014018");
    isbnInfo.add("978-0449221431");
    isbnInfo.add("978-0545132060");
    isbnInfo.add("978-0547745527");
    

    As for edit your array, you can simply add some public getters for your private fields

    public static String[] getIsbnInfo()
    {
       return isbnInfo;
    }
    

    and in your public class:

    String[] isbnInfo = BookInfo.getIsbnInfo();
    

    You can also use a public method to edit your arrays, like:

    public static void replaceIsbnInfo(int index, String isbn)
    {
       isbnInfo[index] = isbn;
    }
    

    And in your menu class

    BookInfo.replaceIsbnInfo(1, "978-0547745527");
    

    I hope it helped. Cheers!

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

Sidebar

Related Questions

I have the following two classes: import java.io.*; import java.util.*; public class User {
Let's say I have the following two classes: package example.model; public class Model {
Consider that I have the two following nested classes: public class Foo { public
I have the following issue: A java object contains two arrays of core datastore
I have the following two classes: class Key<T1, T2> {} class Pair<F, S> {}
I have the following scenario (in Java / Hibernate): I have two entity classes:
I have two classes: public class CourseModule { // attributes... List<Course> courses; public void
I have two domain classes: class A { int id static hasMany = [bs:
I have below this two classes .. class Emp //implements Comparable { String name,job;
I have following two arrays. I want the difference between these two arrays. That

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.