Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

new problem, fixed the last one now my tester and worker java programs will not play nice together?

//Mike Sigl

//Programming Final Exam (GiftBag)

//December 15th, 2011

import java.util.*;

//a class for planning your shopping day based on weight

public class GiftBag

{

private int GiftBag;

private double currentWeight = 0;

private double weight = 0;

String aBigRedBag = null;

double getLimit = 0;

int r = 0;

public int count = 0;

Scanner input = new Scanner(System.in);

//gets the bags weight limit

public void getGifts (int getGifts)

{

while (r <= getGifts)

System.out.println("Add another gift");

int gift = input.nextInt();

getGifts = (gift + getGifts);

r++;

}

public void getLimit()

{

System.out.println("Please input your bags weight limit");

double getLimit = input.nextDouble();

}

// scanner

//Loop for collecting the weights of the gifts

public void getcurrentWeight()

{

while (count <= )

{

System.out.println("Please input a gift weight ");

double weight = input.nextDouble();

currentWeight = (currentWeight + weight);

count++;

}

}

//If statements that determine status of bag

public void getStatusOfBag(String getStatusOfBag)

{

if (currentWeight <= (getLimit / 2))

System.out.println("Your bag is less than or equal to half full, you may continue shopping if you wish");

else if (currentWeight >= (getLimit / 2) && currentWeight < getLimit)

System.out.println("Your bag is nearing its limits you may continue shopping cautiously ");

else if (currentWeight >= getLimit)

System.out.println("You have reached your bags limit please precede to the check out line or get another bag");

}

//returns aBigRedBag to the viewer

public String getaBigRedBag()

{

return aBigRedBag;

}

}

and the tester is

//GiftBagTester.java

//CSC-Staff

//Fall 2011

//FINAL: Create the GiftBag class to have this application work.

/******************************************************************

* The GiftBag class is used to represent a gift bag that will

* hold gifts. The gift bag has a weight limit which is defined when creating the gift bag.

* (this is a hint for the constructor, it needs this weight)

*

* The GiftBag class keeps track of the current weight of all

* the gifts in the bag, and allows you to add as many gifts

* as you want, even over the intended weight limit.

*

* The GiftBag class has a method that will return the status message

* of the bag, depending on the weight of all the gifts in the

* bag. The status messages are:

*

* status

* "Message"

*

* less than 1/2 full (total weight is less than half of the capacity)

* "Not even half full, plenty of room for more gifts."

*

* 1/2 full or more (total weight is half or more of the capacity, but less than capacity)

* "More than half full, but room for more gifts."

*

* full(total weight of the gifts equals the capacity.)

* "Full, all set!"

*

* overfull (total weight of the gifts is less than half of the capacity)

* "You must remove some gifts!."

*

*

******************************************************************/

public class GiftBagTester

{

public static void main(String[] args)

{

GiftBag aBigRedBag = new GiftBag(50);

aBigRedBag.addGifts( 4 ); // addGifts will read in the weight of 4 gifts

System.out.println("\nNick's bag can hold " + aBigRedBag.getLimit() +

" pounds of gifts in his bag.");

System.out.println("He currently has " + aBigRedBag.getCurrentWeight() +

" pounds of gifts in his bag.");

System.out.println( aBigRedBag.getStatusOfBag() ); // this returns the status message

System.out.println();

aBigRedBag.addGifts( 1 ); // addGifts will read in the weight of 1 gift

System.out.println( aBigRedBag.getStatusOfBag() );

System.out.println();

aBigRedBag.addGifts( 3 ); // addGifts will read in the weight of 3 gifts

System.out.println( aBigRedBag.getStatusOfBag() );

System.out.println();

aBigRedBag.addGifts( 1 ); // addGifts will read in the weight of 1 gift

System.out.println( aBigRedBag.getStatusOfBag() );

}

}

one thing is that i can not change the tester

1 Answer

Relevance
  • ?
    Lv 5
    9 years ago
    Favorite Answer

    1)LINE 8

    //a class for planning your shopping day based on weight

    public class GiftBag { //two classes in the SAME FILE cannot be public.Let only the main class be //public

    2) LINE 43

    //Loop for collecting the weights of the gifts

    public void getcurrentWeight()

    {

    while (count <= ) //what do you want hare??????????????

    //less than equal to WHAT???????????????????????????

    {

    3)

    and the tester is //this is not a comment add //

    //GiftBagTester.java

    4) Line 154

    GiftBag aBigRedBag = new GiftBag(50);//parameterized constructor not defined

    System.out.println( aBigRedBag.getStatusOfBag() );

    public void getStatusOfBag(String getStatusOfBag)

    {

Still have questions? Get your answers by asking now.