Commit e949f9cd authored by Matthew Burket's avatar Matthew Burket

First and last

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_20]"/>
<classpathentry combineaccessrules="false" kind="src" path="/project2"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>project4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
package lab4;
import java.util.Scanner;
import lab2.Atom;
public class AtomReader
{
public static void main(String[] args)
{
Scanner parser = new Scanner("Uranium,U,92,92,146");
parser.useDelimiter(",");
String name = parser.next();
parser.next(); // skip over the "U", we don't need to save it
int protons = parser.nextInt();
int electrons = parser.nextInt();
int neutrons = parser.nextInt();
System.out.println(name);
Atom atom = new Atom(protons, neutrons, electrons);
System.out.println("Atomic mass: " + atom.getAtomicMass());
}
}
\ No newline at end of file
package lab4;
public class BibItem
{
private String authors;
private String title;
private String journal;
private int year;
private int volume;
public BibItem(String givenAuthors,
String givenTitle,
String givenJournal,
int givenYear,
int givenVolume)
{
authors = givenAuthors;
title = givenTitle;
journal = givenJournal;
year = givenYear;
volume = givenVolume;
}
public String toString() {
return authors.toUpperCase() + ". " + title + ". " + journal + " " + volume + " (" + year + ").";
}
}
package lab4;
import java.util.Scanner;
public class Bibliography {
public static void main(String[] args)
{
String s1 = "Dijkstra, Edsger#Go To Statement Considered Harmful#Communications of the ACM#1968#11";
String s2 = "Levoy, Marc#Display of Surfaces from Volume Data#IEEE Computer Graphics and Applications#1988#8";
String s3 = "Dean, Jeffrey; Ghemawat, Sanjay#MapReduce: Simplified Data Processing on Large Clusters#Communications of the ACM#2008#51";
BibItem item1 = createBibItem(s1);
BibItem item2 = createBibItem(s2);
BibItem item3 = createBibItem(s3);
System.out.println(item1);
System.out.println(item2);
System.out.println(item3);
}
private static BibItem createBibItem(String s)
{
Scanner parser = new Scanner(s);
parser.useDelimiter("#");
BibItem bibItem = new BibItem(parser.next(), parser.next(),parser.next(), parser.nextInt(), parser.nextInt());
return bibItem;
}
}
package lab4;
public class IfState {
public static void main(String[] args) {
int a = 6;
if (a != 5) {
System.out.println("Stuffs");
if (a > 2) {
System.out.println(" More Stuffs");
}
}
}
}
package lab4;
import java.util.Scanner;
public class Multiplier
{
public static void main(String[] args)
{
// Create one scanner to read from System.in
Scanner scanner = new Scanner(System.in);
// Use the helper method to prompt and return the inputs
int first = getNextNumber(scanner);
int second = getNextNumber(scanner);
int result = first * second;
System.out.println(first + " times " + second + " is " + result);
}
// Helper method
private static int getNextNumber(Scanner scanner)
{
System.out.print("Enter a number: ");
int next = scanner.nextInt();
return next;
}
}
\ No newline at end of file
package lab4;
import java.util.Scanner;
public class NumberPower {
public static void main(String[] args) {
// Create one scanner to read from System.in
Scanner scanner = new Scanner(System.in);
// Use the helper method to prompt and return the inputs
int first = getNextNumber(scanner);
int second = getNextNumber(scanner);
double result = Math.pow(first, first);
System.out.println(first + "^" + second + " is " + result);
}
// Helper method
private static int getNextNumber(Scanner scanner)
{
System.out.print("Enter a number: ");
if (scanner.hasNextInt())
{
int next = scanner.nextInt();
System.out.println("Ok, you entered the number " + next);
return next;
}
else
{
String text = scanner.next();
System.out.println("Hmm, " + text + " isn't a number");
return 1;
}
}
}
package lab4;
import java.util.Scanner;
public class ScannerTest
{
public static void main(String[] args)
{
String theInput = "Huey Louie Dewey";
// construct a scanner to read from the string
Scanner in = new Scanner(theInput);
// parse the input to get the three items
String first = in.next();
String second = in.next();
String third = in.next();
// print them out
System.out.println(first);
System.out.println(second);
System.out.println(third);
}
}
\ No newline at end of file
package lab4;
import java.util.Scanner;
public class ScannerTest2
{
public static void main(String[] args)
{
// construct a scanner to read from the console
Scanner in = new Scanner(System.in);
// print a "prompt" so the user knows why the program is waiting
System.out.print("Enter three words separated by spaces: ");
// parse the input to get the three items
String first = in.next();
String second = in.next();
String third = in.next();
// print them out
System.out.println(first);
System.out.println(second);
System.out.println(third);
}
}
package lab4;
import java.util.Scanner;
public class ScannerTest3
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
if (in.hasNextInt())
{
int i = in.nextInt();
System.out.println("Ok, you entered the number " + i);
}
else
{
String text = in.next();
System.out.println("Hmm, " + text + " isn't a number");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment