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

NEED ALL THESE QUESTIONS ANSWERED PLEASE 1. 2. 3. Declare an ArrayList of intege

ID: 3744984 • Letter: N

Question

NEED ALL THESE QUESTIONS ANSWERED PLEASE

1. 2. 3. Declare an ArrayList of integers and put the first 100 integers in the list. Write a loop that walks through the ArrayList and prints the integers Declare an enumerated type for deck of cards. Declare a variable myCard. Assign diamond classification to this variable. write interface Tax. It has one method calculateTax that accepts an amount and returns 8% of the amount 4. Write class Earnings that will implement calculateTax 5 Write a method that accepts a string and prints each word on a separate line. The string is delimited by* Write the code to create a label, field, and button. Attach them to a JErame. Write an anonymous listener that reads the field and prints the data to the prompt Rewrite the anonymous listener in #6 to be a class listener and register the listener. 6. 7.

Explanation / Answer

Solution 1:

-------------------

import java.util.ArrayList;

/**

* The Class IntegerList.

*/

public class IntegerList {

/**

* The main method.

*

* @param args the arguments

*/

public static void main(String[] args) {

ArrayList<Integer> list = new ArrayList<>();

initializeList(list);

for(Integer i : list) {

System.out.println(i);

}

}

/**

* Initialize list.

*

* @param list the list

*/

private static void initializeList(ArrayList<Integer> list) {

list.add(1);list.add(2);list.add(3);list.add(4);list.add(5);list.add(6);list.add(7);list.add(8);list.add(9);

list.add(10);list.add(11);list.add(12);list.add(13);list.add(14);list.add(15);list.add(16);list.add(17);list.add(18);list.add(19);

list.add(20);list.add(21);list.add(22);list.add(23);list.add(24);list.add(25);list.add(26);list.add(27);list.add(28);list.add(29);

list.add(30);list.add(31);list.add(32);list.add(33);list.add(34);list.add(35);list.add(36);list.add(37);list.add(38);list.add(39);

list.add(40);list.add(41);list.add(42);list.add(43);list.add(44);list.add(45);list.add(46);list.add(47);list.add(48);list.add(49);

list.add(50);list.add(51);list.add(52);list.add(53);list.add(54);list.add(55);list.add(56);list.add(57);list.add(58);list.add(59);

list.add(60);list.add(61);list.add(62);list.add(63);list.add(64);list.add(65);list.add(66);list.add(67);list.add(68);list.add(69);

list.add(70);list.add(71);list.add(72);list.add(73);list.add(74);list.add(75);list.add(76);list.add(77);list.add(78);list.add(79);

list.add(80);list.add(81);list.add(82);list.add(83);list.add(84);list.add(85);list.add(86);list.add(87);list.add(88);list.add(89);

list.add(90);list.add(91);list.add(92);list.add(93);list.add(94);list.add(95);list.add(96);list.add(97);list.add(98);list.add(99);

list.add(100);

}

}

===========================================================================================================

Solution 2:

-----------------

public enum Cards {

/** The clubs. */

CLUBS,

/** The diamonds. */

DIAMONDS,

/** The hearts. */

HEARTS,

/** The spades. */

SPADES;

public static String myCard = DIAMONDS.name();

}

===========================================================================================================

Solution 3:

---------------------

/**

* The Interface Tax.

*/

public interface Tax {

/**

* Calculate tax.

*

* @param amount the amount

* @return the double

*/

double calculateTax(double amount);

}

Solution 4:

---------------------

/**

* The Class Earnings.

*/

public class Earnings implements Tax {

@Override

public double calculateTax(double amount) {

return (amount * 8) / 100;

}

}

=========================================================================================================

Solution 5:

-------------------

/**

* The Class WordPrinter.

*/

public class WordPrinter {

/**

* The main method.

*

* @param args the arguments

*/

public static void main(String[] args) {

String word = "Roket*is*fighting";

wordPrinter(word);

}

/**

* Word printer.

*

* @param word the word

*/

private static void wordPrinter(String word) {

String[] splittedWords = word.split("\*");

for (int i = 0; i < splittedWords.length; i++) {

System.out.println(splittedWords[i]);

}

}

}

=========================================================================================================

Solution 11, 12, & 13

---------------------------

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.io.PrintWriter;

/**

* The Class AssignmentFileReaderWritter.

*/

public class AssignmentFileReaderWritter {

/**

* The main method.

*

* @param args the arguments

*/

public static void main(String[] args) {

writeFile();

readFile();

readFile("poem.txt");

}

/**

* Write file.

*/

public static void writeFile() {

try {

PrintWriter writer = new PrintWriter("poem.txt");

writer.write("Once upon a midnight dreary while I pondered, weak and weavry");

writer.write(" Over many a quaint and curious volume of forgotten Iore");

writer.close();

}

catch (FileNotFoundException e) {

e.printStackTrace();

}

}

/**

* Read file.

*/

public static void readFile() {

try {

BufferedReader br = new BufferedReader(new FileReader("poem.txt"));

String line = null;

while ((line = br.readLine()) != null) {

printWords(line);

}

br.close();

}

catch (IOException e) {

e.printStackTrace();

}

}

/**

* Read file.

*

* @param filename the filename

*/

private static void readFile(String filename) {

try {

BufferedReader br = new BufferedReader(new FileReader(filename));

String line = null;

while ((line = br.readLine()) != null) {

System.out.println(line);

}

br.close();

}

catch (IOException e) {

e.printStackTrace();

}

}

/**

* Word printer.

*

* @param line the word

*/

private static void printWords(String line) {

String[] splittedWords = line.split(" ");

for (int i = 0; i < splittedWords.length; i++) {

System.out.println(splittedWords[i]);

}

}

}

==============================================================================================================

solution 14 to 18

-------------------

===================ComputerManager.java==================

import java.io.BufferedOutputStream;

import java.io.EOFException;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.util.ArrayList;

public class ComputerManager {

public static void main(String[] args) {

ArrayList<Computer> computerList = new ArrayList<>();

Computer dell = new Computer("DELL", 100);

Computer hp = new Computer("HP", 150);

computerList.add(dell);

computerList.add(hp);

double grandTotal = 0;

for (Computer computer : computerList) {

double totalPrice = computer.calculateCharge(5);

System.out.println("Total price for 5 " + computer.getBrand() + " is " + totalPrice + " $");

grandTotal += totalPrice;

}

System.out.println("Grand total is: " + grandTotal + "$");

Laptop laptop = new Laptop("Lenovo", 80, 500);

computerList.add(laptop);

writeFile(computerList);

readFile();

}

private static void writeFile(ArrayList<Computer> computerList) {

try {

FileOutputStream fileOut = new FileOutputStream("computers.ser", true);

ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fileOut));

for (Computer computer : computerList) {

out.writeObject(computer);

}

out.close();

fileOut.close();

}

catch (IOException i) {

}

}

private static void readFile() {

ArrayList<Computer> computerList = new ArrayList<>();

try {

FileInputStream fs = new FileInputStream("computers.ser");

ObjectInputStream save;

try {

for (;;) {

save = new ObjectInputStream(fs);

Computer computer = (Computer) save.readObject();

computerList.add(computer);

}

}

catch (EOFException e) {

}

fs.close();

}

catch (Exception exc) {

exc.printStackTrace();

}

printList(computerList);

}

private static void printList(ArrayList<Computer> computerList) {

for (Computer computer : computerList) {

System.out.println(String.format("Brand: %s, Price: %f", computer.getBrand(), computer.getPrice()));

}

}

}

=========================Laptop.java===============

package mixed_asignment;

public class Laptop extends Computer {

private int size;

public Laptop(String brand, double price, int size) {

super(brand, price);

this.size = size;

}

public int getSize() {

return size;

}

public void setSize(int size) {

this.size = size;

}

@Override

public String toString() {

return String.format("Laptop [Brand = %s,Size = %s,Price = %s]", super.getBrand(), size, super.getPrice());

}

}

======================Computer.java================

package mixed_asignment;

import java.io.Serializable;

public class Computer implements Serializable {

private static final long serialVersionUID = 1L;

private String brand;

private double price;

public Computer(String brand, double price) {

this.brand = brand;

this.price = price;

}

public String getBrand() {

return brand;

}

public void setBrand(String brand) {

this.brand = brand;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public double calculateCharge(int quantity) {

return price * quantity;

}

}

=========================================================

Solution 6 -10

------------------

will provide you soon