Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Copy the files Address.java (Code Listing 8.1), Person.java (Code Listing 8.2

ID: 3695224 • Letter: 1

Question

1. Copy the files Address.java (Code Listing 8.1), Person.java (Code Listing 8.2), Money.java (Code Listing 8.3), MoneyDemo.java (Code Listing 8.4), and CreditCardDemo.java (Code Listing 8.5) from the Student CD or as directed by your instructor. Address.java, Person.java, MoneyDemo.java, and CreditCardDemo.java are complete and will not need to be modified. We will start by modifying Money.java. 2. Overload the constructor. The constructor that you will write will be a copy constructor. It should use the parameter Money object to make a duplicate Money object, by copying the value of each instance variable from the parameter object to the instance variable of the new object Code Listing 8.3 (Money.java) /** This class represents nonnegative amounts of money. */ public class Money { // The number of dollars private long dollars; // The number of cents private long cents; /** Constructor @param amount The amount in decimal format. */ public Money(double amount) { if (amount < 0) { System.out.println("Error: Negative amounts " + "of money are not allowed."); System.exit(0); } else { long allCents = Math.round(amount * 100); dollars = allCents / 100; cents = allCents % 100; } } Copyright © 2016 Pearson Education, Inc., Hoboken NJ // ADD LINES FOR TASK #1 HERE // Document and write a copy constructor /** The add method @param otherAmount The amount of money to add. @return The sum of the calling Money object and the parameter Money object. */ public Money add(Money otherAmount) { Money sum = new Money(0); sum.cents = this.cents + otherAmount.cents; long carryDollars = sum.cents / 100; sum.cents = sum.cents % 100; sum.dollars = this.dollars + otherAmount.dollars + carryDollars; return sum; } /** The subtract method @param amount The amount of money to subtract. @return The difference between the calling Money object and the parameter Money object. */ public Money subtract (Money amount) { Money difference = new Money(0); if (this.cents < amount.cents) { this.dollars = this.dollars - 1; this.cents = this.cents + 100; }

Hi, I am stuck on this coding question....I am not sure how to start. I also posted the coding for the question. thank you in advance.

Explanation / Answer

import javax.swing.*;

002.import java.awt.*;

003.import java.awt.event.*;

004.import java.rmi.*;

005.import java.util.Vector;

006.public class Applications extends JFrame implements ActionListener{

007.

008.JLabel labelTitle;

009.JLabel lApp_Num;

010.JLabel lApp_Dt;

011.JLabel lProg_Code;

012.JLabel lSch_Code;

013.JLabel lApp_Fees;

014.JLabel lApp_Status;

015.

016.JTextField tApp_Num;

017.JTextField tApp_Dt;

018.JTextField tProg_Code;

019.JTextField tSch_Code;

020.JTextField tApp_Fees;

021.JTextField tApp_Status;

022.

023.JPanel pan1, pan2, pan3;

024.JButton submit, reset, view, update, delete, cancel;

025.

026.String App_Num;

027.String App_Dt;

028.String Prog_Code;

029.String Sch_Code;

030.String App_Fees;

031.String App_Status;

032.String Emp_Type;

033.static Color c;

034.static String Ip;

035.public Applications(){

036.}

037.

038.public Applications(String emp_Type, Color c, String ip){

039.Emp_Type=emp_Type;

040.Ip=ip;

041.this.c=c;

042.

043.setTitle(Emp_Type+" (Application Interface) "+"Connected to: "+Ip);

044.setSize(500, 300);

045.pan1 = new JPanel();

046.pan2 = new JPanel();

047.pan3 = new JPanel();

048.pan1.setLayout(new FlowLayout(FlowLayout.CENTER));

049.pan2.setLayout(new GridLayout(6,2));

050.pan3.setLayout(new GridLayout(1,1));

051.pan1.setBackground(c);

052.pan2.setBackground(Color.white);

053.pan3.setBackground(Color.white);

054.

055.Icon logo=new ImageIcon(getClass().getResource("flame.gif"));

056.labelTitle=new JLabel();

057.labelTitle.setIcon(logo);

058.labelTitle.setText("UNIVERSITY OF TAYSIDE");

059.labelTitle.setHorizontalTextPosition(SwingConstants.CENTER);

060.labelTitle.setVerticalTextPosition(SwingConstants.BOTTOM);

061.labelTitle.setFont(new Font("Arial",Font.BOLD,20));

062.labelTitle.setToolTipText("Welcome to University of Tayside");

063.pan1.add(labelTitle);

064.

065.lApp_Num = new JLabel("Application number (i.e App02)");

066.pan2.add(lApp_Num);

067.

068.tApp_Num = new JTextField(15);

069.pan2.add(tApp_Num);

070.

071.lApp_Dt=new JLabel("Apllication Date (i.e yyyy-mm-dd)");

072.pan2.add(lApp_Dt);

073.

074.tApp_Dt = new JTextField(15);

075.tApp_Dt.setToolTipText("YYYY-MM-DD");

076.pan2.add(tApp_Dt);

077.

078.lProg_Code = new JLabel("Program Code");

079.lProg_Code.setToolTipText("Must match a program code in Program Schdules table");

080.pan2.add(lProg_Code);

081.

082.tProg_Code = new JTextField(15);

083.tProg_Code.setToolTipText("Must match a program code in Program Schdules table");

084.pan2.add(tProg_Code);

085.

086.lSch_Code = new JLabel("School Code");

087.lSch_Code.setToolTipText("Must match a School code in Graduate School table");

088.pan2.add(lSch_Code);

089.

090.tSch_Code = new JTextField(15);

091.tSch_Code.setToolTipText("Must match a School code in Graduate School table");

092.pan2.add(tSch_Code);

093.

094.lApp_Fees = new JLabel("Application Fee (i.e 3500)");

095.pan2.add(lApp_Fees);

096.

097.tApp_Fees = new JTextField(15);

098.pan2.add(tApp_Fees);

099.

100.lApp_Status = new JLabel("Aplication Status");

101.lApp_Status.setToolTipText("Rejected, Selected for admission, Admitted, Canceled");

102.pan2.add(lApp_Status);

103.

104.tApp_Status = new JTextField(15);

105.tApp_Status.setToolTipText("Rejected, Selected for admission, Admitted, Canceled");

106.pan2.add(tApp_Status);

107.

108.submit = new JButton("Submit");

109.submit.addActionListener(this);

110.submit.setToolTipText("Submit the form details to the server");

111.pan3.add(submit);

112.

113.reset = new JButton("Reset");

114.reset.addActionListener(this);

115.reset.setToolTipText("Clear the the text field area");

116.pan3.add(reset);

117.

118.view = new JButton("View");

119.view.addActionListener(this);

120.view.setToolTipText("View details");

121.pan3.add(view);

122.

123.update = new JButton("Update");

124.update.addActionListener(this);

125.update.setToolTipText("Update details");

126.pan3.add(update);

127.

128.delete = new JButton("Delete");

129.delete.addActionListener(this);

130.delete.setToolTipText("Delete details");

131.pan3.add(delete);

132.

133.cancel = new JButton("Exit");

134.cancel.addActionListener(this);

135.cancel.setToolTipText("Exit the form");

136.pan3.add(cancel);

137.

138.getContentPane().add(pan1, BorderLayout.NORTH);

139.getContentPane().add(pan2, BorderLayout.CENTER);

140.getContentPane().add(pan3, BorderLayout.SOUTH);

141.

142.addWindowListener(new WindowAdapter()

143.{

144.public void windowClosing(WindowEvent we)

145.{

146.System.exit(0);

147.}

148.});

149.}

150.

151.private void display()

152.{

153.Vector vec = null;

154.String App_Num=tApp_Num.getText();

155.String App_Dt="";

156.String Prog_Code="";

157.String Sch_Code="";

158.String App_Fees="";

159.String App_Status="";

160.

161.try

162.{  

163./* Find the remote object at specified URL */

164.vec = RemoteObject.getRemoteObject(Ip, "AppView").viewAppForm(App_Num);

165.

166.if((vec!=null) && (vec.size()>0))

167.{

168.App_Dt=(String) vec.elementAt(0);

169.Prog_Code=(String) vec.elementAt(1);

170.Sch_Code=(String) vec.elementAt(2);

171.App_Fees=(String) vec.elementAt(3);

172.App_Status=(String) vec.elementAt(4);

173.

174.tApp_Dt.setText(App_Dt);

175.tApp_Dt.setEditable(true);

176.

177.tProg_Code.setText(Prog_Code);

178.tProg_Code.setEditable(true);

179.

180.tSch_Code.setText(Sch_Code);

181.tSch_Code.setEditable(true);

182.

183.tApp_Fees.setText(App_Fees);

184.tApp_Fees.setEditable(true);

185.

186.tApp_Status.setText(App_Status);

187.tApp_Status.setEditable(true);

188.}

189./*else{

190.appDialog = new AppDialog(this, "No Records Found");

191.appDialog.setVisible(true);

192.appDialog.setBackground(c);}*/

193.

194.

195.}

196.catch(Exception e)

197.{

198.System.out.println("In Display "+e);

199.}

200.}

201.

202.private void delete(){

203.AppDialog appDialog;

204.try

205.{  

206.App_Num=tApp_Num.getText();

207.

208./* Find the remote object at specified URL */

209.String str = RemoteObject.getRemoteObject(Ip, "AppDelete").deleteAppForm(App_Num);

210.if(str.trim().equals("Records Inserted")){

211.appDialog = new AppDialog(this, "Records Deleted");

212.appDialog.setVisible(true);

213.appDialog.setBackground(c);

214.

215.tApp_Num.setText("");

216.tApp_Dt.setText("");

217.tProg_Code.setText("");

218.tSch_Code.setText("");

219.tApp_Fees.setText("");

220.tApp_Status.setText("");

221.}

222.else{

223.appDialog = new AppDialog(this, "Records Not Deleted");

224.appDialog.setVisible(true);

225.appDialog.setBackground(c);}

226.}

227.

228.catch(Exception e)

229.{

230.System.out.println(e);

231.}  

232.}

233.

234.

235.private void update(){

236.AppDialog appDialog;

237.try

238.{  

239.

240.

241.App_Num=tApp_Num.getText();

242.App_Dt=tApp_Dt.getText();

243.Prog_Code=tProg_Code.getText();

244.Sch_Code=tSch_Code.getText();

245.App_Fees=tApp_Fees.getText();

246.App_Status=tApp_Status.getText();

247.

248./* Find the remote object at specified URL */

249.String str = RemoteObject.getRemoteObject(Ip, "AppUpdate").updateAppForm(App_Num, App_Dt, Prog_Code, Sch_Code, App_Fees, App_Status);

250.

251.if(str.trim().equals("Records Inserted")){

252.

253.appDialog = new AppDialog(this, "Records Updated");

254.appDialog.setVisible(true);

255.appDialog.setBackground(c);

256.tApp_Num.setText("");

257.tApp_Dt.setText("");

258.tProg_Code.setText("");

259.tSch_Code.setText("");

260.tApp_Fees.setText("");

261.tApp_Status.setText("");

262.}

263.else{

264.appDialog = new AppDialog(this, "Records Not Updated");

265.appDialog.setVisible(true);

266.appDialog.setBackground(c);}

267.}

268.catch(Exception e)

269.{

270.System.out.println(e);

271.}   

272.

273.}

274.

275.

276.public void actionPerformed(ActionEvent ae)

277.{

278.AppDialog appDialog;

279.if(ae.getSource() == submit)

280.{

281.try

282.{  

283.

284.

285.

286.App_Num=tApp_Num.getText();

287.App_Dt=tApp_Dt.getText();

288.Prog_Code=tProg_Code.getText();

289.Sch_Code=tSch_Code.getText();

290.App_Fees=tApp_Fees.getText();

291.App_Status=tApp_Status.getText();

292.

293./* Find the remote object at specified URL */

294.String str = RemoteObject.getRemoteObject(Ip, "AppInsert").insertAppForm(App_Num, App_Dt, Prog_Code, Sch_Code, App_Fees, App_Status);

295.

296.if(str.trim().equals("Records Inserted")){

297.

298.appDialog = new AppDialog(this, "Records Inserted");

299.appDialog.setVisible(true);

300.appDialog.setBackground(c);

301.tApp_Num.setText("");

302.tApp_Dt.setText("");

303.tProg_Code.setText("");

304.tSch_Code.setText("");

305.tApp_Fees.setText("");

306.tApp_Status.setText("");

307.}

308.else{

309.appDialog = new AppDialog(this, "Records Not Inserted");

310.appDialog.setVisible(true);

311.appDialog.setBackground(c);}

312.}

313.catch(Exception e)

314.{

315.System.out.println(e);

316.}   

317.

318.}

319.else if(ae.getSource() == reset)

320.{

321.tApp_Num.setText("");

322.tApp_Dt.setText("");

323.tProg_Code.setText("");

324.tSch_Code.setText("");

325.tApp_Fees.setText("");

326.tApp_Status.setText("");

327.}

328.

329.else if(ae.getSource() == view)

330.{

331.display();

332.}

333.

334.else if(ae.getSource() == update)

335.{

336.update();

337.}

338.

339.else if(ae.getSource() == delete)

340.{

341.delete();

342.}

343.

344.else if(ae.getSource() == cancel)

345.{

346.

347.this.setVisible(false);

348.

349.}

350.}

351.

352.public static void main(String arg[])

353.{

354.Applications form = new Applications();

355.form.setVisible(true);

356.form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

357.form.setResizable(false);

358.form.setDefaultLookAndFeelDecorated(true);

359.

360.}

361.}

362.

363.class AppDialog extends Dialog implements ActionListener

364.{

365.AppDialog(JFrame parent, String title)

366.{

367.super(parent, "Status", false);

368.setLayout(new FlowLayout());

369.setSize(120, 100);

370.parent.setDefaultLookAndFeelDecorated(true);

371.add(new JLabel(title));

372.JButton button_OK = new JButton("OK");

373.add(button_OK);

374.button_OK.addActionListener(this);

375.}

376.public void actionPerformed(ActionEvent ae)

377.{

378.dispose();

379.}

380.}