Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Can someone help me(Simple coding)

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can someone help me(Simple coding)

    import java.lang.*; 		//all import statements must be first
    import java.util.Scanner;	//program uses class Scanner
    /**  prompts user to enter 10 numbers, then displays largest and
      *  average of the numbers.
      *   @version 1
      *   @see java.lang.String
      *   @see java.util.Scanner
      */
    public class JavaMain {
    	public static void main (String args[]) {
     
    		Scanner input = new Scanner (System.in);
     
    		int number1 = 0;
    		int number2 = 0;		
    		int number3 = 0;
    		int number4 = 0;
    int number5 = 0;
    int number6 = 0;
    int total = 0;
    int number7 = 0;
    int number8 = 0;
    int number9 = 0;
    int number10 = 0;
    int number11 = 0;
    int number12 = 0;
    int total1 = 0;
    int total2 = 0;
    int total3 = 0;
    int total4 = 0;
    int total5 = 0;
    int total6 = 0;
     
     
    		{
    			System.out.print ("\nEnter your hybrid activity mark out of 10:");
    number1 = input.nextInt();
    total1 = number1 / 10;
    number7 = total1 *  0.05;
     
    System.out.print ("\nEnter your lab mark out of 6: ");
    number2 = input.nextInt();
    total2 = number2 / 10;
    number8 = total2 * 0.10;
     
    System.out.print ("\nEnter your assignments mark out of 100: ");
    number3 = input.nextInt();
    total3 = number3 / 100;
    number9 = total3 * 0.25;
     
    System.out.print ("\nEnter your test #1 mark out of 30: ");
    number4 = input.nextInt();
    total4 = number4 / 30;
    number10 = total4 * 0.15;
     
    System.out.print ("\nEnter your test #2 mark out of 30: ");
    number5 = input.nextInt();
    total5 = number5 / 30;
    number11 = total5 * 0.15;
     
    System.out.print ("\nEnter your final exam mark out of 60: ");
    number6 = input.nextInt();
    total6 = number6 / 60;
    number12 = total6 * 0.30;
     
    			total = number7 + number8 + number9 + number10 + number11 + number12;
     
    	    }
    		// calculations
     
     
    		System.out.println ("Final Mark: " + total);
     
     
    	} // end of main
    }// end of class


    I am new to programming and I cant seem to run it and says "
    C:\MyJava>javac JavaMain.java
    JavaMain.java:39: error: possible loss of precision
    number7 = total1 * 0.05;
    ^
    required: int
    found: double
    JavaMain.java:44: error: possible loss of precision
    number8 = total2 * 0.10;
    ^
    required: int
    found: double
    JavaMain.java:49: error: possible loss of precision
    number9 = total3 * 0.25;
    ^
    required: int
    found: double
    JavaMain.java:54: error: possible loss of precision
    number10 = total4 * 0.15;
    ^
    required: int
    found: double
    JavaMain.java:59: error: possible loss of precision
    number11 = total5 * 0.15;
    ^
    required: int
    found: double
    JavaMain.java:64: error: possible loss of precision
    number12 = total6 * 0.30;
    ^
    required: int
    found: double
    6 errors

    C:\MyJava>


    Please help me Im soo noob.
    Last edited by poldz123; September 19th, 2012 at 08:19 AM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Can someone help me(Simple coding)

    please use [code=java] before your code and [/code] after your code to help my old eyes see the code in pretty colors and indentation.
    This is your error:JavaMain.java:39: error: possible loss of precision
    This is what to drop into your favorite search engine:java error possible loss of precision
    That will explain what went wrong in words you can understand until you understand these:JavaMain.java:39: error: possible loss of precision
    Once you get an idea of what went wrong, this is where you look:JavaMain.java:39
    Which basically says line #39 is where the compiler was looking when something was found to be wrong.
    This is what the compiler is complaining about:number7 = total1 * 0.05;

    Hopefully this will not just help you fix this error, but introduce you to understanding what the compiler is trying to tell you in the future.
    If you have more questions, please ask.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Can someone help me(Simple coding)

    Quote Originally Posted by jps View Post
    please use [code=java] before your code and [/code] after your code to help my old eyes see the code in pretty colors and indentation.
    This is your error:JavaMain.java:39: error: possible loss of precision
    This is what to drop into your favorite search engine:java error possible loss of precision
    That will explain what went wrong in words you can understand until you understand these:JavaMain.java:39: error: possible loss of precision
    Once you get an idea of what went wrong, this is where you look:JavaMain.java:39
    Which basically says line #39 is where the compiler was looking when something was found to be wrong.
    This is what the compiler is complaining about:number7 = total1 * 0.05;

    Hopefully this will not just help you fix this error, but introduce you to understanding what the compiler is trying to tell you in the future.
    If you have more questions, please ask.
    Do as he says!

    Here's what's wrong

    You're working with decimals, so when you're returning decimals you're returning variable type double, yet I'm seeing int's declared! Change all your variables to double instead of int, and you're problem will be solved!

Similar Threads

  1. Please i need help in a simple coding
    By ookhai in forum Object Oriented Programming
    Replies: 13
    Last Post: July 6th, 2012, 10:19 AM
  2. Need Help With Coding
    By noles227 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 07:35 PM
  3. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  4. i need coding for simple login
    By nag in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: September 29th, 2011, 02:30 PM
  5. [SOLVED] simple question, coding unrelated, how to delete multiple tabs?
    By Perd1t1on in forum Java Theory & Questions
    Replies: 1
    Last Post: September 8th, 2010, 07:44 PM