Question

In: Computer Science

Programming Steps: (In Java) (Please screenshot your output) A. Files required or needed to be created:...

Programming Steps: (In Java) (Please screenshot your output)

A. Files required or needed to be created:
   1. Artist.java (Given Below)
   2. p7artists.java (Input file to read from)
   3. out1.txt (Output file to write to)

B. Java programs needed to writeand create:
   1. MyArtistList.java:

   - Contains the following:
       1. list - public, Arraylist of Artist.
       This list will contain all entries from "p7artists.txt"


       2. Constructor:
       A constructor that accepts one string parameter which is
       the Input File Name, and will read the file
       to a ArrayList.


       3. Two print() methods:
       i) First one takes two parameters : A heading(name) and the output
       file ID - to print the contents of list to the output file
       ii) No parameter: Print the list contents to the console

C. Construct Step1.java that contans only the following code:
  
public class Step1
{
   public Step1()
{
       MyArtistList myArtists = new MyArtistList("C:/Users/patel/Desktop/JavaFiles/p7artists.txt");
       myArtists.print("Name", "C:/Users/patel/Desktop/JavaFiles/exam3out1.txt");
}

}

D. Construct "Main.java" that calls "Step1" which will produce
an output file "out1.txt" that contains all ArtistID and
ArtistName from "p7artists.txt".

E. Attach the output when answering.

Required files:

p7artists.txt:

1   Acconci
2   Budd
3   Carpenter
4   Dill
5   Edwards
6   Fleming
7   Garber
8   Higgins
9   Ibe
10   Kollasch
11   Lerman
12   Metz
13   Novarre
14   Ortega
15   Parker
16   Penn
17   Pierobon
18   Prinzen
19   Quiroz
20   Rath

Artist.java:

public class Artist implements java.lang.Comparable<Artist> {
// Instance variables
private int artistID; // id of artist
private String artistName; // name of artist
private Art art;

/**
* Constructor
*
* @param name
* @param number
*/
Artist(String name, int number) {
this.artistID = number;
this.artistName = name;
}

/**
* Constructor
*
* @param artistID
* @param artistName
* @param art
*/
public Artist(int artistID, String artistName, Art art) {
this.artistID = artistID;
this.artistName = artistName;
this.art = art;
}

/**
* return the artistName
*
* @return
*/
public String getArtistName() {
return artistName;
}

/**
* set the artistName
*
* @param artistName
*/
public void setArtistName(String artistName) {
this.artistName = artistName;
}

/**
* return the artistId
*
* @return
*/
public int getArtistID() {
return artistID;
}

/**
* set the artistId
*
* @param artistId
*/
public void setArtistID(int artistId) {
this.artistID = artistId;
}

/**
* @return the art
*/
public Art getArt() {
return art;
}

/**
* @param art
* the art to set
*/
public void setArt(Art art) {
this.art = art;
}

public int compareTo(Artist o) {
return this.getArt().compareTo(o.getArt());
}

/**
* toString method
*/
public String toString() {
return String.format("%-9d %-20s", this.artistID, this.artistName);
}
}

Solutions

Expert Solution

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class MainArtistsTest {
   public static void main ( String[] args )
   {
       new Step1();
   }
}

class Art implements Comparable<Art> {

   @Override
   public int compareTo(Art o) {
       // TODO Auto-generated method stub
       return 0;
   }

}

class MyArtistList {
  
   private ArrayList<Artist> artists = null;
   public MyArtistList(String filename) {
       Scanner input;
       try {
           input = new Scanner(new File(filename));
           artists = new ArrayList<Artist>();
           while(input != null && input.hasNext()) {
              
               String line = input.nextLine();
               String tokens[] = line.split(" ");
               //System.out.println(tokens.length+""+tokens[1]+" -- "+Integer.parseInt(tokens[0].trim()));
               Artist newA = new Artist(tokens[1],Integer.parseInt(tokens[0].trim()));
               artists.add(newA);
           }
           input.close();
          
          
      
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   }
      
  
   public void print(String heading, String outFile) {
      
       //wite to file
       BufferedWriter writer;
       try {
           writer = new BufferedWriter(new FileWriter(outFile));
           writer.write(heading+"\n");
           for(Artist a : artists) {
               writer.write(a.toString()+"\n");
           }
           writer.flush();
           writer.close();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
      
  
   }
  
   public void print() {
       for(Artist a : artists) {
           System.out.println(a.toString());
       }
   }
}
class Step1
{
   public Step1()
{
       MyArtistList myArtists = new MyArtistList("D:/ravi/Cheg/p7artists.txt");
       myArtists.print();
       myArtists.print("Name", "D:/ravi/Cheg/exam3out1.txt");
}

}

class Artist implements java.lang.Comparable<Artist> {
   // Instance variables
   private int artistID; // id of artist
   private String artistName; // name of artist
   private Art art;

   /**
   * Constructor
   *
   * @param name
   * @param number
   */
   Artist(String name, int number) {
   this.artistID = number;
   this.artistName = name;
   }

   /**
   * Constructor
   *
   * @param artistID
   * @param artistName
   * @param art
   */
   public Artist(int artistID, String artistName, Art art) {
   this.artistID = artistID;
   this.artistName = artistName;
   this.art = art;
   }

   /**
   * return the artistName
   *
   * @return
   */
   public String getArtistName() {
   return artistName;
   }

   /**
   * set the artistName
   *
   * @param artistName
   */
   public void setArtistName(String artistName) {
   this.artistName = artistName;
   }

   /**
   * return the artistId
   *
   * @return
   */
   public int getArtistID() {
   return artistID;
   }

   /**
   * set the artistId
   *
   * @param artistId
   */
   public void setArtistID(int artistId) {
   this.artistID = artistId;
   }

   /**
   * @return the art
   */
   public Art getArt() {
   return art;
   }

   /**
   * @param art
   * the art to set
   */

   public void setArt(Art art) {
   this.art = art;
   }

   public int compareTo(Artist o) {
   return this.getArt().compareTo(o.getArt());
   }

   /**
   * toString method
   */
   public String toString() {
   return String.format("%-9d %-20s", this.artistID, this.artistName);
  
   }

}


Related Solutions

THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep...
Fundamentals of Programming USING JAVA Please copy here your source codes, including your input and output...
Fundamentals of Programming USING JAVA Please copy here your source codes, including your input and output screenshots. Please upload this document along with your source files (i.e., the .java files) on Blackboard by the due date. 1. (Display three messages) Write a program that displays Welcome to Java, Welcome to Computer Science, and Programming is fun. 2. (Convert feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that a text file named FIRST.TXT contains some text written into it, write a class and a method named vowelwords(), that reads the file FIRST.TXT and creates a new file named SECOND.TXT, to contain only those words from the file FIRST.TXT which start with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u'). For example, if the file FIRST.TXT contains Carry umbrella and overcoat...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated a unique process identifier to each process. Exercise 4.20 required you to modify your solution to Exercise 3.20 by writing a program that created a number of threads that requested and released process identifiers. Now modify your solution to Exercise 4.20 by ensuring that the data structure used to represent the availability of process identifiers is safe from race conditions. Use Pthreads mutex locks....
Please in C++ thank you! Please also include the screenshot of the output. I have included...
Please in C++ thank you! Please also include the screenshot of the output. I have included everything that's needed for this. Pls and thank you! Write a simple class and use it in a vector. Begin by writing a Student class. The public section has the following methods: Student::Student() Constructor. Initializes all data elements: name to empty string(s), numeric variables to 0. bool Student::ReadData(istream& in) Data input. The istream should already be open. Reads the following data, in this order:...
Your hardcopy submission will consist of these two things: Source code (your java file). Screenshot of...
Your hardcopy submission will consist of these two things: Source code (your java file). Screenshot of Eclipse showing output of program. (JPG or PNG format only) Write a program to play the game of Stud Black Jack. This is like regular Black Jack except each player gets 2 cards only and cannot draw additional cards. Create an array of 52 integers. Initialize the array with the values 0-51 (each value representing a card in a deck of cards) in your...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the user. Write a program with conditional statements. Write a program with loops. Specifications Think of three countries you’d like to travel to and look up the conversion rate between dollars and the money used in those countries. (See http://www.ratesfx.com/ rates/rate-converter.html for conversion rates.) Write a program that will convert money from dollars into each of those three types of currency, or from one of...
SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. NOTE - Submission in parts. Parts required -...
SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
There are two programming questions for you to do. Please submit two.s or .asm files. You...
There are two programming questions for you to do. Please submit two.s or .asm files. You can use the usual settings as the previous homework. But if you want to use pseudo-instructions, you will need to uncheck "Bare Machine" and check "Accept Pseudo Instructions" (10 points) Declare an array of integers, something like: . data size : . word 8 array : . word 23 , -12 , 45 , -32 , 52 , -72 , 8 , 13 Write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT