Why are my codes error today and fine yesterday?

import java.util.Scanner;

public class CarTest {

    /**
 * @param args
 */
public static void main(String[] args) { 
    //create a Scanner object
    Scanner input = new Scanner(System.in);

    /**
     *Creates a car! object from the Car class
     *with the passing of these arguments
     *year, make, model, price
     */
    Car car1 = new Car("2008", "Nissan", "Pathfinder", "10,000");

    //display toString using car1 object
    System.out.println(car1.toString());

    //user input for year
    System.out.println("Please list your automobile for sale: " +
        "\nPlease enter the year? ");
    //String newYear variable is created for CarTest class
    String newYear = input.nexLine();
    //set year in car class for Car1 object to String newYear
    car1.setYear(newYear);

    //user input for make
    System.out.println("Please enter the make? ");
    //String newMake variable is created for CarTest class

        String newMake = input.nextLine();
    //set make in car class for Car1 object to String newMake
    car1.setMake(newMake);

    //user input for model
    System.out.println("Please Enter the model?");
    //String newModel variable is created for CarTest class
    String newModel = input.nextLine();
    //set model in car class for Car1 object to String newModel
    car1.setModel(newModel);

    //user input for price
    System.out.println("How much would you sell your car for?");
    //String newPrice variable is created for CarTest class

    String newPrice = input.nextLine();

    //set price in car class for Car1 object to String newPrice
    car1.setPrice(newPrice);

    //displays the new info to the screen
    System.out.println(car1.toString());
    }
}

from

public class Car {

    //class variables are created
    private String year;
    private String make;
    private String model;
    private String price;

    //default constructor
    public Car() {
    }

    //constructor with arguments
    public Car(String year, String make, String model, String price) {
    this.year = year;
    this.model = model;
    this.make = make;
    this.price = price;
    }

    //get make of the vehicle
    public String getMake() {
    return make;
    }

    //set make for vehicle
    public void setMake(String make) {
    this.make = make;
    }

    //get model of the vehicle
    public String getModel(){
    return model;
    }

    //set model for vehicle
    public void setModel(String model) {
    this.model = model;
    }

    //get price of the vehicle
    public String getPrice() {
    return price;
    }

    //set price for vehicle
    public void setPrice(String price) {
    this.price = price;
    }

    //get year of the vehicle 
    public String getYear() { 
    return year;
    }

    //set year for vehicle
    public void setYear(String year) {
    this.year = year;
    }

    public String toString() {
    return "For Sale By Owner: " + year + " " + make + " " + model + 
            "\nSelling Price: $" + price + "\n ";
    }
}

It worked fine when i handed it last week for an assignment, but today, when i came to my computer for a new homework, I found red x's on my car.java, and carTest.java.

My eclipse is saying that : from carTest.java is full of errors and: error: main method not found in class homework.cartest. please define the main method public static void main(String[] args)

error is in the way I defined CAR1: Car car1 = new Car("2008", "Nissan", "Pathfinder", "10,000");

and the ways i am getting the inputs

String newYear = input.nexLine();
String newMake = input.nextLine();
String newModel = input.nextLine();
String newPrice = input.nextLine();

with the input.nextLine(); being underlined as an error in the code in eclipse.

also in the Car.java. the method String toSTring() causes an error stating "change toString() type to String type.

it worked fine when I handed it and got a good grade for it, but today I noticed my codes to be errors, when all was okay yesterday?

Answers


Is the file listed under package/project Homework?

If not, reading your error-message correctly, you're trying to run something that doesn't exist.

At the same time, as said above, you could be experiencing filepath issues. Creating a new project and copy-pasting your code (refactored copy) is usually the quickest solution.


Clean and build the project. May be an anomaly with your Java build path


Copied your project and runned it. Only thing that is wrong with it is:

String newYear = input.nexLine();

should be:

String newYear = input.nextLine();

For the rest, it works fine.

And in the toString method you should add an @override annotation

@Override
public String toString() {
    return "For Sale By Owner: " + year + " " + make + " " + model
            + "\nSelling Price: $" + price + "\n ";
}

Also make sure your project is called CarTest and Source packages package cartest


Need Your Help

How to display a self-refreshing "popout" html GET page in a fanciful AJAX

javascript html ajax web

I've got a web form done many donkey years ago that generates on form submit a popout html- page that refreshes itself every 10 seconds with the latest data drawn from the database.

Strange resource dictionary warnings appear in output window even when the WPF trace settings are turned off

c# .net wpf warnings trace

I am using Visual studio 2011 beta with the april 2012 update installed .I have my Debugging options -> Output window > WPF trace settings all the values including Resource Dictionaries turned off....