Hi! It seems like my Scanner for my string is not working in here. I don't have a error but when I run my program, it just skips the scanner and ends the program. Any idea?
Thanks!
import java.util.Scanner;
public class Food {
public static void main(String[] args) {
Scanner Keyboard = new Scanner(System.in);
double pricefruit = 26.99, pricecheese = 22.99, pricedairy = 13.99, pricemeat = 56.99, priceseafood = 38.99;
System.out.println("Please enter the quantities for each item in the list.");
System.out.print("Fruits : ");
int fruits = Keyboard.nextInt();
System.out.print("Cheese : ");
int cheese = Keyboard.nextInt();
System.out.print("Dairy : ");
int dairy = Keyboard.nextInt();
System.out.print("Meat : ");
int meat = Keyboard.nextInt();
System.out.print("Seafood : ");
int seafood = Keyboard.nextInt();
double totalfruits = fruits*pricefruit, totalcheese = cheese*pricecheese, totaldairy = dairy*pricedairy, totalmeat = meat*pricemeat, totalseafood = seafood*priceseafood;
double totalprice = totalfruits+totalcheese+totaldairy+totalmeat+total seafood;
System.out.print("Do you have a membership? (Y/N) ");
RIGHT HERE--->String member = Keyboard.nextLine();
if(member.equals("Y"))
{
if(totalprice < 250)
System.out.println("The total price is " + Math.round((0.9*(totalprice-totalseafood)+seafood)*100.0)/100.0 + ". You will receive " + Math.round(2*totalprice) + " points." );
else if(totalprice >= 250 && totalprice <= 500)
System.out.println("The total price is " + 0.85*(totalprice-totalseafood)+seafood + ". You will receive " + Math.round(2*totalprice) + " points." );
else if(totalprice > 500)
System.out.println("The total price is " + 0.8*(totalprice-totalseafood)+seafood + ". You will receive " + Math.round(3*totalprice) + " points." );
}
if(member.equals("N"))
{
if(totalprice < 250)
System.out.println("The total price is " + 0.9*(totalprice-totalseafood)+seafood + "." );
else if(totalprice >= 250 && totalprice <= 500)
System.out.println("The total price is " + 0.85*(totalprice-totalseafood)+seafood + "." );
else if(totalprice > 500)
System.out.println("The total price is " + 0.8*(totalprice-totalseafood)+seafood + "." );
}
System.out.println();
System.out.print("Thanks for shopping! See you next time!");
(Keyboard).close();
}
}