Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to add to a new object called bk but my program does not read the users input after he uses a space
I am trying to add to a new object called bk but my program does not read the users input after he uses a space bar.
//Book Class package com.codewithEmmanuel; public class book { private int identificationNumber; private String title;String itemAvailable; private int no_of_available_copies; private String author; public book(int identificationNumber, String title, String itemAvailable, int no_of_available_copies, String author){ this.identificationNumber = identificationNumber; this.title = title; this.itemAvailable = itemAvailable; this.no_of_available_copies = no_of_available_copies; this.author = author; } public void setIdentificationNumber(int identificationNumber) { this.identificationNumber = identificationNumber; } public int getIdentificationNumber() { return identificationNumber; } public void setTitle(String title) { this.title = title; } public String getTitle() { return title; } public void setItemAvailable(String itemAvailable) { this.itemAvailable = itemAvailable; } public String getItemAvailable() { if (no_of_available_copies <= 0) { itemAvailable = "Not Available"; } else { itemAvailable = "Available"; } return itemAvailable; } public void setNo_of_available_copies(int no_of_available_copies) { this.no_of_available_copies = no_of_available_copies; } public int getNo_of_available_copies() { return no_of_available_copies; } public void setAuthor(String author) { this.author = author; } public String getAuthor() { return author; } @Override public String toString() { return "Identification Number:" + getIdentificationNumber() + ", Title:" + getTitle() + ", Item:"+getItemAvailable()+ ", No_of_available_copies:" + getNo_of_available_copies()+ ", Author:"+getAuthor(); } }
//Main class package com.codewithEmmanuel; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); ArrayListbk = new ArrayList (); System.out.println("Enter: Identification Number, Title, Item Available, Number of copies, Author"); //This is where I run into issues. Computer does not read inputs when the user uses the space bar bk.add(new book(input.nextInt(), input.next(), input.next(), input.nextInt(), input.next())); System.out.println(bk); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started