I have created an array of objects(cups) which I have set a volume and capacity and colour too, all of this is displayed by calling .display() However I can get the display() to do this in this instance when trying to loop through the array of cups. I get no output to show the cups capacity and colour from the display() method, I have added the two bits of code, one in the cups class that contains the display method and the first one which shows me trying to create an array and display each cup. I would deeply appreciate any help as this is a part of a school assignment.
screenshot of current output
public static void main(String[] args)
{
//Makes Array of cups
Cup [] Cups = new Cup[4];
// Creates 4 Cups with 250 capacity and black colour
for(int i = 0 ; i > 4 ; i++)
{
Cups[i] = new Cup (250, ContainerColour.BLACK );
Cups[i].display();
}
//Teapot, Wash and then fill with tea
TeaCup myTeaCup = new TeaCup();
myTeaCup.Wash();
myTeaCup.Fill();
myTeaCup.display();
}
my cups oop code :
// ---------------------------------------------------------------------
// class variables
// ---------------------------------------------------------------------
private ContainerColour myColour;
private int iCapacity;
private int iVolume;
private int iTemp;
private int iFill;
private String SzMaterial;
private Boolean bEmpty;
// ---------------------------------------------------------------------
// Constructors
// ---------------------------------------------------------------------
public Cup()
{
super();
reset();
return;
}
public Cup (Cup original) {
iCapacity = original.getCapacity();
iVolume = original.getVolume();
SzMaterial = original.getMaterial();
}
public Cup(int size)
{
this();
super.setCapacity(size);
setColour(ContainerColour.NOT_SET);
return;
}
public Cup (int size , ContainerColour colour)
{
this (size);
setColour(colour);
return;
}
//setters
public void setColour(ContainerColour c)
{
myColour = c;
}
//getters
public ContainerColour getColour()
{
return(this.myColour) ;
}
//main
public void display()
{
System.out.println("Cup: \nCapacity = " + getCapacity());
System.out.println("Volume = " + getVolume());
System.out.println("Colour = " + getColour() );
if(iVolume == 0) {
bEmpty = true;
}
else {
bEmpty = false;
}
System.out.println("Empty = " + bEmpty );
return;
}
public static void main(String[] args) {
Cup myCup = new Cup();
myCup.setCapacity(250);
myCup.setColour(ContainerColour.WHITE);
myCup.Wash();
myCup.fill();
myCup.display();
}
public static void main(String[] args)
{
//Makes Array of cups
Cup [] Cups = new Cup[4];
// Creates 4 Cups with 250 capacity and black colour
for(int i = 0 ; i < 4 ; i++)
{
Cups[i] = new Cup (250, ContainerColour.BLACK );
Cups[i].display();
}
//Teapot, Wash and then fill with tea
TeaCup myTeaCup = new TeaCup();
myTeaCup.Wash();
myTeaCup.Fill();
myTeaCup.display();
}
So if of all you made mistake in coding loop it should be less than 4 and secondly array index start with zero it means when you reach 3 you will iterate all objects in array Cups.
Instead of hard-coding the 4, use the actual array itself to determine the length and use that in your for loop:
for(int i=0; i<Cups.length; i++) {
Cups[i] = new Cup (250, ContainerColour.BLACK );
Cups[i].display();
}
Related
I'm trying to understand the benefits of multithreading much better. I have with me a serialised implementation of a parking lot simulation. I want to make it so that the program uses Executor services instead, how would I go about doing that?
Below is my parking-lot class, the implementation could definitely be refined, I just can't seem to figure out how to.
public class Parking {
public static void main(String[] args) throws InterruptedException {
Parking parkingObj = new Parking();
parkingObj.runSimulation();
}
public void runSimulation() throws InterruptedException{
int numOfRuns = 101;//100 runs
int currentRuns = 1;
securityGuard myGuard = new securityGuard();
//spot mySpot = new spot();
ArrayList<ticketClass> ticketArray = new ArrayList<>();
int bouncedCustomers = 1;
spot availableSpot = new spot();
//Random randomExit = new Random();
while (currentRuns < numOfRuns){
Random randomSleep = new Random();
//Car object instantiation
carClass vehicle = new carClass();
//ticketClass ticketObj = new ticketClass();
//Random time generator
Random randomTime = new Random();
//instantiation of the info geneatator class
infoGenerator info = new infoGenerator();
//Generaring random Car info
String plateNumber = info.plateGenerator();
String carModel = info.modelGenerator();
String color = info.colorGenerator();
if (availableSpot.getSpotNum() == 15 ){
System.out.println("Carpark full, No cars allowed unitl a space is free");
//Customers waiting for free space
Thread.sleep(9000);
System.out.println("Total Waiting customers: " + bouncedCustomers);
bouncedCustomers += 1;
}
else{
//System.out.println("Customer Exiting");
Thread.sleep(randomTime.nextInt(5000));
meterClass myMeter = new meterClass();
ticketClass myTicket = myGuard.ticketGenerator(vehicle, myMeter);
//ticketClass myTicket = new ticketClass();
myTicket.setmeter(myMeter);
myTicket.setCar(vehicle);
myTicket.getCar().plateSetter(plateNumber);
myTicket.getCar().colorSetter(color);
myTicket.getCar().modelSeter(carModel);
myTicket.getCar().minSetter(randomTime.nextInt(100));
//Details are only set if there is space available
//The assumption is that users cannot stay longer than 2 days. The reality-to-simulation time ratio is 1 unit:10min
myMeter.setPurchasedMinutes(randomTime.nextInt(72));
System.out.println("\n\nCar " + currentRuns + " has entered the car park");
System.out.println("\nCAR DETAILS:");
System.out.println(carModel);
System.out.println(plateNumber);
System.out.println(color);
int spotAvail = availableSpot.assignSpot();
myTicket.setSlotNum(spotAvail);
//Set the time the car entered
String timeIn = info.timeMonitor();
//myTicket.
ticketArray.add(myTicket);
System.out.println("\n\n===Total customers: " + ticketArray.size());
System.out.println(timeIn+"\n");
availableSpot.spotLog();
}
//Cars leaving at random times
for (int i= 0; i < ticketArray.size();i++ ){
meterClass meterOut = ticketArray.get(i).getMeter();
carClass ExitCar = ticketArray.get(i).getCar();
if(myGuard.checkParking(ExitCar,meterOut)){
System.out.println("\nCustomer " + ExitCar.plateGetter()+ " is exiting the carpark...");
double penaltyVal = ticketArray.get(i).getPenalty();
System.out.println("FINE: " + penaltyVal);
System.out.println("==================================================================");
Thread.sleep(randomTime.nextInt(4000));
ticketArray.remove(ticketArray.remove(i));
availableSpot.spotFree(i);
}
}
currentRuns += 1;
}
}
}
TLDR: I need to optimise the following code, both structure-wise and in terms of speed (Specifically using multithreading with Executor service)
As it currently is, it runs in an infinite loop, and the fine value is 0. The security guard class which is responsible for this calculation is as such;
public class securityGuard{
public String badgeNumber;
public String guardName;
securityGuard(){}
securityGuard(String badgeNumber, String guardName){
this.badgeNumber = badgeNumber;
this.guardName = guardName;
}
public void setBadgeNumber(String badgeNumber){
this.badgeNumber = badgeNumber;
}
public String getBadgeNumber(){
return badgeNumber;
}
public void setguardName(String guardName){
this.guardName = guardName;
}
public String getGuardName(){
return guardName;
}
public boolean checkParking(carClass car,meterClass meter){
return car.minGetter() > meter.getPurchasedMinutes();
}
public ticketClass ticketGenerator(carClass car, meterClass meterVar){
ticketClass myTicket = new ticketClass(car,this);
int timeRemaining = car.minGetter() - meterVar.getPurchasedMinutes();
if(checkParking(car,meterVar)){
if (timeRemaining < 60){
myTicket.penalty = 50;
}
else {
myTicket.penalty = 50 + (10 * (timeRemaining/60));
}
}
return myTicket;
}
}
Please let me know if you require any additional information regarding the other classes or if I left anything out .Thank you in advance
I have an assignment which I have to program that creates a standings table from match list input. I used the word "infinite" because input size is unknown so I have to create a program that works until there's no matches left. I created a football class for this(input contains 2 other sports and their own matches and teams indicating the sports type with first letter of the sport with "F, B, V" for example, they're only different in scoring part, so I though if I can make football work, I can make anything else work) that contains everything required in standings table, and methods for match results which looks like this:
public class Football {
private int scoredGoals;
private int receivedGoals;
private String teamName;
private int Score;
private int wins;
private int losses;
private int MatchCount;
private int draws;
public void teamValues(String teamName, int Sgoals, int Rgoals) {
this.teamName = teamName;
this.scoredGoals = Sgoals;
this.receivedGoals = Rgoals;
}
public void matched() {
MatchCount++;
}
public void winner() {
wins++;
}
public void draw() {
draws++;
}
public void loser() {
losses++;
}
public void winScore() {
Score += 3;
}
public void drawScore() {
Score += 1;
}
public String showTeams() {
return (teamName + " " + MatchCount + " " + wins + " " + draws + " " + losses + " " + scoredGoals+":"+receivedGoals + " " + Score);
}
}
And in main class I'm calling methods in if blocks to calculate wins, score, matches count etc. And main looks like this:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("input.txt");
Scanner scan = new Scanner(file);
String fileString = "";
Football teams[] = new Football[2];
HashSet<String> teamsArray = new HashSet<String>();
while(scan.hasNextLine()) {
fileString = scan.nextLine();
String[] match = fileString.split("\\t|:");
if(match[0].equals("F")) {
int team1score = Integer.valueOf(match[3].trim());
int team2score = Integer.valueOf(match[4].trim());
teams[0] = new Football();
teams[0].teamValues(match[1], team1score, team2score);
teams[1] = new Football();
teams[1].teamValues(match[2], team2score, team1score);
teams[0].matched();
teams[1].matched();
if(team1score>team2score) {
teams[0].winner();
teams[1].loser();
teams[0].winScore();
}
if(team1score==team2score) {
teams[0].draw();
teams[1].draw();
teams[0].drawScore();
teams[1].drawScore();
}
if(team1score<team2score) {
teams[1].winner();
teams[0].loser();
teams[1].winScore();
}
String team0 = teams[0].showTeams();
String team1 = teams[1].showTeams();
teamsArray.add(team0);
teamsArray.add(team1);
}
}
scan.close();
}
}
Since the input is static, I used arrays to work around. My problem with my code is I cant find a way to store my teams without duplicates and the variables that comes within and update whenever that team has another match.
I tried;
Storing them in a 2D string array but since the amount of teams is unknown I think it won't be a healthy way to approach to the problem.
Storing them in a String[] array list, which ended up storing the adresses instead of the values of the teams.
Set which I still use to check if at least the methods are working as intended.
It feels like I hit the wall with this program and I need to start over, so any kind of advice is appreciated.
Here's an example of input and output:
Input:
Home Team Guest Team H : G
F Manchester U. Chelsea 2 : 2
F Liverpool Manchester City 3 : 2
F Leicester City Everton 1 : 3
V Team A Team B 3 : 0
F Tottenham Liverpool 3 : 1
B Team B Team A 90 : 96
F West Ham Manchester U. 2 : 1
F Arsenal Manchester City 0 : 2
F Chelsea Arsenal 3 : 3
Output:
Name Matches Wins Draw Lose Scored:Received Score
1. Manchester U. 10 6 2 2 27:22 20
2. Arsenal 10 6 2 2 25:24 20
3. Chelsea 10 5 3 2 28:20 18
4. Liverpool 10 4 4 2 22:19 16
5. Tottenham 10 4 4 2 22:21 16
There are teams with same scores, because calculating average of scored and received goals is another way to sort the teams.
First some changes to the Football class:
Override equals to be able to search the list
Override compareTo for sorting
Override toString instead of showTeams
Create a constructor
Combine most functions into teamValues
import java.util.Formatter;
public class Football implements Comparable<Football> {
private int scoredGoals;
private int receivedGoals;
private String teamName;
private int score;
private int wins;
private int losses;
private int draws;
private int matchCount;
public int compareTo(Football f) {
return score - f.score;
}
public boolean equals(Object o) {
if (o == null) {
return false;
}
else if (o instanceof Football) {
return teamName.equals(((Football)o).teamName);
}
else if (o instanceof String) {
return teamName.equals((String)o);
}
return false;
}
public Football(String teamName) {
this.teamName = teamName;
}
public void teamValues(int scoredGoals, int receivedGoals) {
this.scoredGoals += scoredGoals;
this.receivedGoals += receivedGoals;
matchCount++;
if (scoredGoals < receivedGoals) {
losses++;
}
else if (scoredGoals > receivedGoals) {
wins++;
score += 3;
}
else {
draws++;
score += 1;
}
}
public String toString() {
return new Formatter().format("%-20s %3d %3d %3d %3d %3d:%-3d %d",
teamName, matchCount, wins, draws, losses, scoredGoals, receivedGoals, score)
.toString();
}
}
For the main program, you don't want to create a new team every time - only when a team is first encountered in the file. Put all the teams in a List. When parsing a new game, first try to find the team in the list. If it is not in there, add it.
List<Football> teamsArray = new ArrayList<>();
while (scan.hasNextLine()) {
fileString = scan.nextLine();
String[]match = fileString.split("\\t|:");
if (match.length == 5 && match[0].equals("F")) {
int team1score = Integer.valueOf(match[3].trim());
int team2score = Integer.valueOf(match[4].trim());
// Create a temp team to search the List
Football team1 = new Football(match[1]);
// Search the list
if (!teamsArray.contains(team1)) {
// Not in the list already. Add it
teamsArray.add(team1);
}
else {
// Already in the List. Use that one.
team1 = teamsArray.get(teamsArray.indexOf(team1));
}
// Repeat for team 2
Football team2 = new Football(match[2]);
if (!teamsArray.contains(team2)) {
teamsArray.add(team2);
}
else {
team2 = teamsArray.get(teamsArray.indexOf(team2));
}
team1.teamValues(team1score, team2score);
team2.teamValues(team2score, team1score);
}
}
System.out.println("Name M W D L S:R S");
// Sort and print
teamsArray
.stream()
.sorted(Comparator.reverseOrder())
.forEach(t -> System.out.println(t));
so for an assignment I've had to create a building class i was given the bare bones of the code and I've got this far the part I'm struggling on is setting the size of the x and y coordinate which needs to be in setBuilding().
This is the desired output of the class:
Building size 11×11
Room from (0,0) to (5, 5) door at (3, 5)
Room from (6,0) to (10, 10) door at (6, 6)
Room from (0,5) to (5, 10) door at (2, 5)
The program displays everything apart from the "Building size 11×11", I'm not looking for someone to do the work for me just want to be pointed in the right direction.
Thanks for any help
import java.util.*;
public class Building {
private int xSize = 10; // size of building in x
private int ySize = 10; // and y
private ArrayList<Room> allRooms; // array of rooms
Building (String first) {
allRooms = new ArrayList<Room>();
setBuilding(first);
}
public void setBuilding(String bS) {
String[] Space;
allRooms.clear();
Space = bS.split(";");
allRooms.add(new Room(Space[1]));
allRooms.add(new Room(Space[2]));
allRooms.add(new Room(Space[3]));
}
public String toString() {
String s;
s = " ";
for (Room r : allRooms) {
s = s + r.toString();
}
return s;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Buidling test\n");
Building b = new Building("11 11;0 0 5 5 3 5;6 0 10 10 6 6;0 5 5 10 2 5"); // Create
System.out.println("built building\n");
System.out.println(b.toString()); // And print
}
}
you didn't add any declaration to your toString for showing the building dimensions. I assume you want to use the xSize and ySize of the building. Also note that you're not extracting the building dimensions from the buidlString you pass to setBuilding.
Change your toString to the code below.
public String toString() {
String s = "Building size" + xSize + ", " + ySize;
for (Room r : allRooms) {
s += r.toString();
}
return s;
}
for defining your building size:
public void setBuilding(String bS) {
String[] Space;
allRooms.clear();
Space = bS.split(";");
//Here we'll update the requested building size
String[] buildingSize = Space[0].split(" "); //split the two integers
xSize = Integer.ParseInt(buildingSize[0]); //transform the string to int
ySize = Integer.ParseInt(buildingSize[1]); //transform the string to int
allRooms.add(new Room(Space[1]));
allRooms.add(new Room(Space[2]));
allRooms.add(new Room(Space[3]));
}
We have a practical test on Java about an IceCream shop. We need to handle exceptions in case no more stock. The code from the app below works fine. Exceptions are properly managed.
public class IceCreamApp2 {
public static void main(String[] args) {
Prijslijst priceList2 = new Prijslijst(2, 5, 8);
Stock stock = new Stock(1, 8, 2, 1);
IceCreamCar iceCar = new IceCreamCar(priceList2, stock);
try {
Eatable[] eatCar = {
iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.CHOCOLATE, Cone.Flavor.BANANA, Cone.Flavor.VANILLA}),
iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.VANILLA, Cone.Flavor.VANILLA}),
iceCar.orderMagnum(Magnum.MagnumType.ROMANTICSTRAWBERRIES),
iceCar.orderMagnum(Magnum.MagnumType.ALPINENUTS),
iceCar.orderIceRocket()
};
for (int i = 0; i < eatCar.length; i++) {
eatCar[i].eat();
}
System.out.println(iceCar.getProfit());
} catch (NoMoreIceCreamException noMoreIce) {
System.out.println("No More Ice To sell... Beat it!!");
System.out.println("Message: " + noMoreIce.getMessage());
System.out.println("Cause: " + noMoreIce.getCause());
}
System.out.println(iceCar.getProfit());
}
}
However this logic is flawded, since it stops counting the rest of order when an exception appears. Therefore Magnums and Icerockets, despite they 're in stock, are not counted in profit.
To do this, we know we need to loop through the table "Eatable". But it doesn't work and exit code 1 with the exception:
public class IceCreamApp2 {
public static void main(String[] args) {
Prijslijst priceList2 = new Prijslijst(2, 5, 8);
Stock stock = new Stock(1, 8, 2, 1);
IceCreamCar iceCar = new IceCreamCar(priceList2, stock);
Eatable[] eatCar = {
iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.CHOCOLATE, Cone.Flavor.BANANA, Cone.Flavor.VANILLA}),
iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.VANILLA, Cone.Flavor.VANILLA}),
iceCar.orderMagnum(Magnum.MagnumType.ROMANTICSTRAWBERRIES),
iceCar.orderMagnum(Magnum.MagnumType.ALPINENUTS),
iceCar.orderIceRocket()
};
for (int i = 0; i < eatCar.length; i++) {
try {
eatCar[i].eat();
} catch (NoMoreIceCreamException noMoreIce) {
System.out.println("No More Ice To sell... Beat it!!");
System.out.println("Message: " + noMoreIce.getMessage());
System.out.println("Cause: " + noMoreIce.getCause());
}
}
System.out.println(iceCar.getProfit());
}
}
Any clue what can be wrong ?
Here is the stack trace :
Preparing your Balls on a cone
Exception in thread "main" Seller.NoMoreIceCreamException: No more Balls or Cones
at Seller.IceCreamCar.prepareCone(IceCreamCar.java:39)
at Seller.IceCreamCar.orderCone(IceCreamCar.java:30)
at App.IceCreamApp2.main(IceCreamApp2.java:18)
Process finished with exit code 1
#Andrew S the condition is already handled in the class “IceCreamCar”. In short:
public class IceCreamCar implements IceCreamSeller {
// Instance Variables
Prijslijst priceList;
Stock stock;
private double profit;
// Constructor
public IceCreamCar() {
}
public IceCreamCar(Prijslijst priceList, Stock stock) {
this.priceList = priceList;
this.stock = stock;
}
// Methods
// Order Cone
#Override
public Cone orderCone(Cone.Flavor[] balls) {
this.prepareCone(balls);
return new Cone(balls);
}
// // Prepare Cone
private Cone prepareCone(Cone.Flavor[] balls) {
int countCones = 1;
if (stock.getCones() < 0 || stock.getBalls() < 0) {
throw new NoMoreIceCreamException("No more Balls or Cones");
} else {
for (int i = 0; i < balls.length; i++) {
stock.setBalls(stock.getBalls() - balls.length);
profit += priceList.getBallPrice();
}
System.out.println("Preparing your Balls on a cone");
countCones++;
stock.setCones(stock.getCones() - countCones);
}
return new Cone(balls);
}
thanks to both of you for your answer :)
Ok, so problem solved. Actually the solution is to put the try and catch in each of the orderCone, orderMagnum, etc...
That was exceptions are handled properly.
This code looks through hundreds of names and finds the popularity and meaning of them. I have two questions. what I am trying to accomplish where the error is, is to print text of the meaning of the name on to the top of my graph.
1. How can I fix this error:
BabyNames.java:82: error: cannot find symbol
String meanings = findingStatistics(console,meaningsFile);
2. By the time findingStatistics runs through twice, variable statistics is only holding the information for the meaning of the name. How can I access the popularity of the name to use my graph? Right now I have the whole method equal to the statistics, which is just the meaning.
Here is my code:
import java.util.*;
import java.io.*;
import java.awt.*;
public class BabyNames{ //ADD COMMENTS
public static final int STARTINGYEAR = 1890;
public static final int WIDTH = 60;
public static final int HEIGHT = 30;
private static String nameFinal;
public static void main(String[] args) throws FileNotFoundException{
Scanner console = new Scanner(System.in);
DrawingPanel panel = new DrawingPanel(780,560);
Graphics g = panel.getGraphics();
Scanner nameFile = new Scanner(new File("names.txt"));
Scanner meaningsFile = new Scanner(new File("meanings.txt"));
Scanner nameFile2 = new Scanner(new File("names2.txt"));
intro();
fixedGraph(g);
nameFinal = nameToLowerCase(console);
if(STARTINGYEAR == 1890){
findingStatistics(console,nameFile);;
changingGraph(console,g);
}
else{
findingStatistics(console, nameFile2);
changingGraph(console,g);
}
findingStatistics(console,meaningsFile);
}
public static void intro(){
System.out.println("This program allows you to search through the");
System.out.println("data from the Social Security Administration");
System.out.println("to see how popular a particular name has been");
System.out.println("since 1890" );
System.out.println();
System.out.print("Name: ");
}
public static String nameToLowerCase(Scanner console){
String originalName = console.next();
String name = "" ;
int lengthOfName = originalName.length();
String beginingOfName = originalName.substring(0,1).toUpperCase();
String endOfName = originalName.substring(1,lengthOfName).toLowerCase();
name = beginingOfName + endOfName;
return name;
}
public static String findingStatistics(Scanner console, Scanner data){
// String nameFinal = nameToLowerCase(console);
boolean goesThroughOnce = false; //
String statistics = "";
String currWord = "";
String currLine = "";
while (data.hasNext() && goesThroughOnce == false){
currLine = data.nextLine();
Scanner lineBeingRead = new Scanner(currLine); //make other scanners?? for each file
currWord = lineBeingRead.next(); //
if (currWord.equals(nameFinal) || currWord.equals(nameFinal.toUpperCase())){ //
statistics = currLine;
goesThroughOnce = true;
System.out.println(statistics);
}
else{
}
}
return statistics;
}
public static void fixedGraph(Graphics g){ //Draws fixed things such as gray blocks and black lines
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0,0,780,HEIGHT);
g.fillRect(0,560-HEIGHT,780,HEIGHT);
g.setColor(Color.BLACK);
g.drawLine(0,HEIGHT,780,HEIGHT);
g.drawLine(0,560-HEIGHT,780,560-HEIGHT);
}
public static void changingGraph(Scanner console, Graphics g){
String meanings = findingStatistics(console,meaningsFile);
g.drawString("" + meanings,0,16); //draws meaning text
int startingYear = STARTINGYEAR;
int amountOfDecades = 0;
if(startingYear == 1890){
amountOfDecades = 13;
}
else{
amountOfDecades = 8;
}
g.drawString("" + startingYear,0,552); //fencepost
for(int i=0; i<=amountOfDecades;i++){
int year = startingYear + (10 * i);
g.drawString("" + year,(WIDTH*i),552); //draws decade numbers
}
}
}
If I add a // on what the error was and not include that, just so one can understand the code better, for the name "Aaron" it should print out:
Name: AARON
Aaron f 0 0 0 0 0 0 0 0 0 883 0 0 0
AARON m English, Biblical From the Hebrew name ??????? ('Aharon) which is most likely of unknown Egyptian origin.
Shortly, I'm trying to make it print text on the graph, and making two variables for the meaning and popularity (I have them both under statistics).
Your changingGraph method is only using console in order to work out meanings, for which of course, it also needs meaningsFile. It would make far more sense to remove the call to findingStatistics from changingGraph, especially since you are calling it from main anyway.
So change the signature of changingGraph so that it takes meanings as a parameter, as well as removing the first line of the method body. It will then look like this.
public static void changingGraph(String meanings, Graphics g){
g.drawString("" + meanings,0,16); //draws meaning text
// ... and so on.
Then, when you call it, pass the value that was returned from the previous call to findingStatistics. So in your main method, you'll have this.
if(STARTINGYEAR == 1890){
findingStatistics(console,nameFile);
}
else{
findingStatistics(console, nameFile2);
}
String meanings = findingStatistics(console, meaningsFile);
changingGraph(meanings, g);