Computer Science-QA480

Computer Science-QA480 Online Services

 

You may use any features from the Java JDK API including those not covered in.
You must NOT use any third-party classes (e.g. classes that are not provided as part of the Java JDK download). If you use any other sources, you must clearly indicate this as comments in the program, and the extent of the reference must be clearly indicated.
 

Submission
 

Your submission should comprise a single zip file containing the source code (i.e. the .java files) for all the classes that you have written as solutions to the assignment tasks. No other files should be included in the zip file. The name of your zip file should include both your name and your registration number.
 

1. Exercise [20%]
 

This exercise is about writing programs for practising multiplication of numbers.
 

Part A [14%]
 

Write a class Exercise1 with a method
public static void partA()
The method should feature a loop that runs 10 times. In each step of the loop, the program should:
 

Generate two random integer numbers in the range 10 to 20 (inclusive).
Ask the user to compute the product of these two numbers.
Check the answer entered by the user. Inform the user if the answer was correct or not. You can assume that the user input is an integer number.
Display the current score of correct answers and the total numbers of answers given.
Here is log from a sample program run
 

Exercise 1A
10 * 18 = ?
180
Correct answer. Score: 1(1)
16 * 11 = ?
176
Correct answer. Score: 2(2)
18 * 16 = ?
238
Incorrect answer. Score: 2(3)
17 * 19 = ?
363
Incorrect answer. Score: 2(4)
12 * 16 = ?
292
Incorrect answer. Score: 2(5)
16 * 10 = ?
160
Correct answer. Score: 3(6)
16 * 11 = ?
176
Correct answer. Score: 4(7)
15 * 15 = ?
225
Correct answer. Score: 5(8)
11 * 17 = ?
188
Incorrect answer. Score: 5(9)
14 * 13 = ?
182
Correct answer. Score: 6(10)
Good-bye
In class Exercise1, add a main() method which invokes partA(). Test your program.
 

Part B [6%]
 

In class Exercise1, add a method public static void partB()
 

The program should implement a similar functionality as in Part A – it should repeatedly ask the user to compute the product of two randomly generated integers in the range 10 to 20. There are a couple of differences:
The number of multiplication problems should not be fixed. Instead, the program should keep posing new multiplication problems until the user decides to quit by entering the letter “q”.
The program should be able to deal with invalid input by the user. It should ignore such input and restate the current multiplication problem. Here is log from a sample program run
 

Exercise 1B
18 * 12 = ?
216
Correct answer. Score: 1(1)
14 * 16 = ?
a
Invalid input
14 * 16 = ?
224
Correct answer. Score: 2(2)
11 * 20 = ?
230
Incorrect answer. Score: 2(3)
12 * 16 = ?
192
Correct answer. Score: 3(4)
19 * 11 = ?
q
Good-bye
Change method Exercise1.main() so that it invokes partB. Test your program.
 

2. Exercise [15%]
 

This exercise is about writing methods which operate on two-dimensional arrays of integers. You can assume that these arrays are rectangular – all rows have the same length. You can also assume each of these arrays has at least one row and that all rows are non-empty. For testing, please use an array with three rows and four columns with the following elements
 

3 -1 4 0
5 9 -2 6
5 3 7 -8
 

Part A [3%]
 

Create a class Exercise2. In this class, write a method
public static int sum(int[][] array)
Given a rectangular 2D array, the method should return the sum of its elements. For example, if applied to the test array, the result should be 31. Write a method main() which applies sum to the test array. Display the method result and check that it is correct.
 

Part B [3%]
 

In class Exercise2 write a method
public static int[] rowSums(int[][] array)
Given a rectangular 2D array with n rows, the method should return an array of length n whose elements are the sums of the corresponding rows in the argument array. For example, if applied to the test array, the result should be an array of length 3 containing the elements (3+(-1)+4+0,5+9+(-2)+6, 5+3+7+(-8)) = (6,18,7). Add code to method
main() which applies rowSums to the test array. Display the method result and check that it is correct.
 

Part C [3%]
 

In class Exercise2 write a method
public static int[] columnSums(int[][] array)
Given a rectangular 2D array with n columns, the method should return an array of length n whose elements are the sums of the corresponding columns in the argument array. For example, if applied to the test array, the result should be an array of length 4 containing the elements (3+5+5,(-1)+9+3, 4+(-2)+7, 0+6+(-8)) = (13,11,9,-2). Add code to
method main() which applies columnSums to the test array. Display the method result and check that it is correct.
 

Part D [3%]
 

In class Exercise2 write a method
public static int maxRowAbsSum(int[][] array)
Given a rectangular 2D array, the method should compute for each row the sum of the absolute values of the elements of that row. The method should return the maximum of these sums. For example, if applied to the test array, the method should return the value max (3+1+4+0,5+9+2+6, 5+3+7+8) = max (8,22,23) = 23. Add code to method main() which applies maxRowAbsSum to the test array. Display the method result and check that it is correct.
 

Part E [3%]
 

Write a class TestExercise2 with four JUnit tests – one for each of the methods coded in Part A – Part D above. Each test should apply one method to some sample test data and check that the result is correct. It is recommended that you use the same test data as above.Create a class called Icosahedron which will be used to represent a regular icosahedron, that is a convex polyhedron with 20 equilateral triangles as faces. The class should have the following features:
 

A private instance variable, edge, of type double, that holds the edge length.
A private static variable, count, of type int, that holds the number of Icosahedron objects that have been created.
A constructor that takes one double argument which specifies the edge length.
An instance method surface() which returns the surface area of the icosahedron. This can be calculated using the formula 5*√3 edge².
An instance method volume() which returns the volume of the icosahedron. This can be calculated using the formula 5*(3+√5)/12*edge³.
An instance method toString() which returns a string with the edge length, surface area and volume as in the example below
 

Icosahedron[edge= 3.000, surface= 77.942, volume= 58.906]
The numbers in this string should be in floating point format with a field that is (at least) 7 characters wide and showing 3 decimal places. Please use the static method String.format with a suitable formatting string to achieve this. A static method getCount() which returns the value of the static variable count. Finally, add the following main method to your Icosahedron class so that it can be run and tested
 

public static void main(String[] args) {
System.out.println(“Number of Icosahedron objects created: ” + getCount());
Icosahedron[] icos = new Icosahedron[4];
for (int i = 0; i < icos.length; i++) icos[i] = new Icosahedron(i+1); for (int i = 0; i < icos.length; i++) System.out.println(icos[i]); System.out.println("Number of Icosahedron objects created: " + getCount());}   4. Exercise [25%]
 

The online CSV file
https://orb.essex.ac.uk/ce/ce152/data/assign/elements.csv
contains data about 104 chemical elements
You should make a copy of this file in a convenient directory on your M: drive. Then look at the file. Apart from the initial header row, each row contains data about a chemical element in the following format:
 

Atomic Number Symbol Element name Group Period Atomic weight
8 O Oxygen 16 2 15.999
In each row, the six fields are separated by commas. You can assume that there are no other commas in the CSV file.
 

Part A [7%]
 

Create a class Element that represents the data for one element as in file elements.csv. Each Element object
should have six fields corresponding to the columns in that file:
number (int)
symbol (String)
name (String)
group (int)
period (int)
weight (double)
 

The class should also have
A constructor with six arguments for initialising the six fields.
An instance method toString() which returns a string in the same format as a row in the CSV file. For
example, in the case of Oxygen, the result should be:
8, O, Oxygen, 16, 2, 15.999
Then create a class Exercise4 with the following method:
public static void exercise4a() {
Element oxygen = new Element(8, “O”, “Oxygen”, 16, 2, 15.999);
System.out.println(oxygen);
}
Add a main() method to class Exercise4 that invokes exercise4a(). Test your program by running the class.
 

Part B [6%]
 

In class Element, write a method
public static List readElements()
The method should read the chemical element data from file elements.csv. It should skip the header row. For each row thereafter, it should create a corresponding Element object. The method should return a list containing these objects in the same order as they are in the file.
In class Exercise4, create a method:
public static void exercise4b()
This method should invoke readElements() and display the first 20 elements from that list.
Add an invocation of exercise4b() in the main() method and test your program.
 

Hints
 

See Week 19 lecture notes for sample code for reading data from a CSV file.
Remember that classes Double and Integer have methods to parse a number from a string.
 

Part C [6%]
 

In class Exercise4, write a method
public static void exercise4c()
The method should read the data from file elements.csv into a list using method readElements(). It should
then
 

sort the elements in that list by number in increasing order and print the first 20 elements of that list; and then perform another sorting of the list but this time order elements by their groups in increasing order. Elements in
the same group should be sorted by their number. Print the first 20 elements of the sorted list.
 

Sorting should be performed using method Collections.sort with appropriate implementations of interfaces
Comparable and/ or Comparator which you will need to code.
Add an invocation of exercise4c() in the main() method and test your program.
 

Part D [6%]
 

In class Element, write a method Public static Map> elementsByGroup(List elements)
Given a list of Element objects, the method should return a map which associates each group with the set of elements in that group. The map should be sorted according to the natural ordering of its keys. Each of the sets of chemical elements should be sorted by element numbers.
 

In class Exercise4, write a method
 

public static void exercise4d()
This method should read the element data from file elements.csv into a list using method readElements(). It should invoke method elementsByGroup with that list. This method invocation returns a map. For each group that occurs as a key in that map, the program should display
 

The name of the group
The first three elements of the set associated with the group in the map.
 

This should result in program output as follows
 

Group 1:
1,H,Hydrogen,1,1,1.008
3,Li,Lithium,1,2,6.94
11,Na,Sodium,1,3,22.98976928
Group 2:
4,Be,Beryllium,2,2,9.0121831
12,Mg,Magnesium,2,3,24.305
20,Ca,Calcium,2,4,40.078

Group 18:
2,He,Helium,18,1,4.002602
10,Ne,Neon,18,2,20.1797
18,Ar,Argon,18,3,39.948
 

5. Exercise [10%]
 

A very simple library system keeps information about the books and periodicals held in stock.
Create an abstract class LibraryItem with two subclasses Book and Periodical.
Every library item has a name (a string) and a unique reference number (also a string) and the year of publication (an int). Every book has an author and a publisher (both strings).
Every periodical has an issue number (an int). You should provide constructors for all three classes. The argument lists for the constructors of the non-abstract
 

You can read more about our case study assignment help services here.
 

How it Works

How It works ?

Step 1:- Click on Submit your Assignment here or shown in left side corner of every page and fill the quotation form with all the details. In the comment section, please mention Case Id mentioned in end of every Q&A Page. You can also send us your details through our email id support@assignmentconsultancy.com with Case Id in the email body. Case Id is essential to locate your questions so please mentioned that in your email or submit your quotes form comment section.

Step 2:- While filling submit your quotes form please fill all details like deadline date, expected budget, topic , your comments in addition to Case Id . The date is asked to provide deadline.

Step 3:- Once we received your assignments through submit your quotes form or email, we will review the Questions and notify our price through our email id. Kindly ensure that our email id assignmentconsultancy.help@gmail.com and support@assignmentconcultancy.com must not go into your spam folders. We request you to provide your expected budget as it will help us in negotiating with our experts.

Step 4:- Once you agreed with our price, kindly pay by clicking on Pay Now and please ensure that while entering your credit card details for making payment, it must be done correctly and address should be your credit card billing address. You can also request for invoice to our live chat representatives.

Step 5:- Once we received the payment we will notify through our email and will deliver the Q&A solution through mail as per agreed upon deadline.

Step 6:-You can also call us in our phone no. as given in the top of the home page or chat with our customer service representatives by clicking on chat now given in the bottom right corner.

Case Approach

Scientific Methodology

We use best scientific approach to solve case study as recommended and designed by best professors and experts in the World. The approach followed by our experts are given below:

Defining Problem

The first step in solving any case study analysis is to define its problem carefully. In order to do this step, our experts read the case two three times so as to define problem carefully and accurately. This step acts as a base and help in building the structure in next steps.

Structure Definition

The second step is to define structure to solve the case. Different cases has different requirements and so as the structure. Our experts understand this and follow student;s university guidelines to come out with best structure so that student will receive best mark for the same.

Research and Analysis

This is the most important step which actually defines the strength of any case analysis. In order to provide best case analysis, our experts not only refer case materials but also outside materials if required to come out with best analysis for the case.

Conclusion & Recommendations

A weak conclusion or recommendations spoil the entire case analysis. Our expert know this and always provide good chunks of volume for this part so that instructors will see the effort put by students in arriving at solution so as to provide best mark.

Related Services

 

classes should be ordered as follows
 

Book: (String name, String refNum, int year, String author, String publisher)
Periodical: (String name, String refNum, int year, int issue Num)
The names you choose to give to the arguments do not matter but their type and order do. Both the Book and the Periodical constructor should start off with an invocation of the parent class constructor. You should also provide suitable toString() methods for classes Book and Periodical. These methods should override the default provided in class Object and they should produce information in intelligible format. The result should be readable and include all the information known about the item. Please declare all fields, constructors and methods as public.
Test your implementation using class Exercise5 provided below.
 

import java.util.Arrays;
public class Exercise5 {
public static void main(String[] args) {
List items = new ArrayList<>();
Collections.addAll(items,
new Book(“Python for Arachnophobes”, “E0001113”, 2003, “Spider,A.”, “Cashin Press”),
new Periodical(“Tarantula Monthly”, “C0090210”, 2010, 35),
new Periodical(“Tarantula Monthly”, “D0090211”, 2011, 43),
new Book(“Java for Arachnophobes”, “B0001099”, 2003, “Spider,A.”, “Cashin Press”),
new Periodical(“Arachnids”, “A0010098”, 1898, 27));
for (LibraryItem item : items)
System.out.println(item);}}
 

6. Exercise [20%] (Challenge)
 

Part A [6%]
 

Write a class Exercise6 which displays a chess board similar to the image below. The program should be coded as a GUI using Java Swing. Please use the colour LIGHT_GRAY for the dark squares.
 

Part B [6%]
 

Expand the program you wrote in Part A so that it displays a blue circle in the top-left corner of the board. Then write program code which allows the user to enter keyboard commands that move this blue circle on the board. The following two kinds of moves should be allowed
 

Moving the circle three squares to the left, right, up or down Moving the circle two squares diagonally (right-and-up, right-and-down, left-and-down or left-and-up) As an example, the first image below uses green squares to indicate all the possible moves of the blue circle
situated in row 3, column 3. Note that the number of possible moves depends on the current position of the blue circle. For example if the blue square in in the starting position (0,0) in the top left corner, then it only has three possible moves: three squares to the right, three square down or two square diagonally left-and-down (see second image below).
 

Moves from (3,3) file:///C/Users/Mark/Downloads/CE152%20Assignment%20Spring%202018.html[15/04/2018 10:11:46] Moves from (0,0) For the keyboard control, please include the number-pad key-bindings listed below. You can add further keybindings
as you see fit.
KeyEvent.VK_NUMPAD4: move left three squares
KeyEvent.VK_NUMPAD6: move right three squares
KeyEvent.VK_NUMPAD8: move upwards three squares
KeyEvent.VK_NUMPAD2: move downwards three squares
KeyEvent.VK_NUMPAD7: move diagonally two squares left, two squares upwards
KeyEvent.VK_NUMPAD9: move diagonally two squares right, two squares upwards
KeyEvent.VK_NUMPAD3: move diagonally two squares right, two squares downwards
KeyEvent.VK_NUMPAD1: move diagonally two squares left, two squares downwards
The program should ignore invalid move attempts.
 

Part C [4%]
 

Expand the program you wrote in Part B so that it selects a random target square on the board. This square should be different from the top-left corner which is the start square of the blue circle. Paint the target square with the colour red. The user should try to move the blue circle to the target square in as few moves as possible. When the blue circle has reached the target square, the program should display a message stating the number of moves made. Please use a JOptionPane to show this message in a format similar to the image below. CE152 Assignment Spring 2018
 

Part D [4%]
 

Expand the program you wrote in Part C so that the blue circle can also be moved with the help of a mouse. Use a mouse click to select the next square for the circle.
 

Assignment Marking Criteria
 

Exercise Weighting Criteria
1A 14% 4 marks for a loop posing 10 multiplication problems. 2 marks for generating random numbers between 10 and 20 used in those problems. 4 marks for reading the user input and providing proper feedback if answer was right or wrong. 4 marks for displaying a proper score (number of correct answers, total number of answers)1B 6% 2 marks for posing an unlimited number of multiplication problems, 2 marks for proper handling of “q” input, 2 marks for proper handling of invalid input.
 

2A – 2D 12% 3 marks for each correct method.
2E 3% 1 mark for each correct test method up to a maximum of 3 marks.
3 10% 2 marks for proper fields, 2 marks for constructor, 1 mark each for methods surface,
volume and get Count. 2 marks for method toString, 1 mark for proper formatting of to String result. 4A 7% 3 marks for a class definition with suitable fields, 2 marks for a correct constructor, 2 marks for a correct to String() method. 4B 6% 5 marks for correct implementation of method read Elements. for correct testing in method exercise4b(). 4C 6% 2 marks for correct sorting by element number, 2 marks for correct sorting by group and element number, 2 marks for correct testing in method exercise4c(). 4D 6% 2 marks for method elements By Group returning a map with correct keys and with value sets containing the correct elements. 1 mark for correct order of map entries. For correct order of elements in sets. 2 marks for a correct method exercise4d().

 

5 10% 3 marks for class Library Item, 4 marks for class Book, 4 marks for class Periodical. Subtraction of up to 2 marks if a subclass constructor duplicates code by not calling the parent class constructor. 6A 6% 4 marks for a Swing GUI displaying a 8×8 grid with squares. 2 marks for proper colouring of squares. 6B 6% 3 marks for implementing horizontal and vertical moves. 3 marks for implementing diagonal moves. Subtraction of marks if program does not stop invalid moves. 6C 4% 1 mark for generating a random target different from the starting square. 1 mark for painting target square in red. 1 mark for keeping track of the number of moves. 1 mark for displaying an appropriate message when the target is reached.6D 4% 4 marks for controlling the blue circle using a mouse. Subtraction of marks if program does not stop invalid moves.
 
product code: Computer Science-QA480
 
Looking for best Computer Science-QA480 online ,please click here
 

Summary