1,105,594 Community Members

Please help for a total newbie!java!

Member Avatar
isebas
Newbie Poster
15 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok so i just started taking AP Computer Science at my high school and I really have no experience with java (just a little bit with python). So for our fist homework we had to try out a few codes and make some programs. I'm getting a " <identifier> expected error at "System.out.println("Enter firsr price ");". Please some help on how to fix it and dont laught at me for not being able to do such simple things, hey that's why I'm learning.

public class total
 
  {public static input in = new input();
    int A, B, C, D, F;
    
    System.out.println("Enter firsr price ");
    A = in.get.Int();
    
    System.out.print("Enter second price");
    B = in.get.Int();
    
    System.out.print("Enter third price");
    C = in.get.Int();
    
    D = (A+B+C)*.06
    F = A+B+C+D
    
    System.out.print("Sales tax is"(D));
    
    System.out.print("Total Cost is"(F));
    }
}
Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
2
 

You code needs to be in a method. You currently have it in the body of the class itself.

Look at your other programs or examples and note how they declare a main() method and put the code in there.

Member Avatar
isebas
Newbie Poster
15 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

You code needs to be in a method. You currently have it in the body of the class itself.

Look at your other programs or examples and note how they declare a main() method and put the code in there.

Ok so i fixed the first problem and a few others. Now, how do i get tu multiply the int by 0.06? here is the current code I have

import java.io.*;
public class total
 
  {public static input in = new input();
    
public static void main(String[] args) throws IOException
   {int A,B,C,D,G; 
    
    
            
            System.out.print("Enter firsr price ");
            A = in.getInt();
    
            System.out.print("Enter second price");
            B = in.getInt();
    
           System.out.print("Enter third price");
           C = in.getInt();
    
           D = (A + B + C)*0.06;
        
           
           G = A + B + C + D;
    
           System.out.print("Sales tax is");
           System.out.print(D);
    
           System.out.println("Total Cost is");
           System.out.print(G);
    }
}
Member Avatar
nagatron
Junior Poster
109 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

You 'D' is supposed to get the total value of your A B and C right? Since 0.6 is a double value. . try to declare the D and G as double because you are passing double values now.

import java.io.*;
public class total
 
  {public static input in = new input();
    
public static void main(String[] args) throws IOException
   {
     int A,B,C;
     double D, G;
    
            System.out.print("Enter firsr price ");
            A = in.getInt();
    
            System.out.print("Enter second price");
            B = in.getInt();
    
           System.out.print("Enter third price");
           C = in.getInt();
    
           D = (A + B + C)*0.06;
        
           
           G = A + B + C + D;
    
           System.out.print("Sales tax is");
           System.out.print(D);
    
           System.out.println("Total Cost is");
           System.out.print(G);
    }
}
Member Avatar
isebas
Newbie Poster
15 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

You 'D' is supposed to get the total value of your A B and C right? Since 0.6 is a double value. . try to declare the D and G as double because you are passing double values now.

import java.io.*;
public class total
 
  {public static input in = new input();
    
public static void main(String[] args) throws IOException
   {
     int A,B,C;
     double D, G;
    
            System.out.print("Enter firsr price ");
            A = in.getInt();
    
            System.out.print("Enter second price");
            B = in.getInt();
    
           System.out.print("Enter third price");
           C = in.getInt();
    
           D = (A + B + C)*0.06;
        
           
           G = A + B + C + D;
    
           System.out.print("Sales tax is");
           System.out.print(D);
    
           System.out.println("Total Cost is");
           System.out.print(G);
    }
}

Thank you so much I was trying double but I was trying the wrong way. Tt compiled perfectly now.

Question Answered as of 2 Years Ago by Ezzaral and nagatron
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: