i had stuck with this question cz i'm newbie for java programming.
i hope ur helping...


The Vote class has the data field count to count votes, and the methods getCount(), setCount(), clear(), increment(), and
decrement()
for reading and handling the votes, as shown in class diagram below. The increment () method increases and decrement () method
decreases the value of count by 1. The clear () method sets count to 0.

--------------------------------------
              Vote                    
--------------------------------------
 ~getCount(): int                 
 ~setCount(c : int) : void     
 ~clear() : void                      
 ~increment() : void              
 ~decrement() : void             
--------------------------------------
Based on the diagram and the description above, complete the following Vote class.

-------------------------------------------------------------------------------------

class Vote{
int count = 0;
public int getCount() {
return count;
}
public void setCount(int c) {
count=c;
}



}

thanks for your participant

Recommended Answers

All 8 Replies

Okay? Show us your attempt at it, not just your assingment text, and we will help you correct it, but we are not going to do it for you. Regardless of what your personal feeling about it would be, that would not help you, it would hurt you.

Let talk a little about what you have
The class vote have a member of type int named count and initialize to 0 and too member function that getCount and setCount ;
The void reserved word mean that it do not return any thing;
The public int declaration means that it returns a data of type int, and the c is called the formal parameter.
So the three functions increment, decrement and clear does not return any thing so you can imagine that they could be declared as void as shown bellow
To increase a value of count all you have to do is to add 1 to it like this:
count=count+1
Or shortly
count +=
Clearing Count consiste to set its value to 0 like that
count =0;
Decreasing the value of count is as follow:
count =count-1
Or more shortly
cout-=;
The core of the tree functions is as follow:

Public void functionName(){
//put the appropriate code here as described above
}
Where the functionName is one of tree words:
Increase, decrease or Clear;
Exemple:
public void Clear{
count=0;
}

So you can do the rest.
It is not hard is’n it?

i had made the java coding, btw thanks ya mouttana i can sleep tight. hehee but when i run i got run time error.

class Vote{

int count = 0;
public int getCount(){
return count;
}
public void setCount(int c) {
count=c;
}
public void clear(){
count=0;
}
public void increment(){
count= count+1;
}
public void decrement(){
count= count-1;
}
}

What message you get?

uhm.
when i add
public static void main (String []args){

after class..
but it will make the program error.

----jGRASP exec: java Vote

java.lang.NoSuchMethodError: main
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

the main method must be inside class not after like that:

class Vote{

int count = 0;
public int getCount(){
return count;
}
public void setCount(int c) {
count=c;
}
public void clear(){
count=0;
}
public void increment(){
count= count+1;
}
public void decrement(){
count= count-1;
}
public static void main(String[]args) {
       //
    }
}

thanks moutanna

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.