主题:发错地方了 请斑竹删贴
import java.io.*;
import java.util.*;
class vote{
private int count;
int getcount(){
return count;
}
void setcount(int count){
this.count = count;
}
void clear(){
this.count = 0;
}
void increment(){
this.count++;
}
void decrement(){
this.count--;
}
}
class candidate{
private String name;
private int number;
vote Vote = new vote();
candidate(){
number++;
}
candidate(String name,vote Vote){
this.Vote = Vote;
this.name = name;
number++;
}
String getname(){
return name;
}
vote getvote(){
return Vote;
}
int getnumber(){
return number;
}
}
/*class menber{
private String Name="";
menber(String name){
Name = name;
}
vote testVote = new vote();
candidate test = new candidate(Name,testVote);
//testVote.clear();
}*/
public class work68{
public static void main(String[] args){
int v=10;
/*menber prople1 = new menber("name1");
menber prople2 = new menber("name2");*/
vote testVote1 = new vote();
vote testVote2 = new vote();
testVote1.clear();
testVote2.clear();
candidate test1 = new candidate("people1",testVote1);
candidate test2 = new candidate("people2",testVote2);
try{
for(;v!=0;){
//v = InputStream.read();
v = System.in.read();
v=v-'0';
//System.out.println(v);
switch(v){
case 1 : test1.Vote.increment();break;
case -1 : test1.Vote.decrement();break;
case 2 : test2.Vote.increment();break;
case -2 : test2.Vote.decrement();break;
default : break;
}
}
}
catch(Exception e){
}
System.out.println(test1.Vote.getcount());
System.out.println(test2.Vote.getcount());
}
}
read〔〕输入无论正负显示都是正```请问怎么解决
还有把成员创建简化成一个类 但不知道怎么弄 乱弄了一下报错了
还请各位达人帮帮小弟``
import java.util.*;
class vote{
private int count;
int getcount(){
return count;
}
void setcount(int count){
this.count = count;
}
void clear(){
this.count = 0;
}
void increment(){
this.count++;
}
void decrement(){
this.count--;
}
}
class candidate{
private String name;
private int number;
vote Vote = new vote();
candidate(){
number++;
}
candidate(String name,vote Vote){
this.Vote = Vote;
this.name = name;
number++;
}
String getname(){
return name;
}
vote getvote(){
return Vote;
}
int getnumber(){
return number;
}
}
/*class menber{
private String Name="";
menber(String name){
Name = name;
}
vote testVote = new vote();
candidate test = new candidate(Name,testVote);
//testVote.clear();
}*/
public class work68{
public static void main(String[] args){
int v=10;
/*menber prople1 = new menber("name1");
menber prople2 = new menber("name2");*/
vote testVote1 = new vote();
vote testVote2 = new vote();
testVote1.clear();
testVote2.clear();
candidate test1 = new candidate("people1",testVote1);
candidate test2 = new candidate("people2",testVote2);
try{
for(;v!=0;){
//v = InputStream.read();
v = System.in.read();
v=v-'0';
//System.out.println(v);
switch(v){
case 1 : test1.Vote.increment();break;
case -1 : test1.Vote.decrement();break;
case 2 : test2.Vote.increment();break;
case -2 : test2.Vote.decrement();break;
default : break;
}
}
}
catch(Exception e){
}
System.out.println(test1.Vote.getcount());
System.out.println(test2.Vote.getcount());
}
}
read〔〕输入无论正负显示都是正```请问怎么解决
还有把成员创建简化成一个类 但不知道怎么弄 乱弄了一下报错了
还请各位达人帮帮小弟``