-1

My professor really threw us into this project with a blindfold on. We didn't go into depth on using and inserting files into Java. I'm getting a ton of errors, which are most likely due to my incorrect insertion of the file. I saved the text file in the same place the class file is saved on my computer, assuming that would be necessary. I've moved it around multiple places on my computer trying to get it to work. Here is the main program. I'm sorry if it's completely incorrect.

To explain what we're supposed to be doing further, here is the link to the prompt with the pseudocode. I haven't attempted to do all the actions listed because I haven't gotten the file to insert correctly yet. http://jcsites.juniata.edu/faculty/rhodes/cs1/projects/program9Gen.html

Edit: This is the whole program in its glory. The class was created in a separate project as our introduction to Java classes. We were just told to use it again and insert the main program at the bottom just for ease of grading.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GenSeq
{
   private String seq;
   private String species;
   private String startCodon;
   private String stopCodon;
   private String shape;
   private String chromosomeLocation;

   public GenSeq (String seq, String species, String startCodon, String stopCodon,
   String shape, String chromosomeLocation){
     this.seq = seq;
     this.species = species;
     this.startCodon = startCodon;
     this.stopCodon = stopCodon;
     this.shape = shape;
     this.chromosomeLocation = chromosomeLocation;
   }
   //Allowing the program to later set constructors

   //Creating all the appropriate getters and setters for the instance variables
   public void setSpecies(String newSpecies){
      species = newSpecies;
   }

   public String getSpecies(){
      return species;
   }

   public void setStartCodon(String newStartCodon){
      startCodon = newStartCodon;
   }

   public String getStartCodon(){
      return startCodon;
   }

   public void setStopCodon(String newStopCodon){
      stopCodon = newStopCodon;
   }

   public String getStopCodon(){
      return stopCodon;
   }

   public void setShape(String newShape){
      shape = newShape;
   }

   public String getShape(){
      return shape;
   }

   public void setChromosomeLocation(String newChromosomeLocation){
      chromosomeLocation = newChromosomeLocation;
   }

   public String getChromosomeLocation(){
      return chromosomeLocation;
   }

   public String toString(){
     return "Sequence length: " + seq.length() +
                       "\nSpecies: "+ species +
                       "\nStart Codon: "+ startCodon +
                       "\nStart Codon: "+ stopCodon+
                       "\nShape: "+ shape +
                       "\nChromosomal Location: " + chromosomeLocation;
     //Creating a toString method to hold all the class data
   }
}



public static void main (String args[ ])
{
  GenSeq seqA = null;
  //Setting constructor to default if not set
  //Opening the file
  Scanner inputStream = null;
  String seq;

  try
  {
    inputStream = new Scanner (new File ("W:\jcsites.junata.edu\students\morrian14\seq.txt"));
  }
  catch (FileNotFoundException e)
  {
    System.out.println ("Error opening the file ");
    System.exit (0);
  }
  do{
    inputStream = inputStream.trim();
    if ('>' == inputStream.charAt(0)){
      seq = inputStream.nextLine();
    }
  }
  while (inputStream.hasNextLine());
  inputStream.close();


}

The error is this same one repeated continuously

File: C:\LEXIPC\Users\Alexis\GenSeq.java [line: 83] Error: class, interface, or enum expected

Lexi
  • 1
  • 2
  • Welcome to StackOverflow. What is the desired effect of the program and what is it doing right now? Refer to [ask] if you want to increase your chances of receiving a helpful answer. Also, if you have errors, please post the stacktrace. – Aify Mar 20 '15 at 00:31
  • The {do while} is entirely unnecessary here, though I'm not sure why you're really asking. – Fiery Phoenix Mar 20 '15 at 00:58
  • `Scanner.charAt()` and `Scanner.trim()` do not exist. This code does not compile. – user207421 Mar 20 '15 at 01:09
  • Are you importing the correct references? Is that all your code? Also your IDE should have an error description post it here. – R Quijano Mar 20 '15 at 01:10
  • I edited the original post to have the entire code and a full explanation of the program. Sorry for the confusion. – Lexi Mar 20 '15 at 01:27
  • Same comment. You're really expected to be able to fix your own compile errors. You've just made up APIs that don't exist; you have braces in the wrong place; and you have an illegal string literal. Use the documentation. – user207421 Mar 20 '15 at 01:46
  • Move you main method inside the class definition. – R Quijano Mar 21 '15 at 15:23

2 Answers2

0

One obvious issue, the last line is clearly meant to have been written as inputStream.close(); and not input.Stream.close(); you will probably need a try .. catch ... around closing the stream too

echen
  • 2,002
  • 1
  • 24
  • 38
0

What exactly is your question? A few notes though... Get rid of the do{} while() and just do something like this:

while(inputStream.hasNextLine(){
    if('>' == inputStream.charAt(0))
        seq = inputStream.nextLine();
}
inputStream.close();

I am a bit confused as to why you are recycling seq to read from the file, as that is what you are using as your file's name. A better way to do this would be to use a File class for your file names. Consider: File seq = new File(.../filename.txt). Also, if you find that you are using too many try/catch blocks, consider using an exception handling class to clean up your code.

peter
  • 78
  • 9