I need help with school stuff

I am in 9th grade and this is my last day to turn things in. and I can’t figure this one out if I run the code below with out inputs it is find but if it has inputs it has a pissy fit
here are the instructing

and here is my code (it’s java btw);

import java.util.Scanner;
public class Main {

public static void main(String[] args) {


    Scanner input = new Scanner(System.in);
    String dummy;
    dummy = input.nextLine();//creating the objects

    int one = input.nextInt();
    int two = input.nextInt();
    int three = input.nextInt();
    int newfour = input.nextInt();
    String booktitle = input.nextLine();
    String aother = input.nextLine();
    int nextpags = input.nextInt();
    String booktitle2 = input.nextLine();
    String aother2 = input.nextLine();
    int nextpages2= input.nextInt();
    int nextpags3 = input.nextInt();
    String booktitle3 = input.nextLine();
    String aother3 = input.nextLine();
    int nextpags4 = input.nextInt();
    String booktitle4 = input.nextLine();
    String aother4 = input.nextLine();
    books book2 = new books();
    books book1 = new books();
    books book3 = new books();
    books book4 = new books();
    int bookratingforpoetry;
    bookratingforpoetry= one;
    book2.rating = bookratingforpoetry;
    book2.book_title = booktitle;
    book2.Author= aother;
    book2.Number_of_pages = nextpags;
    int bookratingforsomethiong_randome;
    bookratingforsomethiong_randome=input.nextInt();
    book1.rating = two;
    book1.book_title =booktitle2;
    book1.Author =aother2;
    book1.Number_of_pages = nextpages2;
    int book3_rating;
    book3_rating=input.nextInt();
    book3.rating = three;
    book3.book_title = booktitle3;
    book3.Author = aother3;
    book3.Number_of_pages = nextpags3;
    int book4_rating;
    book4_rating=input.nextInt();
    book4.rating = newfour;
    book4.book_title=booktitle4;
    book4.Author = aother4;
    book4.Number_of_pages = nextpages2;
    //printing out the books
    System.out.println("Book Title:    "+book1.book_title);
    System.out.println("    Author:    "+book1.Author);
    System.out.println("     Pages:    "+book1.Number_of_pages);
    System.out.println("    Rating:    "+book1.rating);
    System.out.println("Book Title:    "+book2.book_title);
    System.out.println("    Author:    "+book2.Author);
    System.out.println("     Pages:    "+book2.Number_of_pages);
    System.out.println("    Rating:    "+book2.rating);
    System.out.println("Book Title:    "+book3.book_title);
    System.out.println("    Author:    "+book3.Author);
    System.out.println("     Pages:    "+book3.Number_of_pages);
    System.out.println("    Rating:    "+book3.rating);
    System.out.println("Book Title:    "+book4.book_title);
    System.out.println("    Author:    "+book4.Author);
    System.out.println("     Pages:    "+book4.Number_of_pages);
    System.out.println("    Rating:    "+book4.rating);
    //printing out the sintences
    int allpages = book1.Number_of_pages+book2.Number_of_pages+book3.Number_of_pages+ book4.Number_of_pages;
    System.out.println("The total number of pages of all the books is "+allpages+" pages.");
    int title_amounts = book1.book_title.length() + book2.book_title.length()+book3.book_title.length()+book4.book_title.length();
    System.out.println("The total number of characters in all the book titles is "+title_amounts+" characters.");
    String that_author_string =book1.Author.substring(0,1)+book2.Author.substring(0,1)+book3.Author.substring(0,1)+book4.Author.substring(0,1);
    System.out.println("The lowercased first initial of each author's name in a single string is "+that_author_string+".");
    int average_almoust = book1.rating+book2.rating+book3.rating+book4.rating ;
    int four = 4;
    int average = average_almoust / four;
    System.out.println("The average rating of all listed books is "+ average+" stars.");











}

}
class books{//book class
int rating;
String Author;
int Number_of_pages;
String book_title;
}

Ok, so what this assignment tells you to do, is to create a parser using a Scanner object.

I would suggest either using a debugger here, or better yet, print each variable as you read them.

Think of the parser as something that reads a loooooooooooooooooooooong text string. Input will return a portion of that string. Each time you use input, print the variable and compare to the expected value.

I have not looked through your code too much just yet, but pro formatting tip -

Three of the “`” symbol above and below your code pre-formats it.

So this:

```
echo "Hello World!";
```

Turns into:

echo "Hello World!";

thank you that was help full

1 Like