Goal: Discover how to grab user input.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: Asking Questions
/// File Name: AskingQuestions.java
/// Date Finished: Sep. 21, 2015
import java.util.Scanner;
public class AskingQuestions {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int age;
String height;
double weight;
System.out.print("How old are you? ");
age = scanner.nextInt();
System.out.print("How tall are you? ");
height = scanner.next();
System.out.print("How much do you weigh? ");
weight = scanner.nextDouble();
System.out.println("So you're " + age + " years old, " +
height + " tall and " + weight + " pounds.");
}
}
Goal: Experiment more with the Scanner.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: More Questions
/// File Name: MoreQuestions.java
/// Date Finished: Sep. 21, 2015
import java.util.Scanner;
public class MoreQuestions {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What city is the capital of France?");
scanner.next();
System.out.println("What is 6 multiplied by 7?");
scanner.next();
System.out.println("What is your favorite number between 0.0 and 1.0?");
scanner.next();
System.out.println("Is there anything else you would like to tell me?");
scanner.next();
}
}
Goal: Experiment even more with the Scanner.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: Even Moar Questions
/// File Name: RudeQuestions.java
/// Date Finished: Sep. 21, 2015
import java.util.Scanner;
public class RudeQuestions {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name;
int age;
double weight, income;
System.out.println("Hello. What is your name?");
name = scanner.next();
System.out.println("Hi, " + name + "! How old are you?");
age = scanner.nextInt();
System.out.println("So you're " + age + ", eh? That's not old at all.");
System.out.println("How much do you weigh, " + name + "?");
weight = scanner.nextDouble();
System.out.println(weight + "! Better keep that quiet. Finally, what's your income, " + name + "?");
income = scanner.nextDouble();
System.out.println("Hopefully, that is $" + income + " per hour and not per year!");
System.out.println("Well, thanks for answering my rude questions, " + name + ".");
}
}
Goal: Specify some specific information for the user to provide.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: Name, Age, and Salary
/// File Name: NameAgeSalary.java
/// Date Finished: Sep. 21, 2015
import java.util.Scanner;
public class NameAgeSalary {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name;
int age;
double salary;
System.out.println("Hello. What is your name?");
name = scanner.next();
System.out.println("Hi, " + name + "! How old are you?");
age = scanner.nextInt();
System.out.println("So you're " + age + ", eh? That's not old at all!");
System.out.println("How much do you make, " + name + "?");
salary = scanner.nextDouble();
System.out.println("Hopefully, that is $" + salary + " per hour and not per year!");
}
}
Goal: Create a table with user-specified information.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: More User Input
/// File Name: MoreUserInput.java
/// Date Finished: Sep. 22, 2015
import java.util.Scanner;
public class MoreUserInput {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String firstName, lastName, loginName;
int grade, studentId;
double gpa;
System.out.println("Please input the following information:\n");
System.out.print("First Name: ");
firstName = input.next();
System.out.print("Last Name: ");
lastName = input.next();
System.out.print("Grade (9-12): ");
grade = input.nextInt();
System.out.print("Student ID Number: ");
studentId = input.nextInt();
System.out.print("Login Name: ");
loginName = input.next();
System.out.print("GPA (0.0-4.0): ");
gpa = input.nextDouble();
System.out.println("\nYour Information:");
System.out.println("\tLogin: " + loginName);
System.out.println("\tID: " + studentId);
System.out.println("\tName: " + lastName + ", " + firstName);
System.out.println("\tGPA: " + gpa);
System.out.println("\tGrade: " + grade);
}
}
Goal: Do some math with the stored user input.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: Age in 5 Years
/// File Name: AgeIn5Years.java
/// Date Finished: Sep. 22, 2015
import java.util.Scanner;
public class AgeIn5Years {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name;
int age, ageOlder, ageYounger;
System.out.print("Hello! What is your name? ");
name = input.next();
System.out.print("Hello " + name + "! How old are you? ");
age = input.nextInt();
ageOlder = age + 5;
ageYounger = age - 5;
System.out.println("In 5 years, you'll be " + ageOlder + " years old.");
System.out.println("And 5 years ago, you were " + ageYounger + " years old. Wow.");
}
}
Goal: Create a calculator that only does addition.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: A Dumb Calculator
/// File Name: DumbCalculator.java
/// Date Finished: Sep 22, 2015
import java.util.Scanner;
public class DumbCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double num1, num2, num3, result;
System.out.print("What is your first number? ");
num1 = input.nextDouble();
System.out.print("What is your second number? ");
num2 = input.nextDouble();
System.out.print("What is your third number? ");
num3 = input.nextDouble();
result = (num1 + num2 + num3) / 2;
System.out.println("(" + num1 + " + " + num2 + " + " + num3 + ") / 2 = " + result);
}
}
Goal: Create a Body Mass Index (BMI) calculator.
/// Name: Cornelius Eanes
/// Period: 5
/// Program Name: BMI Calculator Part 1
/// File Name: BMICalculator1.java
/// Date Finished: Sep. 22, 2015
import java.util.Scanner;
public class BMICalculator1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double height, weight, bmiValue;
System.out.print("Your height in meters: ");
height = input.nextDouble();
System.out.print("Your weight in kilograms: ");
weight = input.nextDouble();
bmiValue = weight / Math.pow(height, 2.0d);
System.out.println("Your BMI is " + bmiValue);
}
}