My Math Forum  

Go Back   My Math Forum > Science Forums > Computer Science

Computer Science Computer Science Forum


Thanks Tree2Thanks
  • 2 Post By SDK
Reply
 
LinkBack Thread Tools Display Modes
March 29th, 2018, 01:04 AM   #1
Senior Member
 
Joined: Nov 2017
From: india

Posts: 188
Thanks: 1

what is error in this code?

Code:
import java.util.*;
class library
{
    private String name;
    private int price;
    private int day;
    private double fine;
    Scanner sc=new Scanner(System.in);
    public void input()
    {
        System.out.println("Enter name of book, price of book");
        name = sc.nextLine();
        price=sc.nextInt();
    }
    void cal()
    {
        System.out.println("enter no of days late");
        day=sc.nextInt();
        if(day<=7)
        fine=0.25*day;
        
    }

    public void display()
    {
    System.out.println("name = " +name);
    System.out.println("fine paid is" +fine);
    }
}
 class library1
{
     public static void main(String args[])
    {
        library obj=new library();
        obj.input();
        obj.cal();
        obj.display();
    }
}
integration is offline  
 
March 29th, 2018, 01:37 AM   #2
SDK
Senior Member
 
Joined: Sep 2016
From: USA

Posts: 350
Thanks: 192

Math Focus: Dynamical systems, analytic function theory, numerics
It isn't documented.
Thanks from Joppy and integration
SDK is offline  
March 30th, 2018, 12:38 AM   #3
Senior Member
 
Joined: Apr 2014
From: UK

Posts: 855
Thanks: 314

The line:
System.out.println("enter no of days late");
should be:
System.out.println("enter no. of days late");

The line:
System.out.println("fine paid is" +fine);
should be :
System.out.println("fine paid is " +fine);


Magic numbers in the code isn't good practice, you should define constants (I'm looking at your '0.25' and '7')
weirddave is offline  
March 30th, 2018, 12:38 AM   #4
Senior Member
 
Joined: Apr 2014
From: UK

Posts: 855
Thanks: 314

The line:
System.out.println("enter no of days late");
should be:
System.out.println("enter no. of days late");

The line:
System.out.println("fine paid is" +fine);
should be :
System.out.println("fine paid is " +fine);


Magic numbers in the code isn't good practice, you should define constants (I'm looking at your '0.25' and '7')
weirddave is offline  
March 30th, 2018, 11:56 PM   #5
Senior Member
 
Joined: Nov 2017
From: india

Posts: 188
Thanks: 1

Quote:
The line:
System.out.println("enter no of days late");
should be:
System.out.println("enter no. of days late");

The line:
System.out.println("fine paid is" +fine);
should be :
System.out.println("fine paid is " +fine);
what is diffrence between it?
integration is offline  
Reply

  My Math Forum > Science Forums > Computer Science

Tags
code, error



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grey code for 25(10) error?; Need help fast please unistu Algebra 2 June 16th, 2016 11:31 PM
Maximum allowable probability of error for the (8, 4) Hamming Code jmomo Abstract Algebra 1 May 7th, 2014 06:52 AM
Relative error Percenttage error esther Calculus 1 October 25th, 2011 03:57 AM
Pi Code+Phi code..please complete Keith742 Algebra 1 June 21st, 2009 06:09 PM
Code generation, probability of generating same code twice NateL Algebra 2 July 15th, 2008 07:07 PM





Copyright © 2018 My Math Forum. All rights reserved.