Runner13's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 10 (0.06 per day)
- Joined:
- 05-December 12
- Profile Views:
- 290
- Last Active:
Dec 12 2012 08:45 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: How do I write a if statement to return the difference in an array?
Posted 12 Dec 2012
I recieve an error in my code...
import java.io.*; import java.util.Scanner; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.util.Scanner; import java.util.Locale; public class Stock { private static void blackenRect (Picture p, int xMin, int yMin, int xMax, int yMax) { for(int x = xMin; x <= xMax; x++) { for(int y = yMin; y <= yMax; y++) { Pixel pix = p.getPixel(x , y); pix.setColor(java.awt.Color.BLACK); } } } private final int MAXEVERNPRICES = 366 * 5; private double movingAvgs[]; public void Plot() { System.out.println("Hi from Plot()!"); Picture p = new Picture(3 * numberOfDaysWithData, 900); int arrayIndex = 0; while( arrayIndex < numberOfDaysWithData ) { blackenRect(p,3*arrayIndex,0, 3*arrayIndex+2, (int)dailyPrices[ arrayIndex] ); arrayIndex=1+arrayIndex; } p.explore(); } public void readAndPlot(String fileName) { BufferedReader myReader=null; try { myReader = new BufferedReader(new FileReader(fileName)); } catch(FileNotFoundException e) { e.printStackTrace(); } int arrayIndex = 0; this.numberOfDaysWithData = 0; dailyPrices = new double[MAXEVERNPRICES]; Scanner sc = null; try { sc = new Scanner(myReader); sc.useLocale(Locale.US); while ((this.numberOfDaysWithData < MAXEVERNPRICES) && sc.hasNext()) { if (sc.hasNextDouble()) { double currPrice=sc.nextDouble(); dailyPrices[arrayIndex] = currPrice; arrayIndex=arrayIndex+1; this.numberOfDaysWithData++; } else { sc.next(); } } } finally { sc.close(); } //Purpose: Track the LOCATION within //the stock price array of WHERE to //copy the next price that will be //read by the Scanner out of the file. this.Plot(); this.PlotMovingAvg(); } //Fields double lastPChange; double[] dailyPrices; int numberOfDaysWithData; public void addTrade(double price) { dailyPrices[numberOfDaysWithData] = price; numberOfDaysWithData = numberOfDaysWithData + 1; this.numberOfDaysWithData++; lastPChange = (numberOfDaysWithData - 2); } public int numTrades() { return numberOfDaysWithData; } public double lastPriceChange() { int len = dailyPrices.length; if(len < 2) { return lastPChange = (numberOfDaysWithData - 2); } else { return 0; } } public static void main(String[] a) { //FileChooser.pickMediaPath(); Stock myP = new Stock(); myP.readAndPlot(FileChooser.pickAFile()); } }
The error is:: java.lang.IllegalArgumentException: Width (0) and height (900) cannot be <= 0 -
In Topic: How do you find the MAX height of a Picture?
Posted 8 Dec 2012
oh, well this is the code my professor posted up for us to test our Album.java class
import java.util.Scanner; class AlbumTester { private static void printChoices() { System.out.println("add\nadd <0 or positive int>\nshow\nquit"); } public static void main(String[] asdf) { Scanner sc = new Scanner(System.in); System.out.println("Album capacity:"); int requestedCapacity = sc.nextInt(); sc.nextLine(); //Read and throw away the newline after the int Album myAlbum = new Album(requestedCapacity); System.out.println("Pick the directory for your digital images."); FileChooser.pickMediaPath(); boolean stillChoosing = true; int nAdds = 0; while( stillChoosing ) { printChoices(); String choice = sc.nextLine(); if(choice.equals("quit")) { System.out.println("Thanks for the test!"); stillChoosing = false; } else if(choice.equals("add")) { System.out.println("You chose add"); Picture p = new Picture(FileChooser.pickAFile()); boolean added; added = myAlbum.addPicture(p); if(added) nAdds++; else System.out.println("addPicture(Picture) returned false."); } else if(choice.equals("show")) { System.out.println("You chose show"); System.out.println("You should see " + nAdds + " images in your Album"); myAlbum.explore(); } else if(choice.startsWith("add ")) { System.out.println("Your choice started with \"add \"."); String[] tokens = choice.split("\\s+"); //Purpose: Split the input line into tokens separated by whitespace int inputNumber = 0; boolean inputNumberOK = false; try { inputNumber = Integer.parseInt(tokens[1]); inputNumberOK = true; } catch (NumberFormatException e) { System.out.println("Whoops, you mistyped the number after add!"); } if(inputNumberOK) { Picture p = new Picture(FileChooser.pickAFile()); boolean added; added = myAlbum.addPicture(p,inputNumber); if(added) nAdds++; else System.out.println("addPicture(Picture,int) returned false."); } } else { System.out.println("The command to the tester was not recognized."); System.out.println("Try again."); } } return; } } -
In Topic: How do you find the MAX height of a Picture?
Posted 8 Dec 2012
Their is no source code for a picture class.
This is the code my professor gave us to work on for our Project.
We have to create a Album for a collection of pictures.
public class Album { private int nPictsInAlbum; private Picture[] pictArray; private int capacity; public Album(int capacityParam ) { System.out.println("Album( " + capacityParam + " ) constructor called."); //Remove the above line for Project 5. capacity = capacityParam; //You must add more.. } public boolean addPicture( Picture p ) { System.out.println("addPicture( p ) called. The Picture object param. printed as a String is"); System.out.println( p ); return true; } public boolean addPicture( Picture p, int where ) { System.out.println("addPicture( p , " + where + " ) called. The Picture object param. printed as a String is"); System.out.println( p ); return true; } public void explore() { System.out.println("explore called"); } } -
In Topic: How do you find the MAX height of a Picture?
Posted 8 Dec 2012
Album is the class. The explore method is to create a new picture (user choose a picture) whose height is the max of the heights, and width is the sum of the widths of the stored pictures in the album. The pictures in the Album are
copied into a new picture and that Picture is displayed by calling the explore() method on it. All the added Picture copies should start at the top of the new Picture and be laid out horizontally, with no overlaps or gaps. -
In Topic: How do you find the MAX height of a Picture?
Posted 8 Dec 2012
We just have to create a new class to create a picture album.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
Runner13 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
Runner13 has no profile comments yet. Why not say hello?