[go: up one dir, main page]

0% found this document useful (0 votes)
72 views7 pages

Lab 16

This document provides instructions for a programming assignment to create a Java application to calculate depreciation of fixed assets. It includes requirements to create classes for a Company with Assets, and subclasses for Machine and Vehicle assets that use different depreciation methods. It provides details on class structure, methods, and a tester code sample to display results in a GUI. The application must recalculate values when pressing "Last Year" or "Next Year" buttons.

Uploaded by

藍翊齊
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views7 pages

Lab 16

This document provides instructions for a programming assignment to create a Java application to calculate depreciation of fixed assets. It includes requirements to create classes for a Company with Assets, and subclasses for Machine and Vehicle assets that use different depreciation methods. It provides details on class structure, methods, and a tester code sample to display results in a GUI. The application must recalculate values when pressing "Last Year" or "Next Year" buttons.

Uploaded by

藍翊齊
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming Language II 111-2

DpaLab 16
Requirements:
● Create a Java project named StudentId_Lab16
● Read instructions and create classes needed.
● All instance variables are private. Please use public methods to access private instance variables.

Description:
In the accounting field, there are many methods for calculating the depreciation (折舊)of fixed assets.
Now, you have to develop a system for calculating depreciation and the book value (帳面價值) of fixed
assets. The company currently only has two major assets, Machine and Vehicle, and they use double
declining balance depreciation method (雙倍餘額遞減法)and straight-line method (直線折舊)to
depreciate, respectively.

* Please use the GUI to display the results.


*折舊:固定資產因使用耗損而損失的價值
*帳面價值:原始價值 - 折舊

Figure 1. The UML diagram of the exercise problem

1
Programming Language II 111-2

* You should have all the methods below, but you can add anything you want.

1. Create Company class


Company

Return type Method or Variable description

Instance variable

String name Company name.

int year Current year. (init = 1)

double bookValue Book value of the total assets.

double depreciation Depreciation of the current year.

ArrayList assets All fixed assets in the company.


<FixedAsset>

Methods

Company(String name) This is the constructor of the class.

void addFixedAsset Add the new fixed asset into class.


(FixedAsset asset)

2. Create FixedAsset class (interface)


FixedAsset

Return type Method or Variable description

Abstract methods

void calcDepreciation(int year) Calculate the depreciation of the given year.

double getDepreciation() Return the depreciation.

double getValue() Return the original value of the fixed asset.

3. Create Machine class


Machine

Return type Method or Variable description

Instance variable

int durableYear The durable year of the machine.


2
Programming Language II 111-2

double residualValue The residual value of the machine.

double value The initial value of the machine

double depreciation The depreciation of the current year.

Methods

Machine(int durableYear, This is the constructor of the class.


double residualValue,
double value)

void calcDepreciation(int year) Formula of the depreciation rule:


depreciation = (value – residual value) / durable year

4. Create Vehicle class


Vehicle

Return type Method or Variable description

Instance variable

int durableYear The durable year of the vehicle.

double residualValue The residual value of the vehicle.

double value The initial value of the vehicle.

double depreciation The depreciation of the current year.

double deRate The depreciation rate of the vehicle.

Methods

Vehicle(int durableYear, This is the constructor of the class.


double residualValue,
double value)

void calcDepreciationRate() Formula of depreciation rate:


depreciation rate = (1 / durable year) * 2

void calcDepreciation(int year) Formula of the depreciation:


*Vehicle have to calculate depreciation rate first.
if the current year same as the durable year:
depreciation = (value – residual value) / durable year

3
Programming Language II 111-2

Otherwise:
depreciation = residual Value * depreciation Rate

4
Programming Language II 111-2

The main method in Lab16 class

Tester code below has set up the frame, two fixed assets, and all the components in GUI.
You have to implement the other things below:

• In the initial year, you have to print total book values.


• “Next Year” will increase the year by 1. “Last Year” will reduce the year by 1.
• After pressing the button, you should recalculate the depreciation of this year and the current
book value according to the formula defined above.
• Please round all double values to the second decimal place.
• Using the inner-class concept to implement the ActionListener interface.

Sample output #1 Sample output #2

Sample output #3 Sample output #4

Submission: Submit your project as “.zip file” via Moodle. No other submissions will be graded.
Reminder: Please zip the whole project
Deadline: Tomorrow’s midnight (for both Mon56 and Tue23)

5
Programming Language II 111-2

class Lab16
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Tester {

public static void main(String[] args) {

Company company = new Company("NCCU");


company.addFixedAsset(new Machine(8, 420, 1000));
company.addFixedAsset(new Vehicle(6, 300, 1000));

JFrame frame = new JFrame();


JLabel yearLabel = new JLabel("Year");
JLabel year = new JLabel(String.format("%d", company.getYear()));
JLabel depreciationLabel = new JLabel("This year depreciation");
JLabel depreciation = new JLabel(String.format("%.2f", company.getDepreciation()));
JLabel valueLabel = new JLabel("Book value");
JLabel bookValue = new JLabel(String.format("%.2f", company.getBookValue()));

JButton button1 = new JButton("Last year");


JButton button2 = new JButton("Next Year");

frame.setTitle(company.getName());

frame.setLayout(new GridLayout(4, 2));


frame.add(yearLabel);
frame.add(year);
frame.add(depreciationLabel);
frame.add(depreciation);
frame.add(valueLabel);
frame.add(bookValue);
frame.add(button1);
frame.add(button2);

class LastListener implements ActionListener{


public void actionPerformed(ActionEvent e) {
///////////////////////
// Here is your code //
///////////////////////
}
}

class NextListener implements ActionListener{


public void actionPerformed(ActionEvent e) {
///////////////////////
// Here is your code //
///////////////////////
}
}

6
Programming Language II 111-2

button1.addActionListener(new LastListener());
button2.addActionListener(new NextListener());

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

You might also like