0
package assignment1;
    
    /**
     *
     * @author ricar
     */
    public class Change {
     
     
     public String personName;
     public double  coinChange;
     
     public Change(){
     
     this.personName="Unknown";
     this.coinChange=0.0;
     } 
     
     public String  getpersonName(){
          return this.personName; 
     }
     
     public double getcoinChange(){
     return this.coinChange;
     }
     
     public void setpersonName(String name){
         this.personName=name;
     }
     
     
     public void setCoinChange(int coin){
     this.coinChange=coin;
     }
     
     
     public boolean inRange(int range){
         boolean rang=true;
         if(range>=5 && range<=95 && range%5==0){
         rang=true;
         }else{
             rang=false;
         }
         
         return rang;
     }
     
      public static boolean keepEntering (char resp){
           boolean result=false;
            if (resp=='Y'){
            result = true;
           }
           else if (resp=='N'){
            result = false;
           System.out.println("You quit");}
            else 
           {
           System.out.println("You have chosen an invalid option, the program will quit it self.");
           }
           return result;
           
           }
     }
        








package assignment1;
    
    import java.util.Scanner;
    
    /**
     *
     * @author ricar
     */
    public class Client {
     public static Scanner keyboard = new Scanner (System.in);
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            Change c1 = new Change();
            boolean keep=true;
            
            while(keep==true){
            
            System.out.println("Please enter the PERSON NAME: ");
            c1.setpersonName(keyboard.nextLine());
            System.out.println("Please enter the COIN VALUE: ");
            c1.setCoinChange(keyboard.nextInt());
            
            
            if(c1.inRange((int)c1.getcoinChange())){
              System.out.println("The person name is: "+c1.getpersonName());
              System.out.println("The coin change is: "+ c1.getcoinChange());
            }
            System.out.println("Do you wish to continue ? [y/n]");
             
            
            keep = c1.keepEntering(keyboard.next().toUpperCase().charAt(0));
               
            }
               
        }
    }
        

When I opt for 'Y', the loop jumps the c1.setpersonName(keyboard.nextLine()); command and the result is this:

run: Please enter the PERSON NAME: r Please enter the COIN VALUE: 5 The person name is: r The coin change is: 5.0 Do you wish to continue ? [y/n] y Please enter the PERSON NAME: Please enter the COIN VALUE:

  • Please look at [Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo() methods](http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo) – Hovercraft Full Of Eels Aug 27 '20 at 00:43

0 Answers0