Week 3
Week3.java
import java.util.*;
public class Week3 {
public static void main(String[] args) {
String first_name = ""; // add your first name
System.out.println("Week 3 - " + first_name);
// Example 1
// Example 2
// Example 3
// Example 4
// Example 5
// Example 6
// Example 7
}
}
ScannerExample.java
// import all the classes and interfaces from the java.util package into your program.
import java.util.*;
public class ScannerExample {
public static void main(String[] args) {
System.out.println("Scanner Example Code");
// 1. Print a message to the user
// 2. Initialize the Scanner. Declare a variable named in
// that reads from System.in
// 3. Create a variable and assign it to the value returned by nextLine
// The Scanner class provides a method called nextLine that reads a
// line of input from the keyboard and returns a String.
// 4. Print the value of the variable
// 5. Close the Scanner
}
}
ScannerExample2.java
import java.util.*;
public class ScannerExample2 {
public static void main(String[] args) {
System.out.println("Scanner Example 2 Code");
Scanner in = new Scanner(System.in);
System.out.print("What's your age? ");
int age = in.nextInt();
// add code to fix the "Scanner bug"
System.out.print("What's your name? ");
String line = in.nextLine();
System.out.println("Name: " + line);
System.out.println("Age: " + age);
in.close();
}
}
TipCalculator.java
import java.util.*;
public class TipCalculator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the total bill amount: ");
System.out.println("Bill Amount: $");
System.out.println("Tip (15%): $");
System.out.println("Total Amount: $");
}
}
CurrencyConverter.java
import java.util.*;
public class CurrencyConverter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter amount in USD: ");
System.out.println("Amount in EUR £: ");
System.out.println("Amount in GBP €: ");
System.out.println("Amount in JPY ¥: ");
}
}
CompoundInterestCalculator.java
import java.util.*;
public class CompoundInterestCalculator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the principal amount: ");
System.out.print("Enter the annual interest rate (in decimal): ");
System.out.print("Enter the number of years: ");
System.out.println("The amount after " + " years is: ");
}
}
Problem 4
import java.util.*;
public class W3Problem4 {
public static void main(String[] args) {
System.out.println("Problem 4");
Scanner in = new Scanner(System.in);
}
}
Problem 5
import java.util.*;
public class W3Problem5 {
public static void main(String[] args) {
System.out.println("Problem 5");
Scanner in = new Scanner(System.in);
}
}
Problem 6
import java.util.*;
public class W3Problem6 {
public static void main(String[] args) {
System.out.println("Problem 6");
Scanner in = new Scanner(System.in);
}
}
Problem 7
import java.util.*;
public class W3Problem7 {
public static void main(String[] args) {
System.out.println("Problem 7");
Scanner in = new Scanner(System.in);
}
}
Problem 8
import java.util.*;
public class W3Problem8 {
public static void main(String[] args) {
System.out.println("Problem 8");
Scanner in = new Scanner(System.in);
}
}
Last updated
Was this helpful?