• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tuition Calculator Program  RSS feed

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an issue running my program.  I took the advice my professor gave me but I keep getting errors.  Here is the code, but don't look at the flaws that are it, just the error.  I need to adjust a few things and add some others.



This is the error I'm getting:

Martos4.java:34: error: ')' expected
double tuitionCost = calculateTuition(numCourses, String paResident);
                                                        ^
Martos4.java:34: error: illegal start of expression
double tuitionCost = calculateTuition(numCourses, String paResident);
                                                                   ^
2 errors
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16058
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This:

is not correct syntax to call a method.

You cannot specify the type of arguments when you call a method. Remove the "String" in front of the second argument.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have 6 errors instead of two!!!

Martos4.java:91: error: bad operand types for binary operator '&&'
    if(paStudent && sumCredits < 12)
                 ^
  first type:  String
  second type: boolean
Martos4.java:95: error: bad operand types for binary operator '&&'
        else if(paStudent && sumCredits >= 12 && sumCredits <= 18)
                          ^
  first type:  String
  second type: boolean
Martos4.java:100: error: bad operand types for binary operator '&&'
        else if(paStudent && sumCredits > 18)
                          ^
  first type:  String
  second type: boolean
Martos4.java:105: error: bad operand type String for unary operator '!'
         else if(!paStudent && sumCredits < 12)
                 ^
Martos4.java:109: error: bad operand type String for unary operator '!'
         else if(!paStudent && sumCredits >= 12 && sumCredits <= 18)
                 ^
Martos4.java:114: error: bad operand type String for unary operator '!'
         else if(!paStudent && sumCredits > 18)
                 ^
6 errors

----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Martos wrote:

Check the variable type of paStudent. if statement needs to evaluate to a boolean condition.

You have way more than 6 problems in your code. Those 6 are only compiler's issues so far.

What a misleading comment. Student and Resident in my understanding mean different things, while in your code looks like they are synonyms.
Another thing, it gives me impression that it should evaluate to a boolean type variable, but it isn't true.

There are plenty problems. Will need to start reading from the beginning to point them out. Do you have some time to fix them?

For a start, start deleting all those useless comments. It is insane if you have been asked to write them.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:
Daniel Martos wrote:

Check the variable type of paStudent. if statement needs to evaluate to a boolean condition.

You have way more than 6 problems in your code. Those 6 are only compiler's issues so far.

What a misleading comment. Student and Resident in my understanding mean different things, while in your code looks like they are synonyms.
Another thing, it gives me impression that it should evaluate to a boolean type variable, but it isn't true.

There are plenty problems. Will need to start reading from the beginning to point them out. Do you have some time to fix them?

For a start, start deleting all those useless comments. It is insane if you have been asked to write them.


I have a few days, lol
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static int getNumberCourses()
    ...

    return sumCredits;
?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that jGRASP IDE so messes up your code or you just don't pay attention to such important things as:
  • code formatting
  • code indentation

  • ?

    First tasks probably to start are:
  • Remove all comments at the moment
  • Format and indent your code
  • Repost code again


  • These would be the first things (when start writing code) I'd try to get right. Always.

     
    Daniel Martos
    Ranch Hand
    Posts: 126
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liutauras Vilda wrote:
    public static int getNumberCourses()
        ...

        return sumCredits;
    ?


    I should explain.  For my last assignment I had to create a program that figured the cost of tuition for a Pa student and a non Pa student.  This assignment I have to figure out the tuitions for a Pa student, non-Pa student, and an international student.  This was my last program.....I'm just trying to build off of it I guess.

     
    Daniel Martos
    Ranch Hand
    Posts: 126
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liutauras Vilda wrote:Is that jGRASP IDE so messes up your code or you just don't pay attention to such important things as:
  • code formatting
  • code indentation

  • ?

    First tasks probably to start are:
  • Remove all comments at the moment
  • Format and indent your code
  • Repost code again


  • These would be the first things (when start writing code) I'd try to get right. Always.



    It is jgrasp ide
     
    Liutauras Vilda
    Sheriff
    Posts: 4917
    334
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    1. Programming starts with being disciplined. In case you'll be willing to become a programmer, you'll need to understand, that code formatting and indentation is the first thing you need to get right when you write any single line of code.
  • Between successive methods declarations have by one empty line (not by two sometimes, sometimes one)
  • Around operators '=', '+', '-' and other have spaces around
  • Indent your code, so every deeper level of code get indented by four spaces from the left
  • Never omit curly braces in 'if', 'else if' statements, same as in loops
  • Don't put space character before parenthesis in method declaration. Check your 'main' method as a bad example
  • 'main' method's parameter has array identifiers, place them right after the data type String without using space. And don't leave space between []

  • 2. When you choose variable names, spend some time thinking which names would reveal their intention best. 'kybd', 'numCourses', 'sumCredits', 'tuition' - aren't good names in my opinion.
  • 'kybd' is very cryptic and doesn't tell what it means by looking at it.
  • 'numCourses' I'd guess is number of courses, but the method which returns a result, returns 'sumCredits'. It is confusing, isn't it?
  • 'tution' tution what? Fee? Name it maybe then 'tutionFee'.

  • 3. Method names. Same issues. 'calculateTution'. I'm not english speaker, but this name doesn't make sense. Same as I'd say 'calculate house'. 'calculateTutionFee' would make sense.

    4. What this PA means? Country ISO code? If you add comment, comment could explain that.

    5. getNumberCourses() but it returns sumCredits. Why? I see there is variable numCourses, why not this being returned? Do you see chaos in the code. You need to fix those. You might thing these aren't important, but bit by bit you won't notice how you'll get bad habits of doing such things and later will be very difficult to get rid of them.

    6. In the printf method use %n instead \n. Former is platform independent as different systems could differently treat new line.


    After cleaning the code, you'll be able to move forward, to verify if there are more problems in your code. Good luck fixing those
     
    Campbell Ritchie
    Marshal
    Posts: 56530
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Liutauras Vilda wrote:. . . 'main' method's parameter has array identifiers, place them right after the data type String without using space. And don't leave space between [] . . .
    Is array identifier the right name for the []? I look on [] as a postfix unary operator, so following the convention of other unary operators, it should look like this:-
    (String[] args)
    which I think is the same as what you are saying.
    I agree with Liutauras. You need to write the sort of code you will still be able to read and understand in twelve months without needing some sort of glossary. Also get the formatting right from the word “Go” because you can cause yourself severe confusion with incorrectly‑formatted code.
     
    Liutauras Vilda
    Sheriff
    Posts: 4917
    334
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:Is array identifier the right name for the []?
    You're right, probably it isn't. Once I realized I can't come up with the right name for it, I should have better called it as:
    JLS wrote:An array type is written as the name of an element type followed by some number of empty pairs of square brackets []


    @OP
    Don't call it as I did initially, it isn't good name at all.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!