jeudi 7 octobre 2021

Code within my if-statement isn't getting run [closed]

I'm trying to make a program that asks for user input, applies it to an object, and adds it to a list but all of my code within the if-statement isn't being run. I can't tell why, it's formatted the same as other if-statements I've written that do work so I'm at a loss. I'm new at java and only started playing around with arrays, lists, and array lists for this project so I don't know if the problem is with that or not.

import java.util.Scanner;

import java.util.ArrayList;

import java.util.Iterator;

public class MyBusiness {

   public static void main(String[] args) {

ArrayList<Book> bookList = new ArrayList<Book>(); 

    Scanner input = new Scanner(System.in);

System.out.println("Choose what you would like to do:");
System.out.println("1. Add book");

int x = input.nextInt();

if(input.equals(1)) {

Book b1 = new Book();
  System.out.println("Title - ");
    b1.setTitle(input.next());
  System.out.println("Author - ");
    b1.setAuthor(input.next());
  System.out.println("Quantity - ");
    b1.setQty(input.nextInt());
  System.out.println("Price - ");
    b1.setPrice(input.nextDouble());
  System.out.println("Made of kids - ");
    b1.setKids(input.nextBoolean());
  System.out.println("Genre - ");
    b1.setGenre(input.next());
  System.out.println("Fiction - ");
    b1.setIsFiction(input.nextBoolean());
        bookList.add(b1);   
  
     }


 
    }




   }

Aucun commentaire:

Enregistrer un commentaire