Java program has errors, 80 lines of code

Posted by user2961687 on Stack Overflow See other posts from Stack Overflow or by user2961687
Published on 2013-11-06T21:32:44Z Indexed on 2013/11/06 21:53 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

I have a problem with a program. It contains a lot of errors in Eclipse. Sorry for my english and thank you in advance. Here is the task:

I. Declare a class that contains private fields Jam:

String taste,

double weight

Create constructors containing variables as parameters:

(String taste, double weight),

(double weight),

(String taste).

Parameters constructors should initialize class fields. In case the constructor does not provide the necessary parameter, it must be assumed that the field taste must have the value "No Name" and weight - 100.0. Introduce the use of all constructors creating objects that represent three kinds of jams. Note: it must be assumed that the only constructor with two parameters can be assigned to fields of the class.

Declare a class Jar that contains the field Jam jam, a dedicated constructor initiating all declared fields and methods:

open

close

isItOpen

Next, create an object of class Jar and fill it with the selected type of jam, operations repeat for all the kinds of jams.

This is my code this far:

public class App
{
    public static void main(String[] args)
    {
        Jam strawberry = new Jam("strawberry", 20.45);
        Jam raspberry = new Jam(40.50);
        Jam peach = new Jam("peach");
        Jar jar_1 = new Jar();
        Jar jar_2 = new Jar();
        Jar jar_3 = new Jar();
        jar_1.open();
        jar_1.fillIn(strawberry);
        jar_2.fillIn(peach);
        jar_3.fillIn(raspberry);
    }
}

class Jam
{
    String taste;
    double weight;

    public Jam(String taste, double weight)
    {
        this.taste = taste;
        this.weight = weight;
    }

    public Jam(double weight)
    {
        this.taste = "No name";
        this.weight = weight;
    }

    public Jam(String taste)
    {
        this.taste = taste;
        this.weight = 100.0;
    }
}

class Jar
{
    public Jam Jam = new Jam();
    private String state_jar;

    public Jar()
    {
        Jam.weight = 0;
        Jam.taste = "";
        state_jar = "closed";
    }

    public static String open()
    {
        state_jar = open;
        return state_jar;
    }

    public static String close()
    {
        state_jar = "closed";
        return state_jar;
    }

    public static boolean isItOpen()
    {
        return state_jar;
    }

    public void fillIn(Jam jam)
    {
        if (isItOpen == false)
            open();
        this.Jam.weight = jam.weight;
        this.Jam.taste = jam.taste;
        this.Jam.close();
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about jar