5 Replies - 148 Views - Last Post: 08 October 2018 - 07:41 PM Rate Topic: -----

#1 askibum02   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 18

Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:24 PM

I'm trying to complete an assignment: Create a class called Date that includes 3 instance variables—a month (type int), a day (type int), and a year (type int). Provide a constructor that initializes the 3 instance variables and assumes the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day, and year separated by forward slashes(/). Write a test application named DateTest that demonstrates class Date’s capabilities.
I have the code but cannot get it to compile. I haven't figured out how to do it in Eclipse, and when i try to compile it in Terminal i get an error. Here is the code:

//Date.java


public class Date {
	private int monthdate;
	private int daydate;
	private int yeardate;
	
	public Date (int month, int day, int year) {
		monthdate = month;
		daydate = day;
		yeardate = year;
	}
	
	public void setMonth(int month) {
		monthdate = month;
	}
	
	public int getMonth()  {
		return monthdate;
	}
	
	public void setday(int day)  {
		daydate = day;
	}
	
	public int getDay()  {
		return daydate;
	}
	
	public void setYear (int year)  {
		yeardate = year;
	}
	
	public int getYear()  {
		return yeardate;
		
	}
	
	public void dispalyDate ()  {
		System.out.printf("%d/%d/%d\n", getMonth(), getDay(), getYear());
	}
}



This compiles fine.

//DateTest.java
//CSIS 212-B02

import java.util.Scanner;

public class DateTest {
	public static void main(String [] args)  {
		Date display = new Date (0,0,0);
		
		Scanner input = new Scanner(System.in);
		
		int month;
		int day;
		int year;
		
		System.out.print("Enter Month:");
		month = input.nextInt();
		display.setMonth(month);
		
		System.out.println();
		
		System.out.print("Enter Day:");
		day = input.nextInt();
		display.setDay(day);
		
		System.out.println();
		
		System.out.print("Enter Year:");
		year = input.nextInt();
		display.setYear(year);
		
		System.out.println();
		
		display.displayDate();
	}
}



When I compile this I get the error: "DateTest.java:24: error: cannot find symbol
display.setDay(day);
^
symbol: method setDay(int)
location: variable display of type Date
DateTest.java:34: error: cannot find symbol
display.displayDate();
^
symbol: method displayDate()
location: variable display of type Date
2 errors"

I realize this may be elementary for some, but this is my first Java class, and my first attempt at running a program with multiple classes. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

#2 wseng92   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 560
  • Joined: 23-September 15

Re: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:30 PM

Quote

symbol: method setDay(int)
In Date class, you are declaring setday method, but in DateTest, you using setDay

Quote

symbol: method displayDate()
There are no displayDate method in Date class.

This post has been edited by wseng92: 08 October 2018 - 07:32 PM

Was This Post Helpful? 0
  • +
  • -

#3 askibum02   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 18

Re: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:35 PM

Thanks! I went back through my code and also found a spelling mistake. DateTest.java compiles now, and prompts for the month, but when i enter the month I get the following error:

Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at DateTest.main(DateTest.java:17)

Help?
Was This Post Helpful? 0
  • +
  • -

#4 wseng92   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 560
  • Joined: 23-September 15

Re: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:38 PM

Make sure you only enter integer number for your month.
Was This Post Helpful? 0
  • +
  • -

#5 askibum02   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 18

Re: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:40 PM

View Postwseng92, on 08 October 2018 - 10:38 PM, said:

Make sure you only enter integer number for your month.


Ah, yes. Hence the "int" in the program. Ugh! Thank you so much, I had a bad day at work, wasn't thinking straight.
Was This Post Helpful? 0
  • +
  • -

#6 wseng92   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 560
  • Joined: 23-September 15

Re: Compiling multiple classes in Terminal Mac OS and/or Eclipse IDE

Posted 08 October 2018 - 07:41 PM

I would suggest you to use try and catch to handle InputMismatchException :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1