2016-04-11 15 views
0

Java ile derlemeye çalışırken bazı hatalar alıyorum. Bu benim ilk yazı yığınının taşmasıdır, bu yüzden lütfen yazımdaki hataları işaretleyin.Java dosyasını derlemeye çalışırken hatalar

Bu kod, pratik için yaptığım bazı test kodudur.

public class MiscUtilsTest 
{ 

    public static void main(String[] args) 
    { 
    testMax(); 
    testCalcGrade(); 
    testRoomArea(); 
    } 

    public static void testMax() 
    { 
    int num, num2, num3; 

    num = MiscUtils.max(9, 2); 
    assert 9 == num; 

    num2 = MiscUtils.max(6, 1); 
    assert 6 == num2; 

    num3 = MiscUtils.max(7, 7); 
    assert 7 == num3; 

    } 

    public static void testCalcGrade() 
    { 
    int grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9; 

    grade1 = MiscUtils.calcGrade(2); 
    assert "F".equals(grade1); 

    grade2 = MiscUtils.calcGrade(15); 
    assert "F".equals(grade2); 

    grade3 = MiscUtils.calcGrade(28); 
    assert "F".equals(grade3); 

    grade4 = MiscUtils.calcGrade(33); 
    assert "F".equals(grade4); 

    grade5 = MiscUtils.calcGrade(40); 
    assert "F".equals(grade5); 

    grade6 = MiscUtils.calcGrade(49); 
    assert "F".equals(grade6); 

    grade7 = MiscUtils.calcGrade(82); 
    assert "8".equals(grade7); 

    grade8 = MiscUtils.calcGrade(125); 
    assert "".equals(grade8); 

    grade9 = MiscUtils.calcGrade(-12); 
    assert "".equals(grade9); 

    } 

    public static void testRoomArea() 
    { 
    int test, test2, test3; 

    test2 = MiscUtils.roomArea(-10, 5); 
    assert 0 == test; 

    test2 = MiscUtils.roomArea(6, 2); 
    assert 0 == test2; 

    test3 = MiscUtils.roomArea(5, 10); 
    assert 50 == test3; 

    } 
} 

aşağıdaki derleme sırasında ise i almak hataları - MiscUtils Sınıf dosyası, Kod soran olanlar için

MiscUtilsTest.java:45: error: cannot find symbol 
MiscUtilsTest.java:30: error: incompatible types: String cannot be converted to int 
    grade1 = MiscUtils.calcGrade(2); 
           ^
MiscUtilsTest.java:33: error: incompatible types: String cannot be converted to int 
    grade2 = MiscUtils.calcGrade(15); 
           ^
MiscUtilsTest.java:36: error: incompatible types: String cannot be converted to int 
    grade3 = MiscUtils.calcGrade(28); 
           ^
MiscUtilsTest.java:39: error: incompatible types: String cannot be converted to int 
    grade4 = MiscUtils.calcGrade(33); 
           ^
MiscUtilsTest.java:42: error: incompatible types: String cannot be converted to int 
    grade5 = MiscUtils.calcGrade(40); 
           ^
MiscUtilsTest.java:45: error: incompatible types: String cannot be converted to int 
    grade6 = MiscUtils.calcGrade(49); 
           ^
MiscUtilsTest.java:48: error: incompatible types: String cannot be converted to int 
    grade7 = MiscUtils.calcGrade(82); 
           ^
MiscUtilsTest.java:51: error: incompatible types: String cannot be converted to int 
    grade8 = MiscUtils.calcGrade(125); 
           ^
MiscUtilsTest.java:54: error: incompatible types: String cannot be converted to int 
    grade9 = MiscUtils.calcGrade(-12); 
           ^
9 errors 

:

şu benim kodudur. sınıf

import java.io.PrintStream; 
import java.io.PrintStream; 

public class MiscUtils 
{ 
static 
{ 
    System.out.println("[FYI: You are testing the *working* version of MiscUtils. Your test harness *should not* find any problems.]"); 
} 

public static int max(int paramInt1, int paramInt2) 
{ 
    int i = paramInt1; 
    if (paramInt2 > paramInt1) { 
    i = paramInt2; 
    } 
    return i; 
} 

public static String calcGrade(int paramInt) 
{ 
    String str = ""; 
    if ((paramInt >= 0) && (paramInt <= 100)) { 
    if (paramInt >= 50) { 
    str = str + paramInt/10; 
    } else { 
    str = "F"; 
    } 
    } 
    return str; 
} 

public static int roomArea(int paramInt1, int paramInt2) 
{ 
    int i = 0; 
    if ((paramInt1 > 0) && (paramInt2 >= paramInt1) && (paramInt2 <= 3 * paramInt1)) { 
    i = paramInt1 * paramInt2; 
} 
    return i; 
} 
} 
+1

Yeni başlayanlar için, 'MiscUtils' sınıfının kodunu da gönderebilirsiniz. –

+1

MiscUtils –

+1

gönderebilir. .class istemiyoruz. Sorunuzdaki MiscUtils'i tanımlamak için kullanılan kodu ekleyin, lütfen. MiscUtils MiscClassUtilsTest.java'da tanımlanmışsa, sorunuzu düzenleyin ve kodu buraya kopyalayın. – RubioRic

cevap

0

MiscUtils sınıfının derleyici hatalarında gösterilen yöntemleri kaçırmadığınızı belirtin.

+0

https://www.dropbox.com/s/klhhl3ng1sa7n5x/MiscUtils.class.working?dl=0 Sınıf dosyası burada, nasıl açılacağından/okuyacağından emin değilim. – razorgnome

0

Sınıf MiscUtils'i içe aktarmadınız. Böylece onun verme hatası.

MiscUtilsTest sınıfından önce içe aktarma sözdizimini kullanın.

import MiscUtils.*; 
0

değişimi:

int grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9; 

calcGrade() getiriler bir String değil bir int yana

String grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9; 

için.

+0

Çok teşekkür ederim, derlerken başka birçok hata aldım, ama onları düzeltmeyi başardım. Yardımın için teşekkürler, hiç bir hata ile derlemeyi başardı. Ayrıca, bundan sonra ben bu hataları ortadan kaldırmak için emin olacağım :) – razorgnome

İlgili konular