Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 10 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/kXPMD09E)
# Grade 11 Java Review

## Instructions
Expand Down
36 changes: 36 additions & 0 deletions src/gr11review/part1/Review1.java
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
package gr11review.part1;

import java.io.*;

/**
* A program that takes the month number and the day number to calculate
* the amount of days that have passed in the year (assuming no leap year)
*
* @author: R. Shi
*
*/
public class Review1 {
public static void main(String[] args) throws IOException {
// declare reader
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));

// declare variables
int intMonth;
int intMonths[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int intDay;
int intDaynum = 0;

// get variables from user
System.out.print("Enter the month number: ");
intMonth = Integer.parseInt(scan.readLine());
System.out.print("Enter the day number: ");
intDay = Integer.parseInt(scan.readLine());

// add months
for (int i = 0; i < intMonth - 1; i++) {
intDaynum = intDaynum + intMonths[i];
}

// print final result
System.out.println(intDaynum + intDay);
}
}
46 changes: 46 additions & 0 deletions src/gr11review/part1/Review2.java
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
package gr11review.part1;

import java.io.*;

/**
* A simple program to output a joke based on an input between 0-3
*
* @author: R. Shi
*
*/
public class Review2 {
public static void main(String[] args) throws IOException {

// declare reader
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));

// declare variables
int intInput;

// menu choice + get input from user
System.out.println("0 - print a joke about your hair");
System.out.println("1 - print a joke about your feet");
System.out.println("2 - print a joke about your clothes");
System.out.println("3 - print a joke about your teacher");
System.out.print("Choose a menu option: ");
intInput = Integer.parseInt(scan.readLine());

// decision making tree with switch case
switch (intInput) {
case 0:
System.out.println("Why did the barber come first in the race to finish cutting hair the fastest? Because he had taken a short cut!");
break;
case 1:
System.out.println("What's a foot's favourite chocolate? Toe-blerone!");
break;
case 2:
System.out.println("What did the policeman say to the criminal who hid in a laundry basket? You're under a vest!");
break;
case 3:
System.out.println("Teacher: If I had 8 oranges in one hand and 10 apples in the other hand, what would I have? Student: Big hands!");
break;
default:
System.out.println("Invalid menu option");
break;
}
}
}
27 changes: 27 additions & 0 deletions src/gr11review/part1/Review3.java
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
package gr11review.part1;

import java.io.*;

/**
* A simple program to print the odd numbers between 20-100
* then print the numbers between 29-2 in descending order.
*
* @author: R. Shi
*
*/
public class Review3 {
public static void main(String[] args) throws IOException {

// print odd numbers between 20-100
for (int i = 20; i < 100; i++) {
if (i % 2 == 1) {
System.out.println(i);
}
}

// print numbers beteen 29-2 in descending order
System.out.println();
for (int i = 29; i >= 2; i--) {
System.out.println(i);
}
}
}
38 changes: 38 additions & 0 deletions src/gr11review/part1/Review4.java
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
package gr11review.part1;

import java.io.*;
import java.text.DecimalFormat;

/**
* A simple program to take a certain amount of items as well as the price, then
* calculate the subtotal, the tax, and the total of all the items.
*
* @author: R. Shi
*
*/

public class Review4 {
public static void main(String[] args) throws IOException {
// declare reader and format
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat format = new DecimalFormat("0.00");

// declare variables
int intItems;
double dblSubtotal = 0;

// get amount of items from user
System.out.print("How many items do you want to buy? ");
intItems = Integer.parseInt(scan.readLine());

// loop to get each item's price
for (int i = 0; i < intItems; i++) {
System.out.print("Enter the price for item " + (i + 1) + ": ");
dblSubtotal = dblSubtotal + Double.parseDouble(scan.readLine());
}

// print totals
System.out.println("Subtotal: $" + format.format(dblSubtotal));
System.out.println("Tax: $" + format.format(dblSubtotal * 0.13));
System.out.println("Total: $" + format.format(dblSubtotal * 1.13));
}
}
44 changes: 44 additions & 0 deletions src/gr11review/part1/Review5.java
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
package gr11review.part1;

import java.io.*;

/**
* A simple program to compute how many years it takes to earn a certain amount
* of money
* given the interest rate and the yearly invested amount
*
* @author: R. Shi
*
*/
public class Review5 {
public static void main(String[] args) throws IOException {
// declare reader
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));

// declare variables
double dblYearly;
double dblInterest;
double dblTarget;
double dblMoney = 0;
int intYears = 0;

// take variables from user (yearly invested amount, compound interest rate, target amount)
System.out.print("Enter the yearly invested amount: ");
dblYearly = Double.parseDouble(scan.readLine());

System.out.print("Enter the compound interest rate: ");
dblInterest = Double.parseDouble(scan.readLine());

System.out.print("Enter the target amount: ");
dblTarget = Double.parseDouble(scan.readLine());

// while the money is less than the target, simulate a year of interest+investment
while (dblMoney < dblTarget) {
dblMoney = (dblMoney + dblYearly) * (dblInterest / 100 + 1);
intYears = intYears + 1;
}

// print final result
System.out.println("The target amount will be earned in " + intYears + " years.");
}

}
36 changes: 36 additions & 0 deletions src/gr11review/part1/Review6.java
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
package gr11review.part1;

import java.io.*;
import java.text.DecimalFormat;

/**
* A simple program to compute the price, tax, and total after tax of a list of
* items
*
* @author: R. Shi
*
*/
public class Review6 {

public static void main(String[] args) throws IOException {
//
// declare reader
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat format = new DecimalFormat("0.00");

// declare variables
double dblPrice = 0;
double dblSubtotal = 0;

// take input and add it to price until 0 is entered
do {
System.out.print("Enter the price for an item: ");
dblPrice = Double.parseDouble(scan.readLine());
dblSubtotal = dblSubtotal + dblPrice;
} while (dblPrice != 0);

// print results
System.out.println("Subtotal: $" + format.format(dblSubtotal));
System.out.println("Tax: $" + format.format((dblSubtotal * 0.13)));
System.out.println("Total: $" + format.format((dblSubtotal * 1.13)));
}
}
55 changes: 55 additions & 0 deletions src/gr11review/part1/Review7.java
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
package gr11review.part1;

import java.io.*;


/**
* A simple program to count the characters, amount of times the letter a
* appears, and how many spaces are in a string
*
* @author: R. Shi
*
*/

public class Review7 {
public static void main(String[] args) throws IOException {

// declare reader
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));

// declare variables
String strInput;
int intCharacters = 0;
int intSpaces = 0;
int intA = 0;
String strDash = "";

// take sentence from user
strInput = scan.readLine();

// iterate through the string
for (int i = 0; i < strInput.length(); i++) {

// if string at i is "a" count it
if (strInput.substring(i, i + 1).equals("a")) {

intA++;
}
// if string at i is " " count it
if (strInput.substring(i, i + 1).equals(" ")) {

intSpaces++;
}
if (i % 2 == 0) {
strDash = strDash + "-";
}
// count characters
intCharacters++;
}

// print results
System.out.println("There are " + intCharacters + " characters in the sentence.");
System.out.println("There are " + intSpaces + " spaces in the sentence.");
System.out.println("There are " + intA + " letter a in the sentence.");
System.out.println(strDash);
}
}
44 changes: 44 additions & 0 deletions src/gr11review/part1/Review8.java
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
package gr11review.part1;

import java.io.*;
import java.math.*;

/**
* A simple program to simulate 1000 slot pulls from 0-9 with 3 digits, and
* count how many times 3 of the same digit comes up
*
* @author: R. Shi
*
*/
public class Review8 {

public static void main(String[] args) throws IOException {
// declare reader

// declare variables
int int1;
int int2;
int int3;
int intTriple = 0;

// loop 1000 times
for (int i = 0; i < 1000; i++) {

// generate 3 random numbers
int1 = (int) (Math.random() * 10);
int2 = (int) (Math.random() * 10);
int3 = (int) (Math.random() * 10);

// print the 3 random numbers
System.out.println(int1 + " " + int2 + " " + int3);

// if it's a triple count it
if (int1 == int2 && int2 == int3) {
intTriple++;
}
}

// print amount of triples
System.out.println(intTriple);

}
}