Compare commits
2 Commits
d114f8c9ec
...
03c9193168
Author | SHA1 | Date | |
---|---|---|---|
03c9193168 | |||
63531fb46c |
45
StudentClass/Student.java
Normal file
45
StudentClass/Student.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Build Student Class
|
||||||
|
* Private fields
|
||||||
|
* *String name default to Louie
|
||||||
|
* *double gpa default to 1.0
|
||||||
|
*
|
||||||
|
* Default constructor
|
||||||
|
*
|
||||||
|
* Public member methods
|
||||||
|
**setName() & getName()
|
||||||
|
**setGPA() & getGPA()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Comments for submission
|
||||||
|
*
|
||||||
|
* It was certainly a bit of a refresher to go back and review
|
||||||
|
* how classes work in Java. However, no problems. Easy peasy.
|
||||||
|
* */
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
private String name;
|
||||||
|
private double gpa;
|
||||||
|
|
||||||
|
public Student() {
|
||||||
|
this.name="Louie";
|
||||||
|
this.gpa = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getName(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGPA(double gpa){
|
||||||
|
this.gpa = gpa;
|
||||||
|
}
|
||||||
|
public double getGPA(){
|
||||||
|
return this.gpa;
|
||||||
|
}
|
||||||
|
}
|
13
StudentClass/fuck.java
Normal file
13
StudentClass/fuck.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
public class fuck {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Student jack = new Student();
|
||||||
|
|
||||||
|
System.out.println(jack.getGPA());
|
||||||
|
jack.setGPA(2.0);
|
||||||
|
System.out.println(jack.getGPA());
|
||||||
|
|
||||||
|
System.out.println(jack.getName());
|
||||||
|
jack.setName("fart");
|
||||||
|
System.out.println(jack.getName());
|
||||||
|
}
|
||||||
|
}
|
53
old/output-below-amount/outputBelowAmount.java
Normal file
53
old/output-below-amount/outputBelowAmount.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
/*
|
||||||
|
* Get list of ints
|
||||||
|
* first number is number of ints, never above 20
|
||||||
|
* print out all ints that are <= to last int
|
||||||
|
*
|
||||||
|
* input: 5 50 60 140 200 75 100
|
||||||
|
*
|
||||||
|
* output: 50 60 75
|
||||||
|
* for simplicity, all numbers should be followed by a space
|
||||||
|
* even the last one
|
||||||
|
*
|
||||||
|
* Use two methods:
|
||||||
|
*
|
||||||
|
* public static void getUserValues(int[] myArr, int arrSize, Scanner scnr)
|
||||||
|
*
|
||||||
|
* public static void outputIntsLessThanOrEqualToThreshold
|
||||||
|
* (int[] userValues, int userValsSize, int upperThreshold)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class outputBelowAmount{
|
||||||
|
|
||||||
|
public static void getUserValues(int[] myArr, int arrSize, Scanner scnr){
|
||||||
|
|
||||||
|
for (int i=0;i<arrSize;i++){
|
||||||
|
myArr[i] = scnr.nextInt();
|
||||||
|
}
|
||||||
|
myArr[arrSize+1] = scnr.nextInt();
|
||||||
|
|
||||||
|
outputIntsLessThanOrEqualToThreshold(myArr, arrSize, myArr[arrSize+1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void outputIntsLessThanOrEqualToThreshold
|
||||||
|
(int[] userValues, int userValsSize, int upperThreshold){
|
||||||
|
for(int i = 0; i<userValsSize; i++){
|
||||||
|
if (userValues[i] <= upperThreshold){
|
||||||
|
System.out.print(userValues[i] + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scnr = new Scanner(System.in);
|
||||||
|
|
||||||
|
int arrSize = scnr.nextInt();
|
||||||
|
int[] myArr = new int[20];
|
||||||
|
|
||||||
|
getUserValues(myArr, arrSize, scnr);
|
||||||
|
|
||||||
|
scnr.close();
|
||||||
|
}
|
||||||
|
}
|
76
productClass/Product.java
Normal file
76
productClass/Product.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Given main(), define the Product class that will manage
|
||||||
|
* product inventory
|
||||||
|
*
|
||||||
|
* three private member fields
|
||||||
|
* *productCode (String)
|
||||||
|
* *productPrice (double)
|
||||||
|
* *productInInventory (int)
|
||||||
|
*
|
||||||
|
* public Product(String code, double price, int count)
|
||||||
|
* ** Set the member fields using the three params
|
||||||
|
*
|
||||||
|
* public void setCode(String code)
|
||||||
|
* ** Set the product code to parameter code
|
||||||
|
*
|
||||||
|
* public String getCode() -- return product code
|
||||||
|
*
|
||||||
|
* public void setPrice(double p) - set price to parameter p
|
||||||
|
*
|
||||||
|
* public double getPrice() -- return price
|
||||||
|
*
|
||||||
|
* public void setCount(int num)
|
||||||
|
* **set the number of items in inventory to parameter num
|
||||||
|
*
|
||||||
|
* public int getCount() -- return count
|
||||||
|
*
|
||||||
|
* public void addInventory(int amt) - increase inventory by amt
|
||||||
|
* public void sellInventory(int amt) - decrease inv by amt
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Lots of stuff in this assignment on black board all run together
|
||||||
|
// somewhat hard to review and be sure I noticed everything.
|
||||||
|
// it's also not clear what
|
||||||
|
// "Given main(), define the Product class..."
|
||||||
|
// I'm reading that as, I don't have to write a main file (except to test)
|
||||||
|
// Though, it makes me think I should have some main file available to me.
|
||||||
|
//
|
||||||
|
// So, I wrote a main file for myself to do the printing for testing that
|
||||||
|
// outputs as in the example. And as instructed, I'll only upload my class code
|
||||||
|
|
||||||
|
public class Product {
|
||||||
|
private String code;
|
||||||
|
private double price;
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public Product (String code, double price, int count){
|
||||||
|
this.code = code;
|
||||||
|
this.price = price;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
public void setCode(String code){
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
public String getCode(){
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
public void setPrice(double price){
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
public double getPrice(){
|
||||||
|
return this.price;
|
||||||
|
}
|
||||||
|
public void setCount(int count){
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
public int getCount(){
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
public void addInventory(int amt){
|
||||||
|
this.count += amt;
|
||||||
|
}
|
||||||
|
public void sellInventory(int amt){
|
||||||
|
this.count -= amt;
|
||||||
|
}
|
||||||
|
}
|
22
productClass/testProduct.java
Normal file
22
productClass/testProduct.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
public class testProduct {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Product jeans = new Product("jeans", 12.34, 75);
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Name: " + jeans.getCode() +
|
||||||
|
"\nPrice: " + jeans.getPrice() +
|
||||||
|
"\nCount: " + jeans.getCount());
|
||||||
|
jeans.setCode("New Jeans");
|
||||||
|
jeans.setPrice(10.0);
|
||||||
|
jeans.addInventory(5);
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Name: " + jeans.getCode() +
|
||||||
|
"\nPrice: " + jeans.getPrice() +
|
||||||
|
"\nCount +5 : " + jeans.getCount());
|
||||||
|
jeans.sellInventory(20);
|
||||||
|
System.out.println(
|
||||||
|
"Count -20 : " +jeans.getCount());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user