Java 某些内容无法解析为类型
我的代码是一个简单的自动售货机。我用集中部分编码。但我发现了一些错误,比如在课堂上的录像机Java 某些内容无法解析为类型,java,Java,我的代码是一个简单的自动售货机。我用集中部分编码。但我发现了一些错误,比如在课堂上的录像机 Ls[3]=new nosmall_cups(); Ls[4]=new nolarge_cups(); Ls[5]=new exit(); Ls[6]=new start(); 这些错误是相同的:“这一行有多个标记 -无法将nosmall_cups解析为类型“ 而且每次我在veding_类机器中使用Ls[]时,总会出现一个错误“Ls无法解析为变量”,如下面的代码: public void small_
Ls[3]=new nosmall_cups();
Ls[4]=new nolarge_cups();
Ls[5]=new exit();
Ls[6]=new start();
这些错误是相同的:“这一行有多个标记
-无法将nosmall_cups解析为类型“
而且每次我在veding_类机器中使用Ls[]时,总会出现一个错误“Ls无法解析为变量”,如下面的代码:
public void small_cup(){
st.small_cup();
if(st.getId()==1){
//s=2;
st=Ls[1];
}
if(st.getId()==2){
//s=2;
st=Ls[2];
}
}
该自动售货机的全部代码如下所示:
import java.util.*;
class veding_machine{
State st;
private int price;
private int k;
private int k1;
private int t;
private int s;
public veding_machine(){
State[] Ls=new State[7];
Ls[0]=new idle();
Ls[1]=new coins_inserted();
Ls[2]=new sugar();
Ls[3]=new nosmall_cups();
Ls[4]=new nolarge_cups();
Ls[5]=new exit();
Ls[6]=new start();
k=0;
k1=0;
t=0;
price=0;
}
public void setK(int k){
this.k=k;
}
public int getK(){
return k;
}
public void setT(int t){
this.t=t;
}
public int getT(){
return t;
}
public void setK1(int k1){
this.k1=k1;
}
public int getK1(){
return k1;
}
public void setPrice(int price){
this.price=price;
}
public int getPrice(){
return price;
}
public void setS(int s){
this.s=s;
}
public int getS(){
return s;
}
public void coin(){
st.coin();
if(st.getId()==0){
if(t+25<price){
// t=t+25;
st=Ls[0];
}
if(t+25>=price && price>0){
//s=0;
//t=0;
st=Ls[1];
}
}
else if(st.getId()==1){
if(k1>1 && s==2){
//k1=k1-1;
st=Ls[0];
}else{
st=Ls[1];
}
}
else if(st.getId()==2){
st=Ls[2];
}
else if(st.getId()==3){
st=Ls[3];
}
else if(st.getId()==4){
st=Ls[4];
}
}
public void small_cup(){
st.small_cup();
if(st.getId()==1){
//s=2;
st=Ls[1];
}
if(st.getId()==2){
//s=2;
st=Ls[2];
}
}
public void large_cup(){
st.large_cup();
if(st.getId()==1){
//s=1;
st=Ls[1];
}
if(st.getId()==2){
//s=2;
st=Ls[2];
}
}
public void sugar(){
st.sugar();
if(st.getId()==1){
st=Ls[2];
}
if(st.getId()==2){
st=Ls[1];
}
}
public void tea(){
st.tea();
if(st.getId()==1){
if(k>1&&s==1){
//k=k-1;
st=Ls[0];
}
if(k1>1&&s==2){
//k1=k1-1;
st=Ls[0];
}
if(k==1&&s==1){
//k=k-1;
st=Ls[3];
}
if(k1==1&&s==2){
//k1=k1-1;
st=Ls[4];
}
}
if(st.getId()==2){
if(k==1&&s==1){
//k=k-1;
st=Ls[3];
}
if(k1==1&&s==2){
//k1=k1-1;
st=Ls[4];
}
if(k1>1&&s==2){
//k1=k1-1;
st=Ls[0];
}
if(k>1&&s==1){
//k=k-1;
st=Ls[0];
}
}
}
public void insert_large_cups(int n){
st.insert_large_cups(n);
if(st.getId()==0){
if(n>0){
//k=k+n;
st=Ls[0];
}
}
if(st.getId()==3){
if(n>0){
//k=n;
st=Ls[0];
}
}
}
public void insert_small_cups(int n){
st.insert_small_cups(n);
if(st.getId()==0){
if(n>0){
//k1=k1+n;
st=Ls[0];
}
}
if(st.getId()==4){
if(n>0){
//k1=n;
st=Ls[0];
}
}
}
public void set_price(int p){
st.set_price(p);
if(st.getId()==0){
if(p>0){
//price=p;
st=Ls[0];
}
}
}
public void cancle(){
st.cancle();
if(st.getId()==1){
st=Ls[0];
}
if(st.getId()==2){
st=Ls[0];
}
}
public void dispose(){
st.dispose();
if(st.getId()==0){
st=Ls[5];
}
}
}
class State{
veding_machine vm;
int id;
public void coin(){}
public void small_cup(){}
public void large_cup(){}
public void sugar(){}
public void tea(){}
public void insert_large_cups(int n){}
public void insert_small_cups(int n){}
public void set_price(int p){}
public void cancle(){}
public void dispose(){}
public int getId(){
return id;
}
}
// operation of idle class
class idle extends State{
// idle i;
veding_machine vm;
public void coin(){
if(vm.getT()+25<vm.getPrice()){
vm.setT(vm.getT()+25);
}
if((vm.getT()+25>=vm.getPrice())&&(vm.getPrice()>0)){
vm.setS(0);
vm.setT(0);
}
}
public void insert_small_cups(int n){
if(n>0){
vm.setK1(vm.getK1()+n);
}
}
public void insert_large_cups(int n){
if(n>0){
vm.setK(vm.getK()+n);
}
}
public void set_price(int p){
if(p>0){
vm.setPrice(p);
}
}
public void dispose(){
System.exit(0);
}
}
//operation of coins_inserted class
class coins_inserted extends State{
veding_machine vm;
public void coin(){
vm.setT(0);
System.out.println("return coins");
}
public void cancel(){
vm.setT(0);
System.out.println("return coins");
}
public void sugar(){
}
public void small_cup(){
vm.setS(2);
}
public void large_cup(){
vm.setS(1);
}
public void tea(){
if(vm.getK()==1&&vm.getS()==1){
vm.setK(vm.getK()-1);
System.out.println("dispose large cup of tea;");
}
if(vm.getK1()==1&&vm.getS()==2){
vm.setK1(vm.getK1()-1);
System.out.println("dispose small cup of tea;");
}
if(vm.getK()>1&&vm.getS()==1){
vm.setK(vm.getK()-1);
System.out.println("dispose large cup of tea;");
}
if(vm.getK1()>1&&vm.getS()==2){
vm.setK1(vm.getK1()-1);
System.out.println("dispose small cup of tea;");
}
}
public void cancle(){
vm.setT(0);
System.out.println("return coins");
}
}
//operation of sugar class
class sugar extends State{
veding_machine vm;
public void coin(){
vm.setT(0);
System.out.println("return coins");
}
public void small_cup(){
vm.setS(2);
}
public void large_cup(){
vm.setS(1);
}
public void sugar(){
}
public void tea(){
if(vm.getK()==1&&vm.getS()==1){
vm.setK(vm.getK()-1);
System.out.println("dispose large cup of tea;");
}
if(vm.getK1()==1&&vm.getS()==2){
vm.setK1(vm.getK1()-1);
System.out.println("dispose small cup of tea;");
}
if(vm.getK()>1&&vm.getS()==1){
vm.setK(vm.getK()-1);
System.out.println("dispose large cup of tea with sugar;");
}
if(vm.getK1()>1&&vm.getS()==2){
vm.setK1(vm.getK1()-1);
System.out.println("dispose small cup of tea with sugar;");
}
}
//operation of nolarge_cups class
class nolarge_cups extends State{
veding_machine vm;
public void coin(){
vm.setT(0);
System.out.println("return coins");
}
public void insert_large_cups(int n){
if(n>0){
vm.setK(n);
}
}
}
//operation of nosmall_cups class
class nosmall_cups extends State{
veding_machine vm;
public void coin(){
vm.setT(0);
System.out.println("return coins");
}
public void insert_small_cups(int n){
if(n>0){
vm.setK1(n);
}
}
}
//operation of start class
class start extends State{
public void veding_machine(){
int k=0;
int t=0;
int price=0;
int k1=0;
}
}
//operation of exit class
class exit extends State{}
public static void main(String[] args) {
//idle i;
//coins_inserted ci;
//sugar sg;
//nosmall_cups nsc;
//nolarge_cups nlc;
//exit et;
//start st;
int b;
char ch1;
System.out.println("*****CS589 Fall 2010***** \n"+
"******PROJECT********\n"+
"******DEMO******\n");
// PutLines(3);
veding_machine vm;
ch1='1';
while(ch1!='q'){
System.out.println("DRIVE for the vending machine\n");
System.out.println(" 0. coin() \n");
System.out.println(" 1. small_cup() \n");
System.out.println(" 2. large_cup() \n");
System.out.println(" 3. sugar() \n");
System.out.println(" 4. tea() \n");
System.out.println(" 5. insert_large_cups(int n) \n");
System.out.println(" 6. insert_small_cups(int n) \n");
System.out.println(" 7. set_Price(int p) \n");
System.out.println(" 8. cancle() \n");
System.out.println(" 9. dispose() j\n");
System.out.println(" Testing-related methods\n");
System.out.println(" a. show_variables() \n");
System.out.println(" q. Quit Vending Machine class driver \n");
Scanner scan=new Scanner(System.in);
ch1=(char)scan.nextInt();
switch(ch1){
case 'a':
System.out.println(" show_variables() testing-related method ");
}
}
}
}
import java.util.*;
类编纬机{
州立大学;
私人int价格;
私人INTK;
私人int k1;
私人int t;
私人INTS;
公共录像机(){
状态[]Ls=新状态[7];
Ls[0]=新空闲();
Ls[1]=新硬币插入();
Ls[2]=新糖();
Ls[3]=新的nosmall_杯();
Ls[4]=新的nolarge_cups();
Ls[5]=新出口();
Ls[6]=新开始();
k=0;
k1=0;
t=0;
价格=0;
}
公共无效设置(int k){
这个。k=k;
}
公共int getK(){
返回k;
}
公共无效集合(int t){
t=t;
}
公共int getT(){
返回t;
}
公共无效设置k1(int k1){
这个。k1=k1;
}
公共int getK1(){
返回k1;
}
公共无效设置价格(整数价格){
这个。价格=价格;
}
public int getPrice(){
退货价格;
}
公共空集(int-s){
这个.s=s;
}
公共int getS(){
返回s;
}
公众作废硬币(){
圣科恩();
if(st.getId()==0){
如果(t+25=价格&价格>0){
//s=0;
//t=0;
st=Ls[1];
}
}
else if(st.getId()==1){
如果(k1>1&&s==2){
//k1=k1-1;
st=Ls[0];
}否则{
st=Ls[1];
}
}
else if(st.getId()==2){
st=Ls[2];
}
else if(st.getId()==3){
st=Ls[3];
}
else if(st.getId()==4){
st=Ls[4];
}
}
公共空间小(杯){
圣斯莫尔杯();
if(st.getId()==1){
//s=2;
st=Ls[1];
}
if(st.getId()==2){
//s=2;
st=Ls[2];
}
}
公共空间大(杯){
圣大杯();
if(st.getId()==1){
//s=1;
st=Ls[1];
}
if(st.getId()==2){
//s=2;
st=Ls[2];
}
}
公众假期{
圣糖();
if(st.getId()==1){
st=Ls[2];
}
if(st.getId()==2){
st=Ls[1];
}
}
公共茶(){
圣茶();
if(st.getId()==1){
如果(k>1&&s==1){
//k=k-1;
st=Ls[0];
}
如果(k1>1&&s==2){
//k1=k1-1;
st=Ls[0];
}
如果(k==1&&s==1){
//k=k-1;
st=Ls[3];
}
如果(k1==1&&s==2){
//k1=k1-1;
st=Ls[4];
}
}
if(st.getId()==2){
如果(k==1&&s==1){
//k=k-1;
st=Ls[3];
}
如果(k1==1&&s==2){
//k1=k1-1;
st=Ls[4];
}
如果(k1>1&&s==2){
//k1=k1-1;
st=Ls[0];
}
如果(k>1&&s==1){
//k=k-1;
st=Ls[0];
}
}
}
公共空间插入大杯子(整数n){
st.insert_大杯(n);
if(st.getId()==0){
如果(n>0){
//k=k+n;
st=Ls[0];
}
}
if(st.getId()==3){
如果(n>0){
//k=n;
st=Ls[0];
}
}
}
公共空间插入小杯子(整数n){
插入小杯子(n);
if(st.getId()==0){
如果(n>0){
//k1=k1+n;
st=Ls[0];
}
}
if(st.getId()==4){
如果(n>0){
//k1=n;
st=Ls[0];
}
}
}
公共无效集合价格(INTP){
标准设定价格(p);
if(st.getId()==0){
如果(p>0){
//价格=p;
st=Ls[0];
}
}
}
公共空间取消(){
圣坎克尔();
if(st.getId()==1){
st=Ls[0];
}
if(st.getId()==2){
st=Ls[0];
}
}
公共空间处置(){
圣安德鲁斯();
if(st.getId()==0){
st=Ls[5];
}
}
}
阶级国家{
视频采集机;
int-id;
公共无效硬币(){}
公共空间小_杯(){}
公共空间大型_cup(){}
公共空间({}
公共空间({}
公共空白插入\u大\u杯(int n){}
公共空白插入\u小\u杯(int n){}
公共无效集_价格(int p){}
public void cancle(){}
public void dispose(){}
公共int getId(){
返回id;
}
}
//空闲类的操作
类空闲扩展状态{
//闲置i;
视频采集机;
公众作废硬币(){
if(vm.getT()+25=vm.getPrice())&&(vm.getPrice()>0)){
vm.set(0);
vm.setT(0);
}
}
公共空间插入小杯子(整数n){
如果(n>0){
vm.setK1(vm.getK1()+n);
}
}
公共空间插入大杯子(整数n){
如果(n>0){
vm.setK(vm.getK()+n);
}
}
公共无效集合价格(INTP){
如果(p>0){
vm.setPrice(p);
}
}
公共空间处置(){
系统出口(0);
}
}
//插入类的操作
类插入扩展状态{
视频采集机;
公众作废硬币(){
vm.setT(0);
系统输出打印号(“返回硬币”);
}
公开作废取消(){
虚拟机