Ss mwwamm m Java gx

// EX03 02 // Employee.java package _objects; public class Employee { private String name; private String sex; static class Fee {

public static float BasicFee; public static float Discount; public static float GetTotal(){ return BasicFee * Discount; }

public Employee(String na, String sx) { name = na; sex = sx; } public void SetFee(float basic_fee, float disc) { Fee.BasicFee = basic_fee; Fee.Discount = disc; } public void Display() { System. out.println(name + "'s fee: " + Fee.GetTotal());}

// Customer.java package _objects; public class Customer { private String name; private String sex; static class Fee {

public static float AnnualFee;

public static f oat Discount; public static float GetTotal()

{ returnAnnualFee * 32.25f * Discount; }

public Customer(String na, String sx)

{ name = na; sex = sx; } public void SetFee(float annual_fee, float disc) { FeeAnnualFee = annual_fee / 32.25f; // Convert to US$ to NT$ Fee.Discount = disc;

public void Display()

{ System.out.println(name + "'s fee: " + Fee.GetTotal()); }

// JMain.java import _objects.*; public class JMain {

public static void main(String[] args) {

Employee emp = new Employee("Tom", "M");

Customer cust = new Customer("Lily", "F");

emp.SetFee(1000f, 0.9f);

cust.SetFee(500f, 0.75f);

emp.Display();

cust.Display();

ftfM^ftm:

Employee M Customer ^ > IftMAf^ffiM

public class Employee { private String name; private String sex; ststic class Fee { public static float BasicFee; public static float Discount; public static float GetTotal() { return BasicFee * Discount

public class Customer { private String name; private String sex; static class Fee { public static float AnnualFee; public static float Discount; public static float GetTotal() {

return BasicFee * 32.25 * Discount

public class Person {

private String name; private String sex;

// EX03 03 // Person.java package _objects; public class Person {

protected String name; protected String sex;

// Employee.java package _objects;

public class Employee extends Person{ static class Fee {

public static float BasicFee; public static float Discount;

public static float GetTotal() { return BasicFee * Discount; }

public Employee(String na, String sx){ name = na; sex = sx; } public void SetFee(float basic_fee, float disc) { Fee. BasicFee = basic_fee; Fee.Discount = disc; } public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal()); }

// Customer.java package _objects;

public class Customer extends Person { static class Fee {

public static float AnnualFee; public static float Discount; public static float GetTotal() { return AnnualFee

public Customer(String na, String sx){ name = na; public void SetFee(float annual_fee, float disc){ FeeAnnualFee = annual_fee / 32.25f; // Convert to US$ to NT$

Fee.Discount = disc;

public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal()); }

// JMain.java import _objects.*; public class JMain {

public static void main(String[] args) {

Employee emp = new Employee("Tom'

, "M");

Customer cust = new Customer("Lily",

"F");

emp.SetFee(1000f, 0.9f);

cust.SetFee(500f, 0.75f);

emp.Display();

cust.Display();

}}

Java fMA :

// EX03 04 // Person.java package _objects; public class Person {

protected String name; protected String sex; public Person(String na, String sx) { name = na; sex = sx; }

// Employeejava package _objects;

public class Employee extends Person{ static class Fee {

public static float BasicFee; public static float Discount; public static float GetTotal()

{ return BasicFee * Discount; }

public Employee(String na, String sx) { super(na, sx); } public void SetFee(float basic_fee, float disc){ Fee.BasicFee = basic_fee; Fee.Discount = disc; } public void Display(){ System.out.println(name + "'s fee: " + Fee.GetTotal()); }

// Customer.java package _objects;

public class Customer extends Person { static class Fee {

public static float AnnualFee; public static float Discount;

public static float GetTotal(){ return AnnualFee * 32.25f * Discount; }

public Customer(String na, String sx) { super(na, sx); } public void SetFee(float annual_fee, float disc) {

FeeAnnualFee = annual_fee / 32.25f; // Convert to US$ to NT$

Fee.Discount = disc;

public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal()); }

// JMain.java import _objects.*; public class JMain {

public static void main(String[] args) {

Employee emp = new Employee("Tom", "M");

Customer cust = new Customer("Lily", "F");

emp.SetFee(1000f, 0.9f);

cust.SetFee(500f, 0.75f);

emp.Display();

cust.Display();

nmrn&n ■ mnmmmmm fia-niAAiHMs^M! m

MfflMMTO Java g^ffiM :

AA BB

private String x; public void Print() {

System. out. println(x);

private int x; public void Print() { System.out.println(x);

System.out.println( x );

System.out.println( x ); End Sub

aa m bb m private String x; public final void Print() { System.out.println(GetData());

public String GetData() { return x;

private int x; public final Print() { System. out.println(GetD ata());

public String GetData() { return String.valueOf(x);

Pnnt()®mürami£7 ' ^mxm^mm^ W&mfä GetData()Ö^

SuperAB

pubic final void Print() {

System.out.println( GetData() );

public String GetData() {}

private String x;

public String GetData() { return x;

private int x;

public String GetData() { return String.valueOf(x);

public String GetData(){}

public abstract String GetData();

// EX03 05

// JMain.java

package _objects;

public class JMain {

private void print(double x, int y) {

System.out.println(x+y); }

private void print(int k, int y) {

System.out.println(k*y); }

public static void main(String[] args) {

JMain mObj = new JMain();

mObj.print(3.6, 6);

mObj .print(2, 60);

}}

public void print( Number numb, int y ) {

step-2b mmmmmmmmm^&mm^ • Mm • a prstro®»^£

public void print( Number numb, int y) {

System.out.println( numb.prStr(y) );

public abstract class Number { public abstract String prStr(int y); }

// jvIntjava package _objects; public class jvInt extends Number{ private int x;

public String prStr(int y) { return String.valueOf x * y ); }

//jvFloatjava package _objects;

public class jvFloat extends Number {

private float x;

public String prStr(int y) { return String. valueOf(x + y); }

// JMain.java import _objects.*; import _objects.Number; public class JMain {

private void print(Number numb, int y) { System.out.println(numb.prStr(y)); } public static void main(String[] args) { JMain mObj = new JMain(); jvFloat a = new jvFloat(3.6f); jvInt b = new jvInt(2); mObj.print(a, 6); mObj.print(b, 60);

// EX03 07 // Number.java package _objects; public abstract class Number {

public abstract String prStr(int y);

public void print(int y) { System.out.println( this.prStr(y) ); }

// jvlnt.java package _objects; public class jvInt extends Number{ private int x;

public String prStr(int y) { return String.valueOf(x * y); }

//jvFloat.java package _objects;

public class jvFloat extends Number {

private float x;

public String prStr(int y) { return String.valueOfx + y); }

// JMain.java import _objects.*; import _objects.Number; public class JMain {

public static void main(String[] args) { JMain mObj = new JMain(); jvFloat a = new jvFloat(3.6f); jvInt b = new jvInt(2); mObj.print(a, 6);

SA ' MSm® EX03-04 lAMM! iilflilSiBtl^fi^K : public class Employee {

public void Display() {

System.out.println(name + "'s fee: " + Fee.GetTotal()); }

ffi public class Customer {

public void Display(){

System.out.println(name + "'s fee: " + Fee.GetTotal()); }

MffiB^A Employee.Fee ^m® Customer.Fee ^mi&AWMATO ' gffi

S^jt . a^Mfi Fee.GetTotal()gffi®Ajt = @A ' Display()Xt£EMA

Wa^mA ° SA^A—fi Overridable ' ©«ffiSfi . ^fgA =

// EX03 08 // Person.java package _objects; public class Person {

protected String name; protected String sex;

public Person(String na, String sx) { name = na; sex = sx; }

// Employee.java package _objects;

public class Employee extends Person{ static class Fee {

public static float BasicFee; public static float Discount;

public static float GetTotal(){ return BasicFee * Discount; }

public Employee(String na, String sx){ super(na, sx); } public void SetFee(float basic_fee, float disc){ Fee.BasicFee = basic_fee; Fee.Discount = disc;

public void Display() {

System.out.println(name + "'s fee: " + Fee.GetTotal());

// Customer.java package _objects;

public class Customer extends Person { static class Fee {

public static float AnnualFee; public static float Discount;

public static float GetTotal(){ return AnnualFee * 32.25f * Discount; }

public Customer(String na, String sx) { super(na, sx); } public void SetFee(float annual_fee, float disc) { FeeAnnualFee = annual_fee / 32.25f; // Convert to US$ to NT$

Fee.Discount = disc;

public void Display() {

System.out.println(name + "'s fee: " + Fee.GetTotal());

// JMain.java import _objects.*; public class JMain {

public static void main(String[] args) {

Employee emp = new Employee("Tom"

, "M");

Customer cust = new Customer("Lily",

'F");

emp.SetFee(1000f, 0.9f);

cust.SetFee(500f, 0.75f);

emp.Display();

cust.Display();

}}

0 0

Post a comment