COKEDUDE 27 Junior Poster in Training

I have two different parts to my program. My FundRaising.java is my problem. I'm having problems with my print statements. Why are the correct numbers not showing up? I keep getting 0.
System.out.println (booster1);
System.out.println (booster2);

I ask the question to get the numbers and I keep on getting 0
System.out.println ("What is the sales for the first week:");
numBoxes = scan.nextInt();
booster1 = numBoxes.BandBooster(name);

//*********************************************************************
//  FundRaising.java
//
//  Tracks band candy sales of two band boosters over two weeks.
//*********************************************************************

import java.util.Scanner;

public class FundRaising
{
    //-------------------------------------------------------
    // Creates 2 band boosters and gets their sales of band
    // candy over a period of two weeks.  Total sales
    // are computed for each band booster.
    //-------------------------------------------------------
    public static void main (String[] args)
    {
	String name;
	BandBooster booster1;
	BandBooster booster2;
	int numBoxes;
        int boxesSold=0;

	Scanner scan = new Scanner(System.in);

	System.out.println ("Band Sales Program\n");

	//Get names of band boosters
	System.out.print ("Enter the name of the first booster: ");
	name = scan.nextLine();
	booster1 = new BandBooster (name);

	System.out.print ("Enter the name of the second booster: ");
	name = scan.nextLine();
	booster2 = new BandBooster (name);

	//Get sales for week 1

	// add your code here
        System.out.println ("What is the sales for the first week:");
        numBoxes = scan.nextInt();
        booster1 = numBoxes.BandBooster(name);

	//Get sales for week 2


	// add your code here
        System.out.println ("What is the sales for the second week:");
        numBoxes = scan.nextInt();

        //summation
        //boxesSold += numboxes1 + numboxes2;

	// print summary for both band boosters. …
COKEDUDE 27 Junior Poster in Training
for (int i = 0; i < itemCount; i++)
	    contents += cart[i].toString() + "\n[B]"[/B]

	contents += "\nTotal Price: " + fmt.format(totalPrice);

First of all, I think you missed a " after the \n inside the loop.
Secondly, cart is an int. Where did you see written that ints have methods?
The cart doesn't have a method toString because it is an int. You can't make up from your mind methods and call them and then wonder why the code doesn't run.

This is going to work:

for (int i = 0; i < itemCount; i++)
	    contents += cart[i] + "\n";

cart is supposed to be an array. Am I doing arrays properly? I can't find very much documentation on arrays.

COKEDUDE 27 Junior Poster in Training

I don't understand what you are trying to say.

COKEDUDE 27 Junior Poster in Training

Can someone please tell me why "int can not be dereferenced" here.
contents += cart.toString() + "\n


// **********************************************************************
//   ShoppingCart.java
//
//   Represents a shopping cart as an array of items
// **********************************************************************

import java.text.NumberFormat;

public class ShoppingCart
{
    private int itemCount;      // total number of items in the cart
    private double totalPrice;  // total price of items in the cart
    private int capacity;       // current cart capacity

    // -----------------------------------------------------------
    //  Creates an empty shopping cart with a capacity of 5 items.
    // -----------------------------------------------------------
    public ShoppingCart()
    {
	capacity = 5;
	itemCount = 0;
	totalPrice = 0.0;
    }

    // -------------------------------------------------------
    //  Adds an item to the shopping cart.
    // -------------------------------------------------------
    public void addToCart(String itemName, double price, int quantity)
    {
    }

    // -------------------------------------------------------
    //  Returns the contents of the cart together with
    //  summary information.
    // -------------------------------------------------------
    public String toString()
    {
	NumberFormat fmt = NumberFormat.getCurrencyInstance();

	String contents = "\nShopping Cart\n";
	contents += "\nItem\t\tUnit Price\tQuantity\tTotal\n";

	int[] cart = new int [capacity];
        for (int i = 0; i < itemCount; i++)
	    contents += cart[i].toString() + "\n

	contents += "\nTotal Price: " + fmt.format(totalPrice);
	contents += "\n";

	return contents;
    }

    // ---------------------------------------------------------
    //  Increases the capacity of the shopping cart by 3
    // ---------------------------------------------------------
    //Fill in the code for the increaseSize method. Your code should be
    //similar to that in Listing 7.8 of the text but instead of doubling the
    //size just increase it by 3 elements. 
    private void increaseSize()
    {
        int[] cart = new int [capacity + 3];
        
    }
}
COKEDUDE 27 Junior Poster in Training

I figured out the problem.
double Correct = 0;
double Incorrect = 0;
On that part I needed to move it down farther in the code so it reinitialized to 0 to reset the count.

Here's the full working code if anyone is curious.

//****************************************************************
// Quizzes.java
//
// Calculates quizz scores.
// 
//
// ****************************************************************
import java.util.Scanner;

public class Quizzes
{
    public static void main(String[] args)
    {
	final int SALESPEOPLE;
	int sum;
        int Questions;
        int answers;
        int Quizzes;
        String phrase= "";    // a string of characters

	Scanner scan = new Scanner(System.in);

        System.out.println("How many questions are in the quizz?");
        Questions = scan.nextInt();
        System.out.println("The number of questions will be " +Questions);

        //System.out.println("How many quizzes would you like to grade");
        //Quizzes = scan.nextInt();

        int[] canswers = new int[Questions];
        for (int i=0; i<canswers.length; i++)
	    {
		System.out.println("Please give the correct answers " + (i+1) + ": ");
		canswers[i] = scan.nextInt();
	    }


        //int num = Quizzes.length;
        //for(int quiz=1;quiz<=num;quiz++)
        //while(!Quizzes)
        while (!phrase.equals("n"))
        {
        //for(int quiz=1;quiz<=Quizzes;quiz++)
        //{

            double Correct = 0;
            double Incorrect = 0;
            for (int i=0; i<canswers.length; i++)
            {
            System.out.println("What are the answers that the students put");
            answers = scan.nextInt();
            if (answers == canswers[i])
                Correct++;
            else
                Incorrect++;
            }

            double Percent = Correct / Questions;
            System.out.println("There are " +Correct + " correct answers and " +Incorrect
                +" answers");
            System.out.println(Correct);
            System.out.println(Incorrect);
            System.out.println(Questions);
            System.out.println(Percent);
            System.out.println("The percentage correct is " +Percent*100 +"%");
            phrase = scan.nextLine();
            System.out.println("Would you like to grade another quiz y/n");
            phrase = scan.nextLine();
        }


    }
}
COKEDUDE 27 Junior Poster in Training

I think you would need a for loop
That performs quizzes.length loops

int num = quizzes.length;
for(int quiz=1;quiz<=num;quiz++)
{
...
}

And then quiz is your quiz number which you can use inside loop if you want, to display the number of the quiz.

I can't get that to work no matter how I try it :(.

COKEDUDE 27 Junior Poster in Training

Got the part above. Now I'm having problems with this part.
System.out.println("How many quizzes would you like to grade");
Quizzes = scan.nextInt();

int[] canswers = new int[Questions];

While(!=Quizzes.length)

I would like to grade however many quizzes I input above, so I would think I would need some kind of while loop. What kind of loop would I need to make that work? Here is my full code now.

//****************************************************************
// Quizzes.java
//
// Calculates quizz scores.
// 
//
// ****************************************************************
import java.util.Scanner;

public class Quizzes
{
    public static void main(String[] args)
    {
	final int SALESPEOPLE;
	int sum;
        int Questions;
        int answers;
        double Correct = 0;
        double Incorrect = 0;
        int Quizzes;

	Scanner scan = new Scanner(System.in);

        System.out.println("How many questions are in the quizz?");
        Questions = scan.nextInt();
        System.out.println("The number of questions will be " +Questions);

        System.out.println("How many quizzes would you like to grade");
        Quizzes = scan.nextInt();

        int[] canswers = new int[Questions];
        
        While(!=Quizzes.length)
        {
	for (int i=0; i<canswers.length; i++)
	    {
		System.out.println("Please give the correct answers " + (i+1) + ": ");
		canswers[i] = scan.nextInt();
	    }

        for (int i=0; i<canswers.length; i++)
        {
            System.out.println("What are the answers that the students put");
            answers = scan.nextInt();
            if (answers == canswers[i])
                Correct++;
            else
                Incorrect++;
        }

        double Percent = Correct / Questions;
        System.out.println("There are " +Correct + " correct answers and " +Incorrect
                +" answers");
        System.out.println(Correct);
        System.out.println(Incorrect);
        System.out.println(Questions);
        System.out.println(Percent);
        System.out.println("The percentage correct is " +Percent*100 +"%");



        }
    }
}
COKEDUDE 27 Junior Poster in Training

Can someone please explain why this division is not working. This is very simple division but for some reason it won't work.
double Percent = Correct / Questions;

//****************************************************************
// Quizzes.java
//
// Calculates quizz scores.
// 
//
// ****************************************************************
import java.util.Scanner;

public class Quizzes
{
    public static void main(String[] args)
    {
	final int SALESPEOPLE;
	int sum;
        int Questions;
        int answers;
        int Correct = 0;
        int Incorrect = 0;
        //double Percent;

	Scanner scan = new Scanner(System.in);

        System.out.println("How many questions are in the quizz?");
        Questions = scan.nextInt();
        System.out.println("The number of questions will be " +Questions);

        int[] canswers = new int[Questions];

	for (int i=0; i<canswers.length; i++)
	    {
		System.out.println("Please give the correct answers " + (i+1) + ": ");
		canswers[i] = scan.nextInt();
	    }

        for (int i=0; i<canswers.length; i++)
        {
            System.out.println("What are the answers that the students put");
            answers = scan.nextInt();
            if (answers == canswers[i])
                Correct++;
            else
                Incorrect++;
        }

        double Percent = Correct / Questions;
        System.out.println("There are " +Correct + " correct answers and " +Incorrect
                +" answers");
        System.out.println(Correct);
        System.out.println(Incorrect);
        System.out.println(Questions);
        System.out.println(Percent);
        System.out.println("The percentage correct is" +Percent);



    }
}
COKEDUDE 27 Junior Poster in Training

Multiply 100 times your percentage which should be a decimal number? If you elaborate on the purpose of this people be able to think of more ways. There's also a for loop and while loop. Doing an array would also be possible if you gave a list of numbers.

COKEDUDE 27 Junior Poster in Training

After I ask the user to enter a number here
System.out.println("Enter a number");
number = scan.nextInt();
I would like print the id of each salesperson that exceeded that value and the amount of their sales. I Also want to print the total number of salespeople whose sales exceeded the value entered. So I would think I would need some kind of for loop and several print statements. This is what I am thinking for my for loop.
for (int i=0; number<i; i++)
Line 1 to line 56 is good. After that is where I am trying to put my for loop.

//****************************************************************
// Sales.java
//
// Reads in and stores sales for each of 5 salespeople.  Displays
// sales entered by salesperson id and total sales for all salespeople.
//
// ****************************************************************
import java.util.Scanner;

public class Sales
{
    public static void main(String[] args)
    {
	final int SALESPEOPLE = 5;
	int[] sales = new int[SALESPEOPLE];
	int sum;

	Scanner scan = new Scanner(System.in);

	for (int i=0; i<sales.length; i++)
	    {
		System.out.print("Enter sales for salesperson " + (i+1) + ": ");
		sales[i] = scan.nextInt();
	    }

	System.out.println("\nSalesperson   Sales");
	System.out.println("--------------------");
	sum = 0;
        int maximum = sales[0];
        int minimum  = sales[0];
        int a=1, b=1;
	for (int i=0; i<sales.length; i++)
	    {
		if(maximum < sales[i])
                {
                    maximum = sales[i];
                    a = i+1;
                }
                if(minimum > sales[i])
                {
                    minimum = sales[i];
                    b = i+1;
                }
                System.out.println("     " + (i+1) + "         " + sales[i]);
		sum += sales[i];
	    }

	System.out.println("\nTotal sales: " + sum); …
COKEDUDE 27 Junior Poster in Training

If you haven't specified a modifier and they are in a different package, they are private.

Use a public method getName() to get the name - don't access the variable directly.

When you say modifier I assume you mean public, private, and protected? And not sure what you mean by package. Could you explain what you mean by package please.

COKEDUDE 27 Junior Poster in Training

If you have declared it private then you will need to use a public getter method to get the name. Same for balance.

I don't even see the word private. Any ideas why it thinks it is private?

COKEDUDE 27 Junior Poster in Training

Well, move it outside main(). Cut-paste the entire thing outside of the braces that delimit the main() method.

Ok. Any idea about this part?
In my if statement It says name has private access in account. What does that mean and how do i fix it?
if((accnt1.name).equals(accnt2.name))

COKEDUDE 27 Junior Poster in Training

How would I do that? And what about the second question?

COKEDUDE 27 Junior Poster in Training

Why is this an illegal start on an expression? public Account consolidate(Account accnt1, Account accnt2)
In my if statement It says name has private access in account. What does that mean and how do i fix it?
if((accnt1.name).equals(accnt2.name))

//***********************************************************
// TestConsolidation
// A simple program to test the numAccts method of the
// Account class.
//***********************************************************
import java.util.Scanner;

public class TestConsolidation
{
    public static void main(String[] args)
    {
        
        //Account consolidate- the sum of acct1 and acct2
  public static Account consolidate(Account accnt1, Account accnt2)
  {
      Account newAccount = null;
      if((accnt1.name).equals(accnt2.name))
      {
          if(accnt1.acctNum!=accnt2.acctNum)
          {
              String Name = accnt2.name;
              double balances = accnt1.balance + accnt2.balance;
              //Account accountSum;
              //int accountSum;
              //accountSum.balance = account1.getBalance() + account2.getBalance();
              //Consolidate acct1 and acct2 like newAccount = (name, balance of 2 accts, acctnum(random));
		accnt1.close();
		accnt2.close();
                numAccounts++;
          }}


      return newAccount;

  }

    }
}
COKEDUDE 27 Junior Poster in Training

Can someone please explain what both of these mean and the good details about them. Please also explain the parameters of how to use it.

COKEDUDE 27 Junior Poster in Training

Something like this. Except my program is way simpler.
http://www.javapractices.com/topic/TopicAction.do?Id=6

COKEDUDE 27 Junior Poster in Training

Close out a public void close().

COKEDUDE 27 Junior Poster in Training

Again, that depends on what you mean by 'closing an account'. Typically you'd close an account by removing all the money from it, i.e. withdrawing all money from your bank account, then just deleting it or somehow marking it as closed. But we are just programmers, if you need help with implementation or errors that's fine, but I doubt you'll find much help on how to interpret your project's requirements. Is this for a class? If so speak to the professor.

I'm trying to do some form of account.close();. No matter where I put it in my program it won't work :(.

COKEDUDE 27 Junior Poster in Training

What is a consolidated account? Just an account under both names? What do you have to do to 'make an account consolidated'?

Thats one of my problems. I have no clue. I can't find anything useful in my book or online. What about the second part? How would I close the first account?

COKEDUDE 27 Junior Poster in Training

I'm trying to do some consolidation but I'm not sure on the specific rules of consolidation so I'm having A LOT of difficulty on it. Here's what I'm trying to do.
Write a program that prompts for and reads in three names and creates an account with an initial balance of $100 for each. Print the three accounts, then close the first account and try to consolidate the second and third into a new account. Now print the accounts again, including the consolidated one if it was created.
I'm having difficulty with closing the first account then Consolidating :(. Here's my code so far with no errors so far.

//***********************************************************
// TestAccounts1
// A simple program to test the numAccts method of the
// Account class.
//***********************************************************
import java.util.Scanner;

public class TestConsolidation
{
    public static void main(String[] args)
    {

        String name1;
        String name2;
        String name3;
        double balance = 100.00;
        int balance1;
        int balance2;
        int balance3;

        //declare and initialize Scanner object
        String message;
        Scanner scan = new Scanner (System.in);

        //Prompt for and read in the names
        System.out.println ("What is the first name? ");
        name1 = scan.next();

        message = scan.nextLine();
        //balance = balance1;

        System.out.println ("The first name is: \"" + name1 + "\"");
        System.out.println("The balance for this acoount is:" +balance);

        System.out.println ("What is the second name? ");
        name2 = scan.next();

        message = scan.nextLine();

        System.out.println ("The second name is: \"" + name2 + "\"");
        System.out.println("The balance for this acoount is:" +balance);

        System.out.println ("What is the third name? ");
        name3 = …
COKEDUDE 27 Junior Poster in Training

>>

public Account consolidate(Account account1, Account account2)
{
       Account accountSum;
      accountSum.balance = account1.getBalance() + account2.getBalance();

   //make account1 and account close()
}

See how that works. Break down the question, and it becomes simpler.
So you need to sum the balance, and close account1 and account2.
By the way, You should make account1 and account2 = null when its closed.

Ok this looks better. For some reason it doesn't think accountSum has been initialized so my program won't run :(.
Here's what my program looks like so far.

//*******************************************************
// Account.java
//
// A bank account class with methods to deposit to, withdraw from,
// change the name on, and get a String representation
// of the account.
//*******************************************************

public class Account
{
  private double balance;
  private String name;
  private long acctNum;
  private static int numAccounts = 0;

  //----------------------------------------------
  //Constructor -- initializes balance, owner, and account number
  //----------------------------------------------
  public Account(double initBal, String owner, long number)
  {
    balance = initBal;
    name = owner;
    acctNum = number;
    numAccounts++;
  }

  //----------------------------------------------
  // Checks to see if balance is sufficient for withdrawal.
  // If so, decrements balance by amount; if not, prints message.
  //----------------------------------------------
  public void withdraw(double amount)
  {
    if (balance >= amount)
       balance -= amount;
    else
       System.out.println("Insufficient funds");
  }

  //----------------------------------------------
  // Adds deposit amount to balance.
  //----------------------------------------------
  public void deposit(double amount)
  {
    balance += amount;
  }

  //----------------------------------------------
  // Returns balance.
  //----------------------------------------------
  public double getBalance()
  {
    return balance;
  }

//----------------------------------------------
  // Returns account number.
  //----------------------------------------------
  public long getAcctNumber()
  {
    return acctNum;
  } …
COKEDUDE 27 Junior Poster in Training

1)You should always post error you getting
2)Line 93 if statement is with capital "i"
3)You are missing brackets for your first if statement on line 92
4)Line 95 is not a Java expression. Haven't you been given rules about consolidation?

Is there a particular program that you know of that gives good error codes? I use a combination of Jgrasp and netbeans. Thank you for the figuring out the "I" and brackets.
Could you explain the consolidation rules please. I really don't understand them.

COKEDUDE 27 Junior Poster in Training

Could anyone tell me what is wrong this code please. I'm trying to do this.
Add a static method Account consolidate(Account acct1, Account acct2) to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned. Two important rules of consolidation:
Starting at line 98 is where I'm starting to have problems :(.

//*******************************************************
// Account.java
//
// A bank account class with methods to deposit to, withdraw from,
// change the name on, and get a String representation
// of the account.
//*******************************************************

public class Account
{
  private double balance;
  private String name;
  private long acctNum;
  private static int numAccounts = 0;

  //----------------------------------------------
  //Constructor -- initializes balance, owner, and account number
  //----------------------------------------------
  public Account(double initBal, String owner, long number)
  {
    balance = initBal;
    name = owner;
    acctNum = number;
    numAccounts++;
  }

  //----------------------------------------------
  // Checks to see if balance is sufficient for withdrawal.
  // If so, decrements balance by amount; if not, prints message.
  //----------------------------------------------
  public void withdraw(double amount)
  {
    if (balance >= amount)
       balance -= amount;
    else
       System.out.println("Insufficient funds");
  }

  //----------------------------------------------
  // Adds deposit amount to balance.
  //----------------------------------------------
  public void deposit(double amount)
  {
    balance += amount;
  }

  //----------------------------------------------
  // Returns balance.
  //----------------------------------------------
  public double getBalance()
  {
    return balance;
  }

//----------------------------------------------
  // Returns account number.
  //----------------------------------------------
  public long getAcctNumber()
  {
    return acctNum;
  }

   //-----------------------------------------------
    //getNumAccount: return the of accounts
    //-----------------------------------------------

   public static int getNumAccounts()
    {
	return numAccounts; …
COKEDUDE 27 Junior Poster in Training

Try using netbeans. There are WAY to many mistakes for me to even try to help right now. I counted 11 big mistakes. Let netbeans guide you through fixing all of the big mistakes.

COKEDUDE 27 Junior Poster in Training

Done. Sorry for the late reply.

COKEDUDE 27 Junior Poster in Training

Thx a lot masijade. I finally got it ;). Can you please explain why that works? I would like to learn. I would have never of figured that out on my own. My knowledge of java is fairly limited.

COKEDUDE 27 Junior Poster in Training

I really don't understand what you are saying. How would I initialize "phrase" if i put

while (!phrase.equals("quit")) {

so soon? I'm really new with java so please be kind to me.

COKEDUDE 27 Junior Poster in Training

Wrap the thing from that point on in a while (!phrase.equals("quit")) { loop.

Where would I place this? while (!phrase.equals("quit")) { If I do it before

length = phrase.length();

it won't run because I haven't initialized "phrase". If I place it after the

length = phrase.length();

, one of two things happens depending on where I place my "}". Option one at the end is it causes an infinite loop or option two if I place the "}" sooner is it does nothing.

COKEDUDE 27 Junior Poster in Training

Right now my code runs just the way I want it to. I would like the

Enter a sentence or phrase

part to continue until the user enters "quit". I would like to use a while statement. Every way I have tried to enter phrase not equal to "quit" has not worked. Do I need to declare "quit" somewhere or what? Any help would be greatly appreciated.

// **********************************************************
//   length.java
//
//   This program reads in strings (phrases) and counts the
//   number of blank characters and certain other letters
//   in the phrase.
// **********************************************************

import java.util.Scanner;

public class Length
{
  public static void main (String[] args)
  {
      String phrase;    // a string of characters
      int countBlank;   // the number of blanks (spaces) in the phrase
      int length;       // the length of the phrase
      int countA = 0; // the number of a's in the phrase
      int countE = 0; // the number of e's in the phrase
      int countS = 0; // the number of s's in the phrase
      int countT = 0; // the number of t's in the phrase
      char ch;          // an individual character in the string

	Scanner scan = new Scanner(System.in);

      // Print a program header
      System.out.println ();
      System.out.println ("Character Counter");
      System.out.println ();

      // Read in a string and find its length
      System.out.print ("Enter a sentence or phrase: ");
      //System.out.print ("Enter a sentence, phrase, or 'quit' to exit program: ");
      phrase = scan.nextLine();
      length = phrase.length();

      // Initialize counts
      countBlank = …