1) Write a Java program to test a number is positive or negative
import java.util.Scanner;
public class Resolve6_Exercise1 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Input number: ");
int input = in.nextInt();
if (input > 0)
{
System.out.println("Number is positive");
}
else if (input < 0)
{
System.out.println("Number is negative");
}
else
{
System.out.println("Number is zero");
}
}
}
2) Take three numbers from the user and print the greatest number
import java.util.Scanner;
public class Resolve6_Exercise2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input the 1st number: ");
int num1 = in.nextInt();
System.out.print("Input the 2nd number: ");
int num2 = in.nextInt();
System.out.print("Input the 3rd number: ");
int num3 = in.nextInt();
if (num1 > num2)
if (num1 > num3)
System.out.println("The greatest: " + num1);
if (num2 > num1)
if (num2 > num3)
System.out.println("The greatest: " + num2);
if (num3 > num1)
if (num3 > num2)
System.out.println("The greatest: " + num3);
}
}
3) Write a Java Program to produce an invoice for the below items
– Carrots: $2 / lb
– Onions – $4 / lb
– Meat – $10 / lb
a) Ask the customer to how many lbs do they need, and calculate the total
b) Ask the customer if they want to pay cash or card
– If Card, add 13% HST to total
– if Cash, don’t add Tax
c) Display the total amount that customer needs to pay
import java.util.Scanner;
public class Resolve6_Excercise3{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("Did you complete this assignment ? ");
String response = input.next();
if (response.equals("yes")){
System.out.println("Excellent!, You can check your code here on Sunday");
} else if(response.equals("no")) {
System.out.println("No Problem!, Get it done now! ");
} else {
System.out.println("I guess, you did not read the question properly!! ");
}
}
}