Hello, I would like some help with ending a program. I am working on some homework for writing code and everything I try will not allow me to end the program. I keep getting a syntax error "expected "}"" and I can not figure it out. I have checked for the brackets and they are both there, if I remove them it still says the same thing. Could some one please advise? Here is the end portion of my code:

{
System.exit(0);
}
}
}
} //end program

Thank you!

We would need more than the end portion. The problem is, you have an open { without a closing }. Double check all your braces and make sure that for every { there is a corresponding } .

Sorry, I am new at this and quite frankly, Java programming is not my bailiwick. Here is the program I have written and have been working on for several weeks for my IT class. Any help would be appreciated, several portions are not working, but right now the ending is frustrating me more as there is no information on how to do this. Thank you!

/*
 * Inventory.java
 *
 * Created on September 30, 2007, 3:34 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package inventory;
/**
 *
 * @author xxxxxxxxxxx (left intentionally blank)
 */
import java.util.Scanner;

class Inventory {

    private String NameOfItem;

    private int NameOfItems;

    /** Creates a new instance of Inventory */
    public Inventory() {
        String inventoryName = null;
        int items = 0;

    }
    public String getNameOfItem() {
        return this.getNameOfItem();
    }
    public int items() {
        return this.items();
    }
    public void setNameOfItem(String name) {
        this.NameOfItem = name;
    }
    public void setNameOfItem(int item) {
        this.NameOfItem = NameOfItem;
    }
} // End Inventory class class

/*
 * DVD.java
 *
 * Created on September 30, 2007, 3:34 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
class DVD {

    /** Creates a new instance of Inventory */
    public DVD() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Inventory Set[] = new Inventory[4];  // I am using array

        Set[0] = new Inventory();
        Set[0].setNameOfItem("Breakdown Palace");
        Set[0].getNameOfItem();
        inventory.add(dvd);

        Set[1] = new Inventory();
        Set[1].setNameOfItem("The Incredibles");
        Set[1].getNameOfItem();
        inventory.add(dvd);

        Set[2] = new Inventory();
        Set[2].setNameOfItem("Click");
        Set[2].getNameOfItem();
        inventory.add(dvd);

        Set[3] = new Inventory();
        Set[3].setNameOfItem("The Man");
        Set[3].getNameOfItem();
        inventory.add(dvd);

        Set[4] = new Inventory();
        Set[4].setNameOfItem("Christmas with the Kranks");
        Set[4].getNameOfItem();
        inventory.add(dvd);

        Set[5] = new Inventory();
        Set[5].setNameOfItem("Roll Bounce");
        Set[5].getNameOfItem();
        inventory.add(dvd);

        Set[6] = new Inventory();
        Set[6].setNameOfItem("American Outlaws");
        Set[6].getNameOfItem();
        inventory.add(dvd);
    }
    }// End DVD class class
/**** This is a subclass that adds 5% restocking fee and new feature genres***/

class FeatDVD extends DVD
{
     private String genres;

     // class constructor       
     FeatDVD(int item, String title, int stock, double price, String genres)
     {
          super(item, title, stock, price);
          this.genres = genres;
     }
     public String getGenres()
     {
          return genres;
     }

     public double getValue()
     {// getvalue method overrides
      // getvalue method in the superclass
          double value = 1.05F * super.getValue();
          return value;
     }// end getValue method

     public String toString()
     {//toString method overrides the superclass toString method
      //adding another fields
         return super.toString() + "Genre:" + genres;   
     }// end toString method

} // end class FeatDVD

/*****class has inventory of DVDs.
* This class has methods to add and display dvds****/


class Inventory {
}  
    /** Creates a new instance of Inventory */
    public Inventory() {
    }

    /**
     * @param args the command line arguments
     */
    {
    private DVD_name[];
    private number;
    private String name;

    }
    //Constructor to store data
    public Inventory(String DVD_name, number, DVD_price) 
    {
        String name = DVD_name;
        stock = DVD_number;
        cost = DVD_price;
    }//Constructor end

    //main method begins execution of Java application

    public static void main(String[] args) {
        // TODO code application logic here

        boolean stop = false; //controls if loop below executed while (!stop)
        {
            // create Scanner to obtain input from command window
            Scanner input = new Scanner(System.in);

            System.out.println("Welcome to DVD World");

            System.out.print("Enter DVD name or stop to quit: ");// prompt
            String DVD_name = input.nextLine(); // read DVD name entered

            if (DVDname.equals("stop")) // check for sentinal
            {
                System.out.println("Thank you, this program has ended.");
                stop = true;
            } else {
                float DVD_number;// First number
                float DVD_price;// Second number multiplied
                float total;// Total of DVD_number*DVD_price

                System.out.print("Enter the number of DVD:");// prompt
                DVD_number = input.nextFloat();// read number of DVDs
                while (DVD_number <= 0)// Validate for positive number
                {
                    System.out.println();// Enter blank line
                    System.out.println("Please enter the number of DVDs again:");
                    DVD_number = input.nextFloat();// read number of DVDs
                    System.out.println();// Enter blank line
                }
                System.out.print("Enter the amount of the DVDs:");// prompt
                DVD_price = input.nextFloat();// read price of DVD
                while (DVD_price <= 0)// validate for positive number
                {
                    System.out.println();// Enter a blank line
                    System.out.println("DVD_number must be a positive number. No negative numbers allowed.");
                    System.out.print("Please enter the number of DVDs again:");
                    DVD_price = input.nextFloat(); //read price of DVD
                    System.out.println();// Enter a blank line
                }
                total = (float) DVD_number * DVD_price; // Multiply DVD_price by number of DVD_number
                System.out.println();//Enter blank line
                System.out.println("DVD_name:"); //display name
                System.out.println("Number of DVDs" + DVD_number);//display number of DVDs
                System.out.printf("DVD_price: $%,.2f\n", total);//display total
                System.out.println();//Enter's blank line
                System.out.println();//Enter's blank line
            }// end else
        }// end while
    }//end main
}// end program

Well, if you don't start your while loop within a comment, it will probably exit as you expect.

boolean stop = false; //controls if loop below executed [B]while (!stop)[/B]
        {

I'm sorry, but, if you're not even willing to try, why should I. I gave you what you need to fix yourproblem, regardless of whether or not "Java is your bailiwick". And, if you're opening and closing braces in comments, it's not surprising it doesn't work.

I'm sorry, but, if you're not even willing to try, why should I. I gave you what you need to fix yourproblem, regardless of whether or not "Java is your bailiwick". And, if you're opening and closing braces in comments, it's not surprising it doesn't work.

Not willing to try? I am trying and have been for almost 9 weeks! You asked me for more than just the end and that is what I included. You seem to forget that not everyone is a programmer and that some of us are TRYING to learn, we won't get it immediately. I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.

if you are trying to exit the program if a condition is met if

stop == false
boolean stop = false; //controls if loop below executed while (!stop)

have you try an if statement to check for that condition that will make the program abort
while ( ...... )

{
if(condition to abort)
break;
else
code of the program
}

at least that is what i usually do to abort a program or if you want to check for that condition as soon as the program starts just put the while loop in the else

commented: post #4 already says this! -2
Member Avatar for iamthwee

I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.

I doubt this, since every { must have a matching } . In your program this ain't true. So quit moaning and fix it honey.

import java.util.Scanner;

class Inventory
{
  private String NameOfItem;
  private int NameOfItems; 

  public Inventory()
  {
    String inventoryName = null;
    int items = 0;
  }
  public String getNameOfItem()
  {
    return this.getNameOfItem();
  }
  public int items()
  {
    return this.items();
  }
  public void setNameOfItem ( String name )
  {
    this.NameOfItem = name;
  }
  public void setNameOfItem ( int item )
  {
    this.NameOfItem = NameOfItem;
  }
} 

class DVD
{ 
  public DVD()
  {} 

  public static void main ( String[] args )
  {
    Inventory Set[] = new Inventory[4];

    Set[0] = new Inventory();
    Set[0].setNameOfItem ( "Breakdown Palace" );
    Set[0].getNameOfItem();
    inventory.add ( dvd );

    Set[1] = new Inventory();
    Set[1].setNameOfItem ( "The Incredibles" );
    Set[1].getNameOfItem();
    inventory.add ( dvd );

    Set[2] = new Inventory();
    Set[2].setNameOfItem ( "Click" );
    Set[2].getNameOfItem();
    inventory.add ( dvd );

    Set[3] = new Inventory();
    Set[3].setNameOfItem ( "The Man" );
    Set[3].getNameOfItem();
    inventory.add ( dvd );

    Set[4] = new Inventory();
    Set[4].setNameOfItem ( "Christmas with the Kranks" );
    Set[4].getNameOfItem();
    inventory.add ( dvd );

    Set[5] = new Inventory();
    Set[5].setNameOfItem ( "Roll Bounce" );
    Set[5].getNameOfItem();
    inventory.add ( dvd );

    Set[6] = new Inventory();
    Set[6].setNameOfItem ( "American Outlaws" );
    Set[6].getNameOfItem();
    inventory.add ( dvd );
  }
} 

class FeatDVD extends DVD
{
  private String genres; 
  FeatDVD ( int item, String title, int stock, double price, String genres )
  {
    super ( item, title, stock, price );
    this.genres = genres;
  }
  public String getGenres()
  {
    return genres;
  }

  public double getValue()
  {
    double value = 1.05F * super.getValue();
    return value;
  }

  public String toString()
  {
    return super.toString() + "Genre:" + genres;
  }
} 


class Inventory
{

} 
public Inventory()
{

} 

{
  private DVD_name[];
  private number;
  private String name;

} 
public Inventory ( String DVD_name, number, DVD_price )
{
  String name = DVD_name;
  stock = DVD_number;
  cost = DVD_price;
} 
// <--wtf is this all doing? Consider rewriting this

public static void main ( String[] args )
{ 
  boolean stop = false;
  {
    Scanner input = new Scanner ( System.in );

    System.out.println ( "Welcome to DVD World" );

    System.out.print ( "Enter DVD name or stop to quit: " );
    String DVD_name = input.nextLine();

    if ( DVDname.equals ( "stop" ) )
    {
      System.out.println ( "Thank you, this program has ended." );
      stop = true;
    }
    else
    {
      float DVD_number;
      float DVD_price;
      float total;

      System.out.print ( "Enter the number of DVD:" );
      DVD_number = input.nextFloat();
      while ( DVD_number <= 0 )
      {
        System.out.println();
        System.out.println ( "Please enter the number of DVDs again:" );
        DVD_number = input.nextFloat();
        System.out.println();
      }
      System.out.print ( "Enter the amount of the DVDs:" );
      DVD_price = input.nextFloat();
      while ( DVD_price <= 0 )
      {
        System.out.println();
        System.out.println ( "DVD_number must be a positive number. No negative numbers allowed." );
        System.out.print ( "Please enter the number of DVDs again:" );
        DVD_price = input.nextFloat();
        System.out.println();
      }
      total = ( float ) DVD_number * DVD_price;
      System.out.println();
      System.out.println ( "DVD_name:" );
      System.out.println ( "Number of DVDs" + DVD_number );
      System.out.printf ( "DVD_price: $%,.2f\n", total );
      System.out.println();
      System.out.println();
    }
  }
}
} //<- wtf

Oh and if you hit compile and run at the very end after writing the whole thing, take this as a lesson learnt. Hit compile and run as many times as you can after every method written, so you can fix the errors bit by bit instead of all at the end!

Not willing to try? I am trying and have been for almost 9 weeks! You asked me for more than just the end and that is what I included. You seem to forget that not everyone is a programmer and that some of us are TRYING to learn, we won't get it immediately. I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.

Why the hell should I try to sugarcoat what I tell you? And why the hell should I do your work for you? I not only told you that we would need the rest of the code, I also told you what the error meant, and how to fix it. Considering that, it was expected that you do that before posting the code, then only posting the code if there was still a problem (probably a different one), and you didn't, that is showing no effort. Checking the braces is easy. Simply count up for each opening and down for each closing, and you should end at 0. Then, if that's the case, and it still doesn't work, then start looking closer to ensure that none of the blocks "overlap". How is that so hard? And why should anyone have to it for you? And as far as showing no effort? Posting your code and saying do it for me, is showing no effort. And complaining when someone makes a suggestion (regardless of the language used), because they haven't done it for you, is showing no effort. That shows that you simply want someone to do it for you, not "help" in completing it. "Help" is when someone tells you what you're doing wrong, and how to fix it. If they then, do the fix for you, it is no longer "helping", but "cheating", whether it concerns homework, work, or hobby, doesn't matter.

Well, matching braces or no, unless the while loop statement is moved from the end of the comment on the boolean "stop", you won't even have a loop. Statements in comments don't execute so well :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.