Tutorial 3

This commit is contained in:
Marcus Vinicius de Carvalho 2024-09-17 16:51:06 +08:00
parent 5a81a04720
commit fe957201e3
10 changed files with 179 additions and 0 deletions

11
T3Q1-1/T3Q1-1.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,78 @@
import java.util.Scanner;
public class VendingMachine {
public VendingMachine() {}
public double selectDrink() {
Scanner sc = new Scanner(System.in);
int drinkSelection;
double drinkCost = 0;
System.out.println("====== Vending Machine ======");
System.out.println("|1. Buy Beer ($3.00) |");
System.out.println("|2. Buy Coke ($1.00) |");
System.out.println("|3. Buy Green Tea ($5.00) |");
System.out.println("|============================");
do {
System.out.println("Please enter selection: ");
drinkSelection = sc.nextInt();
} while (drinkSelection < 1 || drinkSelection > 3);
if (drinkSelection == 1) drinkCost = 3.00;
else if (drinkSelection == 2) drinkCost = 1.00;
else if (drinkSelection == 3) drinkCost = 5.00;
return drinkCost;
}
public double insertCoins(double drinkCost) {
double amount = 0.0;
Scanner sc = new Scanner(System.in);
System.out.println("Please insert coins: ");
System.out.println("========== Coins Input ===========");
System.out.println("|Enter 'Q' for ten cents input |");
System.out.println("|Enter 'T' for twenty cents input|");
System.out.println("|Enter 'F' for fifty cents input |");
System.out.println("|Enter 'N' for a dollar input |");
System.out.println("==================================");
do {
char coin = sc.next().charAt(0);
switch (coin)
{
case 'Q': case 'q':
amount += 0.10;
break;
case 'T': case 't':
amount += 0.20;
break;
case 'F': case 'f':
amount += 0.50;
break;
case 'N': case 'n':
amount += 1.00;
break;
}
System.out.printf("Coins inserted: %.2f \n", amount);
} while (amount < drinkCost);
return amount;
}
public void checkChange(double amount, double drinkCost)
{
double change = 0.0;
if (amount > drinkCost)
{
change = amount - drinkCost;
System.out.printf("Change $ %.2f \n", change);
}
}
public void printReceipt()
{
System.out.println("Please collect your drink");
System.out.println("Thank you!!");
}
}

11
T3Q1-2/T3Q1-2.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T3Q1-3/T3Q1-3.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T3Q1-4/T3Q1-4.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

13
T3Q2-1/src/Point.java Normal file
View File

@ -0,0 +1,13 @@
public class Point {
protected int x, y;
public Point() { x = 0; y = 0; }
public Point(int x, int y) { this.x = x; this.y = y; }
public void setPoint(int x, int y) { this.x = x; this.y = y; }
public int getX() { return x; }
public int getY() { return y; }
public String toString() { return "[" + x + "," + y + "]"; }
}

11
T3Q2-2/T3Q2-2.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T3Q2-3/T3Q2-3.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T3Q2-4/T3Q2-4.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>