problem on expressing a boolean method
hi guys,
so i'm having a little problem with my program, and till now i cannot figure it out what it is.
here is my program
Code:
import java.io.IOException;
import java.util.Scanner;
public class Punch {
private static Scanner give=new Scanner(System.in);
public static boolean Sugar() throws IOException{
char i;
boolean sugar=true;
i=(char) System.in.read();
if(i=='y'){
sugar=true;
}
else if(i=='n'){
sugar=false;
}
return sugar;
}
public static String getSugar() throws IOException{
boolean Sugar = Sugar();
String sg = null;
if(Sugar==false){
sg="without sugar";
}
else {
sg="with sugar";
}
return sg;
}
public static String getTemperature(){
System.out.println("Which temperature?");
String temp=give.next();
System.out.println(temp);
return temp;
}
public static int getFlavor() {
int i = 0;
i=give.nextInt();
return i;
}
public static void main(String[]args) throws IOException{
String flavor;
System.out.println("Choose flavor");
System.out.println("[0] alcohol free punch"
+"\n[1] turbo punch (double Rum)"
+"\n[2] blood orange punch"
+"\n[3] apple punch with cinnamon");
int fl=getFlavor();
System.out.println("With sugar y/n?");
boolean sugar =Sugar();
String sugar1 = getSugar();
String tp=getTemperature();
System.out.println("Which amount");
int amount=give.nextInt();
if(fl==0){
flavor="alcohol free punch";
for(int i=0;i<amount;i++){
System.out.println(i+""+tp +""+flavor+""
+sugar1+"is ready for drinking");}}
if(fl==1){
flavor="turbo punch (double Rum)";
for(int i=0;i<amount;i++){
System.out.println(i+""+flavor+""+fl+""
+sugar1+"is ready for drinking");}}
if(fl==2){
flavor="blood orange punch";
for(int i=0;i<amount;i++){
System.out.println(i+""+flavor +""+fl+""
+sugar1+"is ready for drinking");}}
if(fl==3){
flavor="apple punch with cinnamon";
for(int i=0;i<amount;i++){
System.out.println(i+""+flavor +""+fl+""
+sugar1+"is ready for drinking");}
}
}
}
the problem is with the boolean expression. I don't know why, but everytime i run the program, whatever i press when it comes to the question
(With sugar y/n) the program will publish just "with sugar".....
Can somebody tell me what i did wrong...??
this is the output of the program
Code:
With sugar y/n?
n
Which temperature?
hot
Which amount
3
0 hot alcohol free punch with sugar is ready for drinking
1 hot alcohol free punch with sugar is ready for drinking
2 hot alcohol free punch with sugar is ready for drinking