work on class 05/05

This commit is contained in:
Rémi Heredero 2022-05-05 16:12:28 +02:00
parent 9a97e6dfbd
commit 608c59d3e3
16 changed files with 183 additions and 10 deletions

14
.vscode/launch.json vendored
View File

@ -1,5 +1,19 @@
{
"configurations": [
{
"type": "java",
"name": "Launch GUI2",
"request": "launch",
"mainClass": "GUI.GUI2",
"projectName": "Lab15_OOP_90898795"
},
{
"type": "java",
"name": "Launch GarageManager",
"request": "launch",
"mainClass": "BillGUI.GarageManager",
"projectName": "Lab15_OOP_90898795"
},
{
"type": "java",
"name": "Launch GUI1",

17
bill.txt Normal file
View File

@ -0,0 +1,17 @@
*************************
* Super Auto 20000 bill ****
*******************************
- Tire replacement 50
- Tire replacement 50
- Tire replacement 50
- Tire replacement 50
- Battery replacement 320
- Brake revision 400
- Oil level control 20
----------------------------------
Bill total 940
----------------------------------
Payment in 30 days. Thank you !

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/GUI/Listener.class Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,10 @@
package BillGUI;
import javax.swing.JFrame;
/**
*
*/
public class ManagerGui extends JFrame{
}

View File

@ -2,7 +2,6 @@ package GUI;
import javax.swing.*;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
@ -10,9 +9,7 @@ import java.awt.event.ActionListener;
public class GUI1 extends JFrame {
public static void main(String[] args) {
GUI1 f1 = new GUI1();
new GUI1();
}
GUI1(){

View File

@ -1,10 +1,80 @@
package GUI;
public class GUI2 {
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.Container;
/**
*
*/
public class GUI2 extends JFrame{
int number;
public static void main(String[] args) {
new GUI2();
}
/**
*
*/
GUI2(){
setSize(200,200);
setLocation(600,200);
Container c = this.getContentPane();
BoxLayout fl = new BoxLayout(c, BoxLayout.Y_AXIS);
c.setLayout(fl);
JSlider js1 = new JSlider(0, 100);
js1.setValue(0);
JProgressBar jp1 = new JProgressBar(0, 100);
JLabel jl1 = new JLabel("waiting");
Listener l = new Listener(jp1, jl1, js1);
js1.addChangeListener(l);
c.add(js1);
c.add(jp1);
c.add(jl1);
this.setVisible(true);
}
}
/**
*
*/
class Listener implements ChangeListener {
JProgressBar jp1;
JLabel jl1;
JSlider js1;
int number = 0;
/**
*
* @param jp1
* @param jl1
* @param js1
*/
Listener(JProgressBar jp1, JLabel jl1, JSlider js1){
this.jp1 = jp1;
this.jl1 = jl1;
this.js1 = js1;
}
/**
*
* @param e
*/
@Override
public void stateChanged(ChangeEvent e) {
number = js1.getValue();
jl1.setText("" + number);
jp1.setValue(number);
}
}

View File

@ -1,12 +1,25 @@
package bank;
/**
* Create a bank account with a balance and a owner
*/
public abstract class BankAccount {
protected double balance;
protected String owner;
/**
* Get balance of the account
* @return the balance of the account
*/
public double getBalance() {
return balance;
}
/**
* Deposit an amount on your account
* Check the amount for accept only positive amount.
* @param amount
*/
public void deposit(double amount){
if(amount<0){
error("cannot deposit this amount !");
@ -14,6 +27,13 @@ public abstract class BankAccount {
}
balance += amount;
}
/**
* Withdraw an amount on your account
* Check the amount for be sure you have this money
* @param amount The amount you want to withdraw
* @return true : if the withdraw has been done
*/
public boolean withdraw(double amount){
if(balance<amount){
return error("cannot withdraw this amount !");
@ -22,13 +42,19 @@ public abstract class BankAccount {
return true;
}
/**
* Explain the problem, if something is wrong
* @param text
* @return the explanation of the problem
*/
protected boolean error(String text){
System.out.println("Problem : " + text);
return false;
}
/**
* Rewrite the bank account to string
*/
@Override
public String toString() {
return owner + " have " + balance + "CHF on his account.";

View File

@ -1,8 +1,18 @@
package bank;
/**
* Create a bank account with specification :
* -
*/
public class Checking extends BankAccount{
private double minBalance;
/**
*
* @param owner
* @param amount
* @param minBalance
*/
protected Checking(String owner, double amount, double minBalance){
if(owner==null){
error("An account have to be an owner");
@ -20,6 +30,11 @@ public class Checking extends BankAccount{
this.balance = amount;
this.minBalance = minBalance;
}
/**
*
* @param minBalance
*/
protected void setMinBalance(double minBalance) {
if(minBalance>0){
error("Min balance can't be positive");
@ -27,10 +42,18 @@ public class Checking extends BankAccount{
}
this.minBalance = minBalance;
}
/**
*
* @return
*/
public double getMinBalance() {
return minBalance;
}
/**
*
*/
@Override
public boolean withdraw(double amount){
if((balance-minBalance)<amount){

View File

@ -3,8 +3,18 @@ package bank;
import hevs.utils.DateUtils;
import java.util.Date;
/**
*
*/
public class Savings extends BankAccount{
private double interestRate;
/**
*
* @param owner
* @param amount
* @param interestRate
*/
protected Savings(String owner, double amount, double interestRate){
if(owner==null){
error("An account have to be an owner");
@ -23,6 +33,12 @@ public class Savings extends BankAccount{
this.interestRate = interestRate;
}
/**
*
* @param a
* @param b
* @return
*/
protected double calcInterest(Date a, Date b){
double days = DateUtils.nDays(a, b);
return balance * interestRate * (days/360.0);