// Material from Ch. 4

import java.util.Scanner;

public class Number
{

public static void main(String[] args)
{

// example of roundoff error
double f = 4.35;
System.out.println(100 * f); // doesn't print 435

// assigning an int to a double is OK
int dollars = 100;
double balance = dollars;

// assigning a double to an int requires a cast
balance = 13.75;
dollars = (int) balance; // removes the decimal digits

// integer division:
System.out.println(7 / 4); // prints 1
// avoiding integer division if you don't want it:
System.out.println(7.0 / 4); // or
System.out.println( (double)7 / 4);

// keeping the remainder:
System.out.println(7 % 4); // prints 3

// Strings:

// length method
System.out.println("Metuchen".length());
String town = "Metuchen";
System.out.println(town.length());

// concatenation (nod to 2001 Space Odyssey)
String name = "Dave";
String message = "Hello, " + name;
System.out.println(message);

String a = "Agent";
int n = 7;
String hello = a + n;
System.out.println(hello);

// convert a String to an int
// "17" --> 17
String input = "17";
int count = Integer.parseInt(input);
count++;
System.out.println(count);

// convert a String to a double
// "17.78" --> 17.78
String input2 = "17.78";
double price = Double.parseDouble(input2);
price += 1;
System.out.println(price);

String greeting = "Hello, Metuchen";
String sub1 = greeting.substring(0, 8);
System.out.println(sub1); // prints "Hello, M"

System.out.println(greeting.substring(7)); // prints "Metuchen"

//Using the Scanner class to input and output:

Scanner in = new Scanner(System.in);
System.out.print("Enter quantity: ");
int quantity = in.nextInt();
// the following line is necessary because .nextIt()
// leaves a newline character in the input stream
// Calling nextLine() consumes the newline
in.nextLine();

// in.nextLine() returns up until Enter is hit
System.out.print("Enter city: ");
String city = in.nextLine();

// in.next() returns the first word entered
System.out.print("Enter state code: ");
String state = in.next();
}
}