Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:42:08+00:00 2026-05-27T04:42:08+00:00

My code is a simple vending machine. I used centralised parttern to coding. But

  • 0

My code is a simple vending machine. I used centralised parttern to coding. But I found some errors such as in class veding_machine,

Ls[3]=new nosmall_cups();
Ls[4]=new nolarge_cups();
Ls[5]=new exit();
Ls[6]=new start();

these errors are the same:” Multiple markers at this line
– nosmall_cups cannot be resolved to a type”
And also each time when I using Ls[] in class veding_machine, there is always exits an error “Ls cannot be resolved to a variable” such as in below code:

 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];
        }
    }

The whole code of this vending machine are listed below:

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 ");

              }


           }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:42:08+00:00Added an answer on May 27, 2026 at 4:42 am

    Your Ls variable is out of visible scope for other methods, since it is declared only in veding_machine constructor. Make it a field, so that other methods can also see it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This very simple code gives me tons of errors: #include <iostream> #include <string> int
take this simple code: class A{ public: virtual void foo() = 0; void x(){
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
Pretty simple code, which I may say worked as intended in Xcode 4.1 but
Simple code from java.sun: public class BasicApp implements Runnable { JFrame mainFrame; JLabel label;
Edit: Simple code I used to solve the problem in case anyone is interested
Such simple code, why isn't it working? When the page loads, it should display
I am trying to code simple membership class. First class name is Customer and
I have this code, and works perfectly, but i want to make a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.