I am trying to convert and sucessfully run my pettycash program in throughthe eclipse IDE in Java. First Ill show where Im at I am lost afterhere then ill show the petty cash program. I am not sure if I am on the right track and dont understand how to import the date and to make the information run in the program


package org.eclipse.lifegame.domain;

public class PettyCash {

private static final String self = null;
private static final String initial = null;
private static Object amt;

public PettyCash() {
}
private static void __init__ (String self2, Object amt2){
self.balance = initial;
}
private static void deposit (String self2, Object amt2){
self.balance = self.balance + amt;};

private static void withdraw(String self2, Object amt2) {
self.balance = self.balance - amt;
if (self.balance < 0)
{System.out.println ("Not enough here");}
else {
return self.balance}


private static void getbalance(String self2){
return self.balance;}
}

#!/usr/bin/python
# Filename: petty cash.py
 
from datetime import date
import string
now = date.today
 
class Account:
     def __init__(self, initial):
         '''Initializes the account data.'''
         self.balance = initial
         print ' (Initializing; balance is %s) ' % self.balance
     def deposit(self, amt):
         '''Deposit amt into account'''
         self.balance = self.balance + amt
         print " (Depositing %s; new balance is %s) " % (amt, self.balance)
         # When this deposit is created, it
         # adds to the balance
         self.balance + amt
     def withdraw(self,amt):
         '''Withraw amt from account'''
         print " (Withdrawing %s; new balance is %s) " % (amt, self.balance)
         # When this deposit is created, it
         # subtracts from the balance
         self.balance = self.balance - amt
     def getbalance(self):
         '''Return the current balance of this account.'''
         return self.balance
def printmenu():
    print "please select a number"
    print "1 Deposit"
    print "2 Withdraw"
    print '3 Balance'
    print '4 Done'
 
    # Get user's choice and return it to caller
    return input (">")
def showbalance(a):
    print "new balance is %s" %  a.getbalance()
def getnumberinput(txt):
    num = 0
    while num == 0:
        val = input(txt)
        num = float(val)
        if num <= 0:
            print "The number needs to be greater than zero."
            num = 0
            
    return num
    
a = Account(1000.00)
print "what is today's Julian date?"
date = input (">")
print 'Todays  Julian date is', date
print "Welcome to the petty cash account"
print "Did you deposit or withdraw money today"
print
 
choice = 0
while choice <> 4:
    choice = printmenu()
    if choice == 1:
        deposit = getnumberinput("how much?")
        a.deposit(deposit)
        
    elif choice == 2:
        # do the withdraw logic here
        withdraw = getnumberinput("How Much?")
        a.withdraw(withdraw)
    elif choice == 3:
        showbalance(a)
        
    elif choice == 4:
        print 'Thank you!'
        showbalance(a)
        print 'done'

Dani AI

Generated

Converting this Python script to Java means rethinking the design, not copying lines. Python uses dynamic types and self; Java requires typed fields, a constructor, and instance methods (use this instead of self). For dates use java.time.LocalDate (Java 8+), for console input use java.util.Scanner, and for money prefer BigDecimal to avoid floating-point rounding. ’s posted Java fragment mixes Python idioms (and static/placeholders) — rebuild the class with typed fields and instance methods instead. was right that this is a Java question: focus on Java idioms and Eclipse run/debug steps.

A simple, safe Java layout (illustrative — paste into a new Eclipse class with a main method):

import java.time.LocalDate;
import java.util.Scanner;
import java.math.BigDecimal;

public class PettyCash {
    private BigDecimal balance;

    public PettyCash(BigDecimal initial) {
        this.balance = initial;
        System.out.println("(Initializing; balance is " + balance + ")");
    }

    public void deposit(BigDecimal amt) {
        balance = balance.add(amt);
        System.out.println("(Deposited " + amt + "; balance " + balance + ")");
    }

    public void withdraw(BigDecimal amt) {
        if (balance.compareTo(amt) < 0) {
            System.out.println("Not enough funds.");
        } else {
            balance = balance.subtract(amt);
            System.out.println("(Withdrew " + amt + "; balance " + balance + ")");
        }
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PettyCash a = new PettyCash(new BigDecimal("1000.00"));
        System.out.println("Today's date: " + LocalDate.now());
        // simple menu loop: read lines and parse to avoid Scanner nextInt/nextLine pitfalls
        // (omitted for brevity)
        sc.close();
    }
}

Eclipse notes and quick troubleshooting: create a Java Project → New → Class (check the public static void main box), add needed import lines, then Run As → Java Application. If LocalDate is unknown, ensure project Java compiler compliance is 1.8+ (Project → Properties → Java Compiler). Handle user input errors with try/catch or BigDecimal parsing. Docs: LocalDate, Scanner, BigDecimal.

You might have to post this one on the Java Forum!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.