CS 151 serves as a foundational class to teach students the essentials of programming. The foundational concepts that CS 151 teaches are variables, data types and expressions, assignment, control-flow statements, I/O, exception handling, functions, arrays, and classes.
Here are some examples of the kind of coding that CS 151 entails.
import java.util.*;
public class Midterm1 {
public static void main(String[] args) {
// Jadyn Richardson
// 01221594
System.out.print("How many packages were purchased? ");
Scanner input = new Scanner (System.in);
// variable for the user to input how many products will be purchased
int quantity = input.nextInt();
input.close();
// creating variables for all of the numbers that will be calculated
double discount = 0;
// the price of each item is 99$
double sum = quantity * 99;
double amountDiscounted = 0;
String qualifier = " ";
double discountedSum = 0;
// if the quantity of the items is in between the two specified numbers, the discount variable is set to the specified numbers in the parameters of the project
if(quantity >= 10 && quantity <=19)
discount = .2;
else if (quantity >= 20 && quantity <= 49)
discount = .3;
else if (quantity >= 50 && quantity <= 49)
discount = .4;
else if (quantity >= 100)
discount = .5;
else
discount = 1;
// // the qualifier line is a string that prints out what discount the user will get in percentage form
qualifier = "this purchase qualifies for a " + discount*100 + "% discount ";
// the discounted sum is calculated by taking the sum - (sum * discount)
discountedSum = sum - (sum * discount);
// the amount discounted is the sum * discount
amountDiscounted = (sum * discount);
// printing out results
System.out.println(qualifier);
System.out.println("the total amount of the discount is: " + amountDiscounted);
System.out.println("The total amount of the purchase is: " + discountedSum);
}
}