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

1. The array int[][] numbers contains many numbers. Unfortunately, some of those

ID: 3547779 • Letter: 1

Question

1. The array int[][] numbers contains many numbers. Unfortunately, some of those

numbers are 3, which is an ugly number (it's just a lazy 8). Remove all 3s from the matrix

and replace them with 8s.


2. You've created a new project in NetBeans. How do you create a new form?


3. Write the code to get the ints in dividendTextBox and divisorTextBox and append the

output to outputTextArea. The output should look like this:

5 / 2 = 2.5


4. Given the arrays

int[] num = {1, 2, 3};

String[] alphabet = {"A", "B", "C", "D"};

write the code to generate the following output:

1 <-> D B

2 <-> D B

3 <-> D B


5. The class Car contains name, year, price, horsepower and weight. Write the method

getFastest(List<Car> cars)

which returns the car that has the highest ratio of horsepower to weight (hp/w).



6. The class Car contains name, year, price, horsepower and weight. Write the method

getBestValue(List<Car> cars)

which returns the car that has the lowest price to horsepower ratio.



7. Class Person contains name and gender ("m"/"f'"). Class Invitation contains name and

seated. Write the method

List<Invitation> generateInvitations(

Person[][] seatingChart)

Invitations should include the person's name prefixed with either "Mr. " or "Ms. ". The

seat number is their row (second dimension) * 100 plus their column (ex.

Explanation / Answer

3.




import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextArea;

import javax.swing.JTextField;



public class Divide extends JFrame implements ActionListener {


public JLabel dividend;

public JLabel divisor;

public JLabel result;

public JTextField dividendfield;

public JTextField divisorfield;

public JTextArea resultfield;

public JButton enter;

public double divi;

public double div;

public double res;


public Divide(String s) {


super(s);

setLayout(new FlowLayout());

divi = 0;

div = 0;

res = 0;


dividend = new JLabel("Divident");

divisor = new JLabel("Divisor");

result = new JLabel("Result");


dividendfield = new JTextField(10);

divisorfield = new JTextField(10);

resultfield = new JTextArea(10, 10);



enter = new JButton("Result");


this.getContentPane().add(dividend);

this.getContentPane().add(dividendfield);

this.getContentPane().add(divisor);

this.getContentPane().add(divisorfield);

this.getContentPane().add(enter);

this.getContentPane().add(result);

this.getContentPane().add(resultfield);


  



enter.setActionCommand("enter");

enter.addActionListener(this);





this.setSize(270, 300);


setVisible(true);


setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}


public void actionPerformed(ActionEvent e) {

if ("enter".equals(e.getActionCommand())) {

divi = Double.parseDouble(dividendfield.getText().toString());

div = Double.parseDouble(divisorfield.getText().toString());

res = divi / div;

resultfield.setText(divi + "/" + div + "=" + res);

}

}


public static void main(String[] args) {

Divide d = new Divide("Divide Numbers");

}

}