Skip to content
Snippets Groups Projects
Commit a23f0103 authored by Andreas's avatar Andreas
Browse files

Made IncomeOverview class with constructor

parent 5b5743a3
No related branches found
No related tags found
1 merge request!4ItemOverview class (with test class)
package no.ntnu.idatt1002.demo;
public class IncomeOverview {
private double income;
private final double fixedIncome;
public IncomeOverview(double fixedIncome){
this.income = fixedIncome;
this.fixedIncome = fixedIncome;
}
}
package no.ntnu.idatt1002.demo;
import no.ntnu.idatt1002.demo.view.MyWindow;
/**
* Use this class to start the application
* @author nilstes
*/
public class MyApp {
/**
* Main method for my application
*/
public static void main(String[] args) throws Exception {
MyWindow window = new MyWindow("The Window");
window.setVisible(true);
}
}
package no.ntnu.idatt1002.demo.data;
import java.util.Date;
import java.util.List;
/**
* This is just a simple Java-bean
* @author nilstes
*/
public class MyEntity {
private String id;
private String name;
public MyEntity() {
}
public MyEntity(String id, String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package no.ntnu.idatt1002.demo.repo;
import no.ntnu.idatt1002.demo.data.MyEntity;
import java.util.Arrays;
import java.util.List;
/**
* Repository for the MyEntity-entity
*
* @author nilstes
*/
public class MyEntityRepo {
/**
* Get object with given id
*
* @param id the entity id
* @return an instance of MyEntity
*/
public MyEntity getMyEntity(String id) {
// Get connection (maybe use pool?)
// Do some SQL
// Return som real data
return new MyEntity("id", "name");
}
public List<MyEntity> findMyEntities(String someParameter) {
// Get connection (maybe use pool?)
// Do some SQL
// Return som real data
return Arrays.asList(new MyEntity("id1", "name1"), new MyEntity("id2", "name2"));
}
public void addMyEntity(MyEntity obj) {
// Get connection (maybe use pool?)
// Do some SQL
}
public void deleteMyEntity(String id) {
// Get connection (maybe use pool?)
// Do some SQL
}
}
package no.ntnu.idatt1002.demo.view;
import no.ntnu.idatt1002.demo.repo.MyEntityRepo;
import no.ntnu.idatt1002.demo.data.MyEntity;
import java.awt.*;
import javax.swing.*;
/**
* Main window for my application!
*
* @author nilstes
*/
public class MyWindow extends JFrame {
/**
* Constructor for window
*
* @param title Title ow the window
* @see Image
*/
public MyWindow(String title) {
super(title);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new GridLayout(1, 1, 1, 1));
MyEntityRepo dao = new MyEntityRepo();
MyEntity object = dao.getMyEntity("id");
add(new JLabel(object.getName()));
pack();
}
}
package no.ntnu.idatt1002.demo.repo;
import no.ntnu.idatt1002.demo.data.MyEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class MyEntityRepoTest {
@Test
public void testThatWeCanReadMyEntityFromDatabase() {
MyEntity e = new MyEntityRepo().getMyEntity("id");
assertEquals(e.getName(), "name");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment