Problem 1 |
public void between1And100()
{
int num1;
System.out.print("Enter a number from 1 to 100: ");
num1=in.nextInt();
if (1<=num1 & num1<=100)
System.out.print("That number is valid.");
else
System.out.print("That number is not valid.");
} |
Problem 2 |
public void compareNumbers()
{
int num1, num2;
System.out.print("Enter a number: ");
num1=in.nextInt();
System.out.print("Enter another number: ");
num2=in.nextInt();
if (num1>num2)
System.out.print(num1+" is greater than "+num2);
else if(num1<num2)
System.out.print(num1+" is less than "+num2);
else
System.out.print("The numbers are equal.");
} |
Problem 3 |
public void oddOrEven()
{
int ran1, remain;
ran1=(int)(Math.random() *10)+1;
System.out.println("The number chosen by the computer is "+ran1);
remain=ran1%2;
if(remain==0)
System.out.print(ran1+" is an even number.");
else
System.out.print(ran1+" is an odd number.");
} |
Problem 4 |
public void temp()
{
double temp;
System.out.print("Enter the current temperature (Fahrenheit): ");
temp=in.nextDouble();
if(temp<60)
System.out.print("Wear a coat today.");
else
System.out.print("Have a nice day.");
} |
Problem 5 |
public void temp()
{
double temp;
System.out.print("Enter the current temperature (Fahrenheit): ");
temp=in.nextDouble();
if(temp<60 &&temp>=40)
System.out.print("Wear a coat today.");
else if(temp>=90)
System.out.print("Wear your bathing suit.");
else if(temp>=60& temp<90)
System.out.print("Have a nice day.");
else
System.out.print("Wear your winter coat.");
} |
Problem 6 |
public void squareArea()
{
int num1, area;
System.out.print("Enter a positive whole number: ");
num1=in.nextInt();
area=num1*num1;
if (num1>=1)
System.out.print("The area of the square is "+area+" units.");
else
System.out.print("Invalid entry.");
} |
Problem 7 |
public void rectangleArea()
{
int num1, num2, area;
System.out.print("Enter a positive integer: ");
num1=in.nextInt();
System.out.print("Enter another positive integer: ");
num2=in.nextInt();
area=num1*num2;
if (num1>=1 && num2>=1)
System.out.print("The area of the rectangle is "+area+" square units.");
else if(num1>=1 && num2<=0)
System.out.print("There is one invalid integer.");
else if(num1<=0 && num2>=1)
System.out.print("There is one invalid integer.");
else
System.out.print("The numbers entered are invalid.");
} |
Problem 8 |
public void calcDiscriminant()
{
int a, b, c, answer;
System.out.print("Enter a value for a: ");
a=in.nextInt();
System.out.print("Enter a value for b: ");
b=in.nextInt();
System.out.print("Enter a value for c: ");
c=in.nextInt();
answer=(b*b)-(4*a*c);
if (answer>=1)
System.out.print("a= "+a+", b= "+b+", c= "+c+", the discriminant= "+answer+" and has Two Roots.");
else if(answer<=-1)
System.out.print("a= "+a+", b= "+b+", c= "+c+", the discriminant= "+answer+" and has No Roots.");
else
System.out.print("a= "+a+", b= "+b+", c= "+c+", the discriminant= "+answer+" and has One Roots.");
} |
Problem 9 |
public void calcGrade()
{
int grade;
System.out.print("Enter a grade (0-100): ");
grade=in.nextInt();
if (grade<60)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of F.");
}
else if (grade>=60&&grade<=69)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of D.");
}
else if (grade>=70&&grade<=79)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of C.");
}
else if (grade>=80&&grade<=89)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of B.");
}
else
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of A.");
}
}
|
Problem 10 |
public void calcGrade()
{
int grade;
System.out.print("Enter a grade (0-100): ");
grade=in.nextInt();
if (grade<60)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of F.");
}
else if (grade>=60&&grade<=63)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of D-.");
}
else if (grade>=64&&grade<=66)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of D.");
}
else if (grade>=67&&grade<=69)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of D+.");
}
else if (grade>=70&&grade<=73)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of C-.");
}
else if (grade>=74&&grade<=76)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of C.");
}
else if (grade>=77&&grade<=79)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of C+.");
}
else if (grade>=80&&grade<=83)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of B-.");
}
else if (grade>=84&&grade<=86)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of B.");
}
else if (grade>=87&&grade<=89)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of B+.");
}
else if (grade>=90&&grade<=93)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of A-.");
}
else if (grade>=94&&grade<=96)
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of A.");
}
else
{
System.out.println("The grade you entered was "+grade);
System.out.print("You have earned a letter grade of A+.");
}
}
} |
Problem 11 |
public class Problem_11
{
public void packageCalc()
{
int length, width, height;
System.out.print("Enter a package length(cm): ");
length=in.nextInt();
System.out.print("Enter a package width(cm): ");
width=in.nextInt();
System.out.print("Enter a package height(cm): ");
height=in.nextInt();
if (length<=10 && height<=10 && width<=10)
System.out.print("Package Accepted.");
else
System.out.print("Package Rejected.");
}
} |
Problem 12 |
public class Problem_12
{
public void wageCalc()
{
double hour, rate, wage;
System.out.print("Enter the number of hours worked: ");
hour=in.nextDouble();
System.out.print("Enter the hourly rate: $");
rate=in.nextDouble();
if (hour<=40)
{
wage=rate*hour;
System.out.print("Wages earned= "+wage);
}
else
{
wage=(hour-40)*rate*1.5+40*rate;
System.out.print("Wages earned= "+wage);
}
}
|
Problem 13 |
public void calcPay()
{
double hours, rate, wage,tax;
String exempt;
System.out.print("Enter hours worked: ");
hours=in.nextDouble();
System.out.print("Enter hourly rate: $");
rate=in.nextDouble();
System.out.print("Exempt? (Y/N): ");
exempt=in.next();
if(hours<40 && exempt.compareToIgnoreCase("y")==0)
{
wage=hours*rate;
wage=Math.round(wage*100.0)/100.0;
System.out.println("Wages earned= "+wage);
System.out.print("No Taxes Deducted");
}
else if (hours<40)
{
tax=hours*rate*.18;
tax=Math.round(tax*100.0)/100.0;
wage=(hours*rate)-tax;
wage=Math.round(wage*100.0)/100.0;
System.out.println("Wages earned= "+wage);
System.out.print("Taxes deducted= "+tax);
}
else if (hours>40 && (exempt.compareToIgnoreCase("y")==0))
{
wage=((hours-40) * 1.5 * rate)+(40*rate);
wage=Math.round(wage*100.0)/100.0;
System.out.println("Wages earned= "+wage);
System.out.print("No Taxes Deducted");
}
else
{
wage=((hours-40) * 1.5 * rate)+(40*rate);
tax=wage*.18;
wage=wage-tax;
wage=Math.round(wage*100.0)/100.0;
System.out.println("Wages earned= "+wage);
System.out.print("Taxes deducted= "+tax);
}
} |
Problem 14 |
public void nameCompare()
{
String name1, name2;
System.out.print("Enter a name: ");
name1=in.next();
System.out.print("Enter another name: ");
name2=in.next();
if(name1.compareTo(name2)< 0)
System.out.println(name1+" comes before "+name2+" alphabetically.");
else if(name1.compareTo(name2)>0)
System.out.println(name1+" comes after "+name2+" alphabetically.");
else
System.out.println("These names are the same. Nice one, Einstein.");
} |
Problem 15 |
public void batMan()
{
String word;
System.out.print("Enter a word (first letter capitalized): ");
word=in.next();
if (word.compareTo("Bat")>0 && word.compareTo("Man")<0)
System.out.print("Is between.");
else
System.out.print("Is not between.");
} |
Problem 16 |
public void vowelOrConsonant()
{
String letter;
System.out.print("Enter a letter: ");
letter=in.next();
if (letter.compareToIgnoreCase("A")==0||
letter.compareToIgnoreCase("E")==0||
letter.compareToIgnoreCase("O")==0||
letter.compareToIgnoreCase("U")==0||
letter.compareToIgnoreCase("I")==0)
System.out.print(letter+" is a vowel.");
else
System.out.print(letter+" is a consonant.");
} |
Problem 17 |
public void fruit()
{
int num;
System.out.print("Enter a number from 1 to 5: ");
num=in.nextInt();
switch(num)
{
case 1:
System.out.println("You will eat a pomegranate.");
break;
case 2:
System.out.println("You will eat an orange.");
break;
case 3:
System.out.println("You will eat a banana.");
break;
case 4:
System.out.println("You will eat a peach.");
break;
case 5:
System.out.println("You will eat an apple.");
break;
default:
System.out.println("That is an invalid response.");
}
} |
|
|
|