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

Programming Steps: A. Files required: 1. Artist.java 2. p7artists.java (Input fi

ID: 3807929 • Letter: P

Question

Programming Steps:

A. Files required:
   1. Artist.java
   2. p7artists.java (Input file to read from)
   3. out3A.txt (Output file to write to)

B. Java programs needed to write:
   1. ArtNode.java:
   - Contains:
       1. "previous" and "next" of type ArtNode.
       - By these two variables, you should see that this object will be the node of a doubly linked list.
       2. Constructor:
       - A constructor that accepts six parameters for the six fields.
       3. Getters and Setters for "previous" and "next" fields.
       4. "toString" method that prints the 4 fields of Art class. i.e. artID, artTitle, artistID, artValue.
       - USe the following string format: "%5d %-15s %5d %10.2f".
      
   2. ArtistNode.java :
   - Contains:
       1. Extends Artist class.
       2. "firstNode" and "lastNode" of type ArtNode that was defined above.
      3. "totalEntries" :
       - An integer counter that tally the total number of art Works from the specific Artist.
       4. "totalValue" :
       - A double value that represents the total estimate value of art Work from this artist.
       5. An constructor that accepts artistID and artistName and initialize all other values to either null or 0.
      6. Getters for "totalEntries" and "totalValue".
       7. "toString" method that prints artistID, artistName, totalEntries, totalValue.

   3. MyArtistNodes.java:
   - Contains:
       1. "myArtistNodes" :
       - public, ArrayList of ArtistNode.
       2. A constructor that accepts one string parameter which is the input file name.This constructor will read the input file into the ArrayList "myArtistNodes".
       3. Two print() methods:
       - One takes 2 parameters: A heading and the output File ID. Example : (String Name, String outFile)
       This first print method prints the contents of "file" in REVERSE order to the output file with the heading the first line.
       - Implement Comparable to print the list in REVERSE order.

       - SEcond one prints the list content to the console. (No Parameter)

4. Step3A.java:
  
   public class Step3A
   {
   public Step3A()
       {
       MyArtistNodes myArtists = new MyArtistNodes("p7artists.txt");
       myArtists.print("Name", "out3A.txt");
       }

   }

5. Main.java:
   - Have this method call the Step3A to implement the classes to produce the output similar to below:

Sample Output: (Not complete):

   Name
   20 Rath       , 0 , 0.00
   19 Quiroz   , 0 , 0.00
   18 Prinzen   , 0 , 0.00

Required Programs and text files:

p7artists.txt:

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 static int artistID; // id of artist

private static 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 static String getArtistName() {

return artistName;

}

/**

* set the artistName

*

* @param artistName

*/

public void setArtistName(String artistName) {

this.artistName = artistName;

}

/**

* return the artistId

*

* @return

*/

public static 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);

}

}

Art.java:

public class Art implements java.lang.Comparable<Art> {

// Instance variables
private int artID;
private String artTitle;
private int appraisedValue;

/**
* Constructor
*
* @param artID
* - art id
* @param artTitle
* - title of the art
* @param appraisedValue
* - value
*//*
public Art(int artID, String artTitle, int appraisedValue) {
this.artID = artID;
this.artTitle = artTitle;
this.appraisedValue = appraisedValue;
}

/**
* @return the artID
*//*
public int getArtID() {
return artID;
}

/**
* @return the artTitle
*//*
public String getArtTitle() {
return artTitle;
}

/**
* @return the appraisedValue
*//*
public int getAppraisedValue() {
return appraisedValue;
}

/**
* @param artID
* the artID to set
*//*
public void setArtID(int artID) {
this.artID = artID;
}

/**
* @param artTitle
* the artTitle to set
*//*
public void setArtTitle(String artTitle) {
this.artTitle = artTitle;
}

/**
* @param appraisedValue
* the appraisedValue to set
*//*
public void setAppraisedValue(int appraisedValue) {
this.appraisedValue = appraisedValue;
}
  
public int compareTo(Art o) {
return (this.getArtID() - o.getArtID());
}

@Override
public String toString() {
return String.format("%-6d %-25s %d", artID, artTitle, appraisedValue);
}


}

Explanation / Answer

This cannot possible. The ArrayList<ArtistNode> myArtistNodes cannot store 20 unique ArtistNode objects. Because the artistID and artistName are static member of class Artist which is a super class for ArtistNode. If you try to add a new ArtistNode object to myArtistNodes, then previous objects data will be changed to new object's data.

So, printing in reverse order cannot possible using myArstistNodes and console print also cannot possible with myArtistNodes.If you try to print this array list(myArtistNodes), all the rows will have same data which is recently added ArtistNode into arraylist.

However, anything can be possible(reverse order can be printed in ouput file) but there will be no meaning for modularity of these classes, if you achieve this in some other unreliable way.

Thankyou.

Main.java

class Main{
   public static void main(String a[]){
       Step3A stp = new Step3A();
   }
}


ArtNode.java

class ArtistNode extends Artist{
   private ArtNode firstNode,lastNode;
   private int totalEntries;//An integer counter that tally the total number of art Works from the specific Artist.
   private double totalValue;// A double value that represents the total estimate value of art Work from this artist.
  
   public ArtistNode(String artistName,int artistID){
       super(artistName,artistID);
       this.firstNode = null;
       this.lastNode = null;
       totalEntries = 0;
       totalValue = 0.0;
   }
  
  
   //getters
   public int getTotalEntries(){
       return this.totalEntries;
   }
   public double getTotalValue(){
       return this.totalValue;
   }
  
   public String toString(){
       return super.toString()+" "+getTotalEntries()+" "+getTotalValue();
   }
}


MyArtistNodes.java

import java.util.ArrayList;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
class MyArtistNodes{
   public ArrayList<ArtistNode> myArtistNodes = new ArrayList<ArtistNode>();
   public MyArtistNodes(String fileName){
       //read file into myArtistNodes variable
       try{
           FileReader txtfile = null;
           BufferedReader br = null;
           StringBuilder sb = null;
           txtfile = new FileReader(fileName);
           br = new BufferedReader(txtfile);
           sb = new StringBuilder();
           String line = br.readLine();
           while (line != null) {
              
               String str[] = line.split("   ");
               ArtistNode an = new ArtistNode(str[1],Integer.parseInt(str[0]));
              
               System.out.println(an);
               myArtistNodes.add(an);
               //System.out.println(str[1]+"-"+Integer.parseInt(str[0]));
              
               line = br.readLine();
           }
           br.close();
           txtfile.close();
       }
       catch(IOException e){
           System.out.println("Some error in reading input file!!!");
       }
   }
   public void print(String Name, String outFile) {
       //This first print method prints the contents of "file" in REVERSE order
       // to the output file(out3A.txt) with the heading the first line.
     
      
   }
   public void print() {
       //prints list contents
      
       for(ArtistNode an:myArtistNodes){
           System.out.println(an);
       }
      
   }
}


ArtNode.java

class ArtNode{
   private ArtNode previous,next;
   private int artID;
   private String artTitle;
   private int artistID;
   private double artValue;
  
   public ArtNode(ArtNode previous,ArtNode next,int artID,String artTitle,int artistID,double artValue){
       //accept 6 parameters.
       this.previous = previous;
       this.next = next;
       this.artID = artID;
       this.artTitle = artTitle;
       this.artistID = artistID;
       this.artValue = artValue;
   }
  
   public ArtNode getPrevious(){
       return this.previous;
   }
   public ArtNode getNext(){
       return this.next;
   }
  
   public void setPrevious(ArtNode previous){
       this.previous = previous;
   }
   public void setNext(ArtNode next){
       this.next = next;
   }
  
   public String toString(){
       return String.format("%5d %-15s %5d %10.2f", this.artID, this.artTitle, this.artistID, this.artValue);
   }
}