是不正确的方法调用,还是过度思考?

时间:2013-04-25 02:57:53

标签: java class methods counter

这是我的代码

/*Simulate a tally counter that can be used to admit a limited number of people.*/
public class tally
{public static void main(String[] args)
 {tallyCounter occupancy = new tallyCounter();
  occupancy.setLimit();
  occupancy.getPeople();
  if (people <= limit)
  {occupancy.storeOC();
  }
  else if (people > limit)
  {String big = JOptionPane.showInputDialog("There are too many people in the restaraunt\n Do you want to raise the limit of " + limit + " occupants? y/n");
   if(big.equals("y") || big.equals("Y") || big.equals("yes") || big.equals("Yes"))
   {occupancy.setLimit();
   }
   else if(big.equals("n") || big.equals("N") || big.equals("no") || fro.equals("No"))
   {occupancy.clearLimit();
}}}}


/*Initializes tools for tally class*/
class tallyCounter
{private int people;
 private int limit;
 //Constructs tallyCounter 
 public tallyCounter()
 {people = 0;
  limit = 0;
 }
 //Increments people (people)[people]
 public void Count(int people)
 {people = people + 1;
 }
 //Gets the amount of people in the restaraunt
 public int getpeople()
 {return people;
 }
 //sets limit (people)[limit]
 public int setLimit()
  {String lim = JOptionPane.showInputDialog("How many people can be in the restaurant tonight?\n (Integers only please.)");
   int limit = Integer.parseInt (lim);
   return limit;
  }
 //Clears count (people)[count]
  public static int clearcount(int count)
 {String cnt = JOptionPane.showInputDialog("Are you sure you want to return the count to zero? y/n");
  if(cnt.equals("y") || cnt.equals("Y") || cnt.equals("yes") || cnt.equals("Yes"))
  {count = 0;
  }
  else if(cnt.equals("n") || cnt.equals("N") || cnt.equals("no") || cnt.equals("No"))
  {
  count = count;
  }
  return count;
 }
 //clears limit (people)[limit]
 public static int clearlimit(int limit)
 {String cnt = JOptionPane.showInputDialog("Do you want to set the limit to zero? y/n");
  if(cnt.equals("y") || cnt.equals("Y") || cnt.equals("yes") || cnt.equals("Yes"))
  {limit = 0;
  }
  else if(cnt.equals("n") || cnt.equals("N") || cnt.equals("no") || cnt.equals("No"))
  {
  limit = limit;
  }
  return limit;
 }
  public int storeOc()
  {String fro = JOptionPane.showInputDialog("Is the store open?");
    if (fro.equals("y") || fro.equals("Y") || fro.equals("yes") || fro.equals("Yes"));
    {String fre = JOptionPane.showInputDialog("Has someone entered the restaraunt? y/n");
    if(fre.equals("y") || fre.equals("Y") || fre.equals("yes") || fre.equals("Yes"))
     {int people = Count();
     }
   else if(fro.equals("n") || fro.equals("N") || fro.equals("no") || fro.equals("No"))
   {int limit = clearlimit();
  }}
  return people;
}}

我包含了整个代码,因为我认为此代码无法编译的原因是由于方法调用不当。 我不知道我需要做什么不同。 我已经多次重新编写了这段代码,这似乎是最接近正确的, 或者我只是在严厉地思考它。

----------------------编辑------------------------

here is the full error list as of now

tally.java:6: error: cannot find symbol
  occupancy.getPeople();
           ^
  symbol:   method getPeople()
  location: variable occupancy of type tallyCounter
tally.java:7: error: cannot find symbol
  if (people <= limit)
      ^
  symbol:   variable people
  location: class tally
tally.java:7: error: cannot find symbol
  if (people <= limit)
                ^
  symbol:   variable limit
  location: class tally
tally.java:8: error: cannot find symbol
  {occupancy.storeOC();
            ^
  symbol:   method storeOC()
  location: variable occupancy of type tallyCounter
tally.java:10: error: cannot find symbol
  else if (people > limit)
           ^
  symbol:   variable people
  location: class tally
tally.java:10: error: cannot find symbol
  else if (people > limit)
                    ^
  symbol:   variable limit
  location: class tally
tally.java:11: error: cannot find symbol
  {String big = JOptionPane.showInputDialog("There are too many people in the restaraunt\n Do you want to raise the limit of " + limit + " occupants? y/n");
                                                                                                                                 ^
  symbol:   variable limit
  location: class tally
tally.java:11: error: cannot find symbol
  {String big = JOptionPane.showInputDialog("There are too many people in the     restaraunt\n Do you want to raise the limit of " + limit + " occupants? y/n");
            ^
  symbol:   variable JOptionPane
  location: class tally
tally.java:15: error: cannot find symbol
   else if(big.equals("n") || big.equals("N") || big.equals("no") || fro.equals("No"))
                                                                     ^
  symbol:   variable fro
  location: class tally
tally.java:16: error: cannot find symbol
   {occupancy.clearLimit();
             ^
  symbol:   method clearLimit()
  location: variable occupancy of type tallyCounter
tally.java:37: error: cannot find symbol
  {String lim = JOptionPane.showInputDialog("How many people can be in the restaurant tonight?\n (Integers only please.)");
                ^
  symbol:   variable JOptionPane
  location: class tallyCounter
tally.java:43: error: cannot find symbol
 {String cnt = JOptionPane.showInputDialog("Are you sure you want to return the count to zero? y/n");
               ^
  symbol:   variable JOptionPane
  location: class tallyCounter
tally.java:55: error: cannot find symbol
 {String cnt = JOptionPane.showInputDialog("Do you want to set the limit to zero? y/n");
               ^
  symbol:   variable JOptionPane
  location: class tallyCounter
tally.java:66: error: cannot find symbol
  {String fro = JOptionPane.showInputDialog("Is the store open?");
                ^
  symbol:   variable JOptionPane
  location: class tallyCounter
tally.java:68: error: cannot find symbol
    {String fre = JOptionPane.showInputDialog("Has someone entered the restaraunt? y/n");
                  ^
  symbol:   variable JOptionPane
  location: class tallyCounter
tally.java:70: error: method Count in class tallyCounter cannot be applied to given types;
     {int people = Count();
                   ^
  required: int
  found: no arguments
  reason: actual and formal argument lists differ in length
tally.java:73: error: method clearlimit in class tallyCounter cannot be applied to given types;
   {int limit = clearlimit();
                ^
  required: int
  found: no arguments
  reason: actual and formal argument lists differ in length
17 errors

0 个答案:

没有答案