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...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that will test if some string is a palindrome Ask the user to enter a string Pass the string to a Boolean function that uses recursion to determine if something is a palindrome or not. The function should return true if the string is a palindrome and false if the string is not a palindrome. Main displays the result ( if the string is a...
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:...
Programming language: Java If any more information is needed please let me know exactly what you...
Programming language: Java If any more information is needed please let me know exactly what you need. Though there are a bunch of files they are small and already done. Modify the driver file ,Starbuzz coffee, to be able to order each blend and be able to add each condiment to each of the blends. The price should be set accordingly. Be able to: order 1 of each type of beverage, add multiple toppings to each ordered beverage and use...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A Add to your project this class Position, which has x and y coordinates. Create an abstract class GameElt, which has a String name, an int health (keep it in the range 0 to 100) and a Position pos. For GameElt, include a default constructor that starts pos at (0, 0), and a parameterized constructor that takes x and y coordinates and a name. health...
Please submit 1) the source code (.java file), and 2) the screenshot of running results of...
Please submit 1) the source code (.java file), and 2) the screenshot of running results of each question. (Factorials) Write an application that calculates the factorial of 20, and display the results. Note: 1) The factorial of a positive integer n (written n!) is equal to the product of the positive integers from 1 to n. 2) Use type long. (Largest and Smallest Integers) Write an application that reads five integers and determines and prints the largest and smallest integers...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT